use of boofcv.alg.similar.SimilarImagesData 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());
}
}
Aggregations