Search in sources :

Example 1 with RecognitionNearestNeighborInvertedFile

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);
}
Also used : RecognitionNearestNeighborInvertedFile(boofcv.alg.scene.ann.RecognitionNearestNeighborInvertedFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RecognitionNearestNeighborInvertedFile(boofcv.alg.scene.ann.RecognitionNearestNeighborInvertedFile) InvertedFile(boofcv.alg.scene.bow.InvertedFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

RecognitionNearestNeighborInvertedFile (boofcv.alg.scene.ann.RecognitionNearestNeighborInvertedFile)1 InvertedFile (boofcv.alg.scene.bow.InvertedFile)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 Test (org.junit.jupiter.api.Test)1