Search in sources :

Example 11 with DogArray

use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.

the class TestSimilarImagesData method buildAndLookUp.

/**
 * Checks all functions to some extent
 */
@Test
void buildAndLookUp() {
    var alg = new SimilarImagesData();
    List<List<Point2D_F64>> features = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        features.add(UtilPoint2D_F64.random(0, 200, 10 + i * 2, rand));
    }
    alg.add("0", features.get(0));
    alg.add("1", features.get(1));
    alg.add("2", features.get(2));
    alg.add("3", features.get(3));
    for (int i = 0; i < 3; i++) {
        for (int j = i + 1; j < 3; j++) {
            if ((i + j) % 2 == 0)
                alg.setRelationship(i + "", j + "", randomAssociated(features.get(i).size(), features.get(j).size(), 8).toList());
            else
                alg.setRelationship(j + "", i + "", randomAssociated(features.get(j).size(), features.get(i).size(), 8).toList());
        }
    }
    // See if the features were stored correctly
    DogArray<Point2D_F64> foundFeatures = new DogArray<>(Point2D_F64::new);
    for (int view = 0; view < features.size(); view++) {
        List<Point2D_F64> expected = features.get(view);
        alg.lookupPixelFeats(view + "", foundFeatures);
        assertEquals(expected.size(), foundFeatures.size);
        foundFeatures.forIdx((idx, v) -> assertTrue(v.isIdentical(expected.get(idx), 0.0)));
    }
    // Basic sanity check for similar views
    List<String> foundSimilar = new ArrayList<>();
    alg.findSimilar("2", (v) -> true, foundSimilar);
    assertEquals(2, foundSimilar.size());
    alg.findSimilar("3", (v) -> true, foundSimilar);
    assertEquals(0, foundSimilar.size());
    // Inspect the relationship between one set of views
    var foundPairsA = new DogArray<>(AssociatedIndex::new);
    var foundPairsB = new DogArray<>(AssociatedIndex::new);
    // do it in both directions
    alg.findSimilar("2", (v) -> true, foundSimilar);
    alg.lookupAssociated("1", foundPairsA);
    alg.findSimilar("1", (v) -> true, foundSimilar);
    alg.lookupAssociated("2", foundPairsB);
    // Other than the swap they should be identical
    assertEquals(foundPairsA.size, foundPairsB.size);
    for (int i = 0; i < foundPairsB.size; i++) {
        AssociatedIndex a = foundPairsA.get(i);
        AssociatedIndex b = foundPairsB.get(i);
        assertEquals(a.src, b.dst);
        assertEquals(a.dst, b.src);
    }
}
Also used : ArrayList(java.util.ArrayList) DogArray(org.ddogleg.struct.DogArray) Point2D_F64(georegression.struct.point.Point2D_F64) UtilPoint2D_F64(georegression.geometry.UtilPoint2D_F64) List(java.util.List) ArrayList(java.util.ArrayList) AssociatedIndex(boofcv.struct.feature.AssociatedIndex) Test(org.junit.jupiter.api.Test)

Example 12 with DogArray

use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.

the class TestSimilarImagesSceneRecognition method simpleAllTogether.

/**
 * Simple scenario which exercises everything all at once
 */
@Test
void simpleAllTogether() {
    var config = new ConfigSimilarImagesSceneRecognition();
    // Needed to do some hacking since the defaults assume there are a bunch of image features
    config.minimumSimilar.setRelative(0.1, 0.0);
    config.recognizeNister2006.minimumDepthFromRoot = 0;
    SimilarImagesSceneRecognition<GrayU8, TupleDesc_F32> alg = FactorySceneReconstruction.createSimilarImages(config, ImageType.SB_U8);
    alg.detector = new HelperDetector();
    for (int i = 0; i < 5; i++) {
        alg.addImage("" + i, new GrayU8(50, 10));
    }
    alg.fixate();
    // For all these other functions just check to see if something got populated
    DogArray_I32 words = new DogArray_I32();
    alg.lookupImageWords("3", words);
    assertTrue(words.size > 0);
    var features = new DogArray<>(Point2D_F64::new);
    alg.lookupPixelFeats("1", features);
    assertTrue(features.size > 0);
    // Look up similar images. All but the query view should be similar
    List<String> similarImages = new ArrayList<>();
    alg.findSimilar("0", (a) -> true, similarImages);
    assertTrue(similarImages.size() > 0);
    var pairs = new DogArray<>(AssociatedIndex::new);
    alg.lookupAssociated(similarImages.get(0), pairs);
    assertTrue(features.size > 0);
}
Also used : TupleDesc_F32(boofcv.struct.feature.TupleDesc_F32) ArrayList(java.util.ArrayList) DogArray_I32(org.ddogleg.struct.DogArray_I32) DogArray(org.ddogleg.struct.DogArray) Point2D_F64(georegression.struct.point.Point2D_F64) GrayU8(boofcv.struct.image.GrayU8) AssociatedIndex(boofcv.struct.feature.AssociatedIndex) Test(org.junit.jupiter.api.Test)

Example 13 with DogArray

use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.

the class TestVisualDepthOps method depthTo3D_with_rgb.

@Test
void depthTo3D_with_rgb() {
    GrayU16 depth = new GrayU16(width, height);
    depth.set(200, 80, 3400);
    depth.set(600, 420, 50);
    Planar<GrayU8> rgb = new Planar<>(GrayU8.class, width, height, 3);
    GImageMiscOps.fillUniform(rgb, rand, 0, 200);
    DogArray<Point3D_F64> pts = new DogArray<>(Point3D_F64::new);
    DogArray<int[]> color = new DogArray<>(() -> new int[3]);
    VisualDepthOps.depthTo3D(param, rgb, depth, pts, color);
    assertEquals(2, pts.size());
    assertEquals(2, color.size());
    assertEquals(0, compute(200, 80, 3400).distance(pts.get(0)), 1e-8);
    assertEquals(0, compute(600, 420, 50).distance(pts.get(1)), 1e-8);
    color(200, 80, rgb, color.get(0));
    color(600, 420, rgb, color.get(1));
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) GrayU16(boofcv.struct.image.GrayU16) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 14 with DogArray

use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.

the class TestMicroQrCodeDecoderImage method transposed.

/**
 * Transposes the input image and sees if it can still be decoded by default
 */
@Test
void transposed() {
    MicroQrCode qr = new MicroQrCodeEncoder().addAutomatic("123LK").fixate();
    GrayU8 image = render(qr);
    GrayU8 imageTransposed = image.createSameShape();
    ImageMiscOps.transpose(image, imageTransposed);
    var patterns = new DogArray<>(PositionPatternNode::new);
    addPositionPattern(qr, patterns);
    var alg = new MicroQrCodeDecoderImage<>(null, "", GrayU8.class);
    alg.process(patterns.toList(), imageTransposed);
    assertEquals(1, alg.found.size());
    assertEquals(0, alg.failures.size());
    assertEquals("123LK", alg.found.get(0).message);
    // It should fail now since it won't consider a transposed marker
    alg.considerTransposed = false;
    alg.process(patterns.toList(), imageTransposed);
    assertEquals(0, alg.found.size());
    assertEquals(1, alg.failures.size());
}
Also used : GrayU8(boofcv.struct.image.GrayU8) PositionPatternNode(boofcv.alg.fiducial.qrcode.PositionPatternNode) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 15 with DogArray

use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.

the class TestMicroQrCodeDecoderImage method simple_all_configs.

/**
 * Render then decode images with all possible versions, masks, and error correction levels.
 */
@Test
void simple_all_configs() {
    String message = "01234";
    var engine = new FiducialImageEngine();
    engine.configure(0, 100);
    var generator = new MicroQrCodeGenerator();
    generator.markerWidth = 100;
    generator.setRender(engine);
    var alg = new MicroQrCodeDecoderImage<>(null, "", GrayU8.class);
    var patterns = new DogArray<>(PositionPatternNode::new);
    for (int version = 1; version <= 4; version++) {
        ErrorLevel[] errors = MicroQrCode.allowedErrorCorrection(version);
        for (ErrorLevel error : errors) {
            // Generate the QR code
            var encoder = new MicroQrCodeEncoder();
            // encoder.setVerbose(System.out, null);
            MicroQrCode qr = encoder.setVersion(version).setError(error).setMask(M00).addNumeric(message).fixate();
            generator.render(qr);
            // Set up the "detected" position pattern
            patterns.reset();
            PositionPatternNode pp = patterns.grow();
            pp.square = qr.pp;
            pp.grayThreshold = (double) (engine.getWhite() / 2);
            // ShowImages.showWindow(engine.getGray(), "Title");
            // BoofMiscOps.sleep(10_000);
            // Process the image
            // alg.decoder.setVerbose(System.out, null);
            alg.process(patterns.toList(), engine.getGray());
            // Check results
            assertEquals(1, alg.found.size());
            assertEquals(0, alg.failures.size());
            assertEquals(version, alg.found.get(0).version);
            assertEquals(message, alg.found.get(0).message);
        }
    }
}
Also used : FiducialImageEngine(boofcv.alg.drawing.FiducialImageEngine) ErrorLevel(boofcv.alg.fiducial.microqr.MicroQrCode.ErrorLevel) PositionPatternNode(boofcv.alg.fiducial.qrcode.PositionPatternNode) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Aggregations

DogArray (org.ddogleg.struct.DogArray)79 Test (org.junit.jupiter.api.Test)48 ArrayList (java.util.ArrayList)27 Point3D_F64 (georegression.struct.point.Point3D_F64)18 DogArray_I32 (org.ddogleg.struct.DogArray_I32)17 Point2D_F64 (georegression.struct.point.Point2D_F64)16 GrayU8 (boofcv.struct.image.GrayU8)13 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)10 Point2D_I32 (georegression.struct.point.Point2D_I32)7 DMatrixRMaj (org.ejml.data.DMatrixRMaj)7 BufferedImage (java.awt.image.BufferedImage)6 Point3dRgbI_F64 (boofcv.struct.Point3dRgbI_F64)5 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)5 List (java.util.List)5 PositionPatternNode (boofcv.alg.fiducial.qrcode.PositionPatternNode)4 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)4 GrayF32 (boofcv.struct.image.GrayF32)4 PointCloudViewer (boofcv.visualize.PointCloudViewer)4 Se3_F64 (georegression.struct.se.Se3_F64)4 FactoryNearestNeighbor (org.ddogleg.nn.FactoryNearestNeighbor)4