use of boofcv.struct.feature.AssociatedTripleIndex in project BoofCV by lessthanoptimal.
the class TestAssociateThreeByPairs method failOnCtoA.
/**
* A->B is good. B->C is good. C->A exceeds error margin
*/
@Test
void failOnCtoA() {
DogArray<TupleDesc_F64> featuresA = UtilFeature.createArrayF64(1);
DogArray<TupleDesc_F64> featuresB = UtilFeature.createArrayF64(1);
DogArray<TupleDesc_F64> featuresC = UtilFeature.createArrayF64(1);
DogArray_I32 featuresSetA = new DogArray_I32();
DogArray_I32 featuresSetB = new DogArray_I32();
DogArray_I32 featuresSetC = new DogArray_I32();
featuresB.grow().setTo(234234234);
featuresC.grow().setTo(2344234);
featuresC.grow().setTo(99234234);
for (int i = 0; i < 10; i++) {
featuresA.grow().setTo(i);
featuresB.grow().setTo(i + 0.1);
featuresC.grow().setTo(i + 0.2);
}
// there is only one set
featuresSetA.resize(featuresA.size);
featuresSetA.fill(0);
featuresSetB.resize(featuresB.size);
featuresSetB.fill(0);
featuresSetC.resize(featuresC.size);
featuresSetC.fill(0);
double maxError = 0.1 * 0.1 + 0.00000001;
ScoreAssociation<TupleDesc_F64> score = FactoryAssociation.defaultScore(TupleDesc_F64.class);
AssociateDescription<TupleDesc_F64> associate = FactoryAssociation.greedy(new ConfigAssociateGreedy(true, maxError), score);
AssociateThreeByPairs<TupleDesc_F64> alg = new AssociateThreeByPairs<>(associate);
alg.initialize(1);
alg.setFeaturesA(featuresA, featuresSetA);
alg.setFeaturesB(featuresB, featuresSetB);
alg.setFeaturesC(featuresC, featuresSetC);
alg.associate();
DogArray<AssociatedTripleIndex> matches = alg.getMatches();
assertEquals(0, matches.size);
}
use of boofcv.struct.feature.AssociatedTripleIndex in project BoofCV by lessthanoptimal.
the class TestAssociateThreeByPairs method perfect.
@Test
void perfect() {
DogArray<TupleDesc_F64> featuresA = UtilFeature.createArrayF64(1);
DogArray<TupleDesc_F64> featuresB = UtilFeature.createArrayF64(1);
DogArray<TupleDesc_F64> featuresC = UtilFeature.createArrayF64(1);
DogArray_I32 featuresSetA = new DogArray_I32();
DogArray_I32 featuresSetB = new DogArray_I32();
DogArray_I32 featuresSetC = new DogArray_I32();
featuresB.grow().setTo(234234234);
featuresC.grow().setTo(2344234);
featuresC.grow().setTo(99234234);
for (int i = 0; i < 10; i++) {
featuresA.grow().setTo(i);
featuresB.grow().setTo(i);
featuresC.grow().setTo(i);
}
// there is only one set
featuresSetA.resize(featuresA.size);
featuresSetA.fill(0);
featuresSetB.resize(featuresB.size);
featuresSetB.fill(0);
featuresSetC.resize(featuresC.size);
featuresSetC.fill(0);
ScoreAssociation<TupleDesc_F64> score = FactoryAssociation.defaultScore(TupleDesc_F64.class);
AssociateDescription<TupleDesc_F64> associate = FactoryAssociation.greedy(new ConfigAssociateGreedy(true, 1e-8), score);
AssociateThreeByPairs<TupleDesc_F64> alg = new AssociateThreeByPairs<>(associate);
alg.initialize(1);
alg.setFeaturesA(featuresA, featuresSetA);
alg.setFeaturesB(featuresB, featuresSetB);
alg.setFeaturesC(featuresC, featuresSetC);
alg.associate();
DogArray<AssociatedTripleIndex> matches = alg.getMatches();
assertEquals(10, matches.size);
for (int i = 0; i < 10; i++) {
AssociatedTripleIndex a = matches.get(i);
assertEquals(i, a.a);
assertEquals(i + 1, a.b);
assertEquals(i + 2, a.c);
}
}
use of boofcv.struct.feature.AssociatedTripleIndex in project BoofCV by lessthanoptimal.
the class AssociateThreeByPairs method associate.
@Override
public void associate() {
sanityCheck();
matches.reset();
// Associate view A to view B
UtilFeature.setSource(featuresA, setsA, associator);
UtilFeature.setDestination(featuresB, setsB, associator);
associator.associate();
FastAccess<AssociatedIndex> pairs = associator.getMatches();
tmpA.resize(pairs.size);
tmpSetsA.resize(pairs.size);
tmpB.resize(pairs.size);
tmpSetsB.resize(pairs.size);
for (int i = 0; i < pairs.size; i++) {
AssociatedIndex p = pairs.get(i);
matches.grow().setTo(p.src, p.dst, -1);
// indexes of tmp lists will be the same as matches
tmpA.data[i] = featuresA.data[p.src];
tmpB.data[i] = featuresB.data[p.dst];
tmpSetsA.data[i] = setsA.data[p.src];
tmpSetsB.data[i] = setsB.data[p.dst];
}
// Associate view B to view C, but only consider previously associated features in B
UtilFeature.setSource(tmpB, tmpSetsB, associator);
UtilFeature.setDestination(featuresC, setsC, associator);
associator.associate();
pairs = associator.getMatches();
tmpB.resize(pairs.size);
tmpSetsB.resize(pairs.size);
srcToC.resize(pairs.size);
// do this to make the code easier to read
FastArray<TD> tmpC = tmpB;
DogArray_I32 tmpSetsC = tmpSetsB;
for (int i = 0; i < pairs.size; i++) {
AssociatedIndex p = pairs.get(i);
// tmpSrc points to indexes in matches
matches.get(p.src).c = p.dst;
tmpC.data[i] = featuresC.data[p.dst];
tmpSetsC.data[i] = setsC.data[p.dst];
// save mapping back to original input index
srcToC.data[i] = p.dst;
}
// mark the unmatched as unmatched
DogArray_I32 unsrc = associator.getUnassociatedSource();
for (int i = 0; i < unsrc.size; i++) {
int idx = unsrc.get(i);
matches.get(idx).c = -1;
}
// Associate view C to view A but only consider features which are currently in the triple
UtilFeature.setSource(tmpC, tmpSetsC, associator);
UtilFeature.setDestination(tmpA, tmpSetsA, associator);
associator.associate();
pairs = associator.getMatches();
for (int i = 0; i < pairs.size; i++) {
AssociatedIndex p = pairs.get(i);
AssociatedTripleIndex t = matches.get(p.dst);
// index of tmpA (destination) matches the index of matches
if (matches.get(p.dst).c != srcToC.data[p.src]) {
// mark it so that it will be pruned
t.c = -1;
}
}
DogArray_I32 undst = associator.getUnassociatedDestination();
for (int i = 0; i < undst.size; i++) {
int idx = undst.get(i);
matches.get(idx).c = -1;
}
// Prune triplets which don't match
pruneMatches();
}
Aggregations