Search in sources :

Example 1 with RecognitionVocabularyTreeNister2006

use of boofcv.alg.scene.nister2006.RecognitionVocabularyTreeNister2006 in project BoofCV by lessthanoptimal.

the class TestRecognitionIO method recognitionVocabularyTreeNister2006_stream.

@Test
void recognitionVocabularyTreeNister2006_stream() {
    // Create the data structure and fill it in with non default values
    RecognitionVocabularyTreeNister2006<TupleDesc_F64> db = createDefaultNister2006();
    // Encode then decode
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    RecognitionIO.saveBin(db, stream);
    var found = new RecognitionVocabularyTreeNister2006<TupleDesc_F64>();
    InputStream input = new ByteArrayInputStream(stream.toByteArray());
    RecognitionIO.loadBin(input, found);
    // See if all the important components were copied
    compareTrees(db.tree, found.tree);
    assertEquals(db.getImagesDB().size, found.getImagesDB().size);
    assertEquals(db.invertedFiles.size(), found.invertedFiles.size());
    for (int i = 0; i < db.invertedFiles.size(); i++) {
        InvertedFile e = db.invertedFiles.get(i);
        InvertedFile f = found.invertedFiles.get(i);
        assertEquals(e.size(), f.size());
        assertEquals(e.weights.size(), f.weights.size());
        assertEquals(e.weights.size(), f.size());
        for (int imageIdx = 0; imageIdx < e.size; imageIdx++) {
            int indexE = e.get(imageIdx);
            int indexF = f.get(imageIdx);
            assertEquals(indexE, indexF);
            float weightE = e.weights.get(imageIdx);
            float weightF = f.weights.get(imageIdx);
            assertEquals(weightE, weightF);
        }
    }
}
Also used : TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) RecognitionVocabularyTreeNister2006(boofcv.alg.scene.nister2006.RecognitionVocabularyTreeNister2006) 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)

Example 2 with RecognitionVocabularyTreeNister2006

use of boofcv.alg.scene.nister2006.RecognitionVocabularyTreeNister2006 in project BoofCV by lessthanoptimal.

the class TestRecognitionIO method createDefaultNister2006.

@NotNull
private RecognitionVocabularyTreeNister2006<TupleDesc_F64> createDefaultNister2006() {
    var db = new RecognitionVocabularyTreeNister2006<TupleDesc_F64>();
    db.tree = createTree(6);
    db.getImagesDB().resize(20);
    for (int i = 0; i < 20; i++) {
        db.getImagesDB().set(i, rand.nextInt());
    }
    for (int i = 0; i < db.tree.nodes.size; i++) {
        InvertedFile ld = db.invertedFiles.grow();
        ld.add(rand.nextInt(20));
        ld.weights.add(rand.nextFloat());
    }
    return db;
}
Also used : RecognitionVocabularyTreeNister2006(boofcv.alg.scene.nister2006.RecognitionVocabularyTreeNister2006) RecognitionNearestNeighborInvertedFile(boofcv.alg.scene.ann.RecognitionNearestNeighborInvertedFile) InvertedFile(boofcv.alg.scene.bow.InvertedFile) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RecognitionNearestNeighborInvertedFile (boofcv.alg.scene.ann.RecognitionNearestNeighborInvertedFile)2 InvertedFile (boofcv.alg.scene.bow.InvertedFile)2 RecognitionVocabularyTreeNister2006 (boofcv.alg.scene.nister2006.RecognitionVocabularyTreeNister2006)2 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.junit.jupiter.api.Test)1