Search in sources :

Example 1 with LookUpSimilarImages

use of boofcv.alg.structure.LookUpSimilarImages in project BoofCV by lessthanoptimal.

the class TestMultiViewIO method save_load_SimilarImages.

@Test
void save_load_SimilarImages() {
    SimilarImagesData expected = new SimilarImagesData();
    for (int i = 0; i < 4; i++) {
        String id = "" + i;
        List<Point2D_F64> features = new ArrayList<>();
        for (int j = 0; j < 4 + i; j++) {
            features.add(new Point2D_F64(i + j, 1));
        }
        expected.add(id, features);
    }
    var matches12 = new ArrayList<AssociatedIndex>();
    for (int i = 0; i < 8; i++) {
        matches12.add(new AssociatedIndex(rand.nextInt(), rand.nextInt()));
    }
    expected.setRelationship("2", "1", matches12);
    var output = new ByteArrayOutputStream();
    MultiViewIO.save(expected, new OutputStreamWriter(output, UTF_8));
    var input = new ByteArrayInputStream(output.toByteArray());
    LookUpSimilarImages found = MultiViewIO.loadSimilarImages(new InputStreamReader(input, UTF_8));
    assertEquals(expected.listImages.size(), found.getImageIDs().size());
    DogArray<Point2D_F64> features = new DogArray<>(Point2D_F64::new);
    DogArray<AssociatedIndex> pairs = new DogArray<>(AssociatedIndex::new);
    for (String id : expected.listImages) {
        int i = Integer.parseInt(id);
        found.lookupPixelFeats(id, features);
        assertEquals(4 + i, features.size);
    }
    for (String id : expected.listImages) {
        int i = Integer.parseInt(id);
        List<String> similarIds = new ArrayList<>();
        found.findSimilar(id, (s) -> true, similarIds);
        if (i != 2 && i != 1) {
            assertEquals(0, similarIds.size());
            continue;
        }
        assertEquals(1, similarIds.size());
        found.lookupAssociated(similarIds.get(0), pairs);
        assertEquals(8, pairs.size());
    }
}
Also used : SimilarImagesData(boofcv.alg.similar.SimilarImagesData) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LookUpSimilarImages(boofcv.alg.structure.LookUpSimilarImages) DogArray(org.ddogleg.struct.DogArray) Point2D_F64(georegression.struct.point.Point2D_F64) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStreamWriter(java.io.OutputStreamWriter) AssociatedIndex(boofcv.struct.feature.AssociatedIndex) Test(org.junit.jupiter.api.Test)

Aggregations

SimilarImagesData (boofcv.alg.similar.SimilarImagesData)1 LookUpSimilarImages (boofcv.alg.structure.LookUpSimilarImages)1 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)1 Point2D_F64 (georegression.struct.point.Point2D_F64)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 DogArray (org.ddogleg.struct.DogArray)1 Test (org.junit.jupiter.api.Test)1