use of boofcv.alg.scene.ann.RecognitionNearestNeighborInvertedFile in project BoofCV by lessthanoptimal.
the class TestRecognitionIO method nearestNeighborBin_stream.
@Test
void nearestNeighborBin_stream() {
var expected = new RecognitionNearestNeighborInvertedFile<>();
expected.getImagesDB().resize(45);
for (int i = 0; i < 20; i++) {
InvertedFile iv = expected.getInvertedFiles().grow();
int N = rand.nextInt(10);
for (int j = 0; j < N; j++) {
iv.addImage(rand.nextInt(1_000_000), rand.nextFloat());
}
}
// Encode then decode
ByteArrayOutputStream stream = new ByteArrayOutputStream();
RecognitionIO.saveNearestNeighborBin(expected, stream);
var found = new RecognitionNearestNeighborInvertedFile<>();
InputStream input = new ByteArrayInputStream(stream.toByteArray());
RecognitionIO.loadNearestNeighborBin(input, found);
// See if they are identical
compareInverted(expected.getInvertedFiles(), found.getInvertedFiles());
assertEquals(expected.getImagesDB().size, found.getImagesDB().size);
}
Aggregations