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);
}
}
}
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;
}
Aggregations