use of boofcv.struct.feature.AssociatedIndex in project BoofCV by lessthanoptimal.
the class TestAssociateNearestNeighbor method various.
/**
* Several tests combined into one
*/
@Test
public void various() {
Dummy<Integer> nn = new Dummy<>();
// src = assoc[i] where src is the index of the source feature and i is the index of the dst feature
nn.assoc = new int[] { 2, 0, 1, -1, 4, -1, -1, 2, 2, 1 };
AssociateNearestNeighbor<TupleDesc_F64> alg = new AssociateNearestNeighbor<>(nn, 10);
FastQueue<TupleDesc_F64> src = new FastQueue<>(10, TupleDesc_F64.class, false);
FastQueue<TupleDesc_F64> dst = new FastQueue<>(10, TupleDesc_F64.class, false);
for (int i = 0; i < 5; i++) {
src.add(new TupleDesc_F64(10));
}
for (int i = 0; i < 10; i++) {
dst.add(new TupleDesc_F64(10));
}
alg.setSource(src);
alg.setDestination(dst);
alg.associate();
FastQueue<AssociatedIndex> matches = alg.getMatches();
assertTrue(nn.pointDimension == 10);
assertEquals(7, matches.size);
for (int i = 0, count = 0; i < nn.assoc.length; i++) {
if (nn.assoc[i] != -1) {
int source = nn.assoc[i];
assertEquals(source, matches.get(count).src);
assertEquals(i, matches.get(count).dst);
count++;
}
}
GrowQueue_I32 unassoc = alg.getUnassociatedSource();
assertEquals(1, unassoc.size);
assertEquals(3, unassoc.get(0));
unassoc = alg.getUnassociatedDestination();
assertEquals(3, unassoc.size);
assertEquals(3, unassoc.get(0));
assertEquals(5, unassoc.get(1));
assertEquals(6, unassoc.get(2));
}
use of boofcv.struct.feature.AssociatedIndex in project BoofCV by lessthanoptimal.
the class AssociateUniqueByScoreAlg method processDestination.
/**
* Selects a subset of matches that have at most one association for each destination feature.
*/
private void processDestination(FastQueue<AssociatedIndex> matches, int numDestination, FastQueue<AssociatedIndex> output) {
// set up data structures
scores.resize(numDestination);
solutions.resize(numDestination);
for (int i = 0; i < numDestination; i++) {
solutions.data[i] = -1;
}
// select best matches
for (int i = 0; i < matches.size(); i++) {
AssociatedIndex a = matches.get(i);
int found = solutions.data[a.dst];
if (found != -1) {
if (found == -2) {
// the best solution is invalid because two or more had the same score, see if this is better
double bestScore = scores.data[a.dst];
int result = type.compareTo(bestScore, a.fitScore);
if (result < 0) {
// found a better one, use this now
solutions.data[a.dst] = i;
scores.data[a.dst] = a.fitScore;
}
} else {
// see if this new score is better than the current best
AssociatedIndex currentBest = matches.get(found);
int result = type.compareTo(currentBest.fitScore, a.fitScore);
if (result < 0) {
// found a better one, use this now
solutions.data[a.dst] = i;
scores.data[a.dst] = a.fitScore;
} else if (result == 0) {
// two solutions have the same score
solutions.data[a.dst] = -2;
}
}
} else {
// no previous match found
solutions.data[a.dst] = i;
scores.data[a.dst] = i;
}
}
output.reset();
for (int i = 0; i < numDestination; i++) {
int index = solutions.data[i];
if (index >= 0) {
output.add(matches.get(index));
}
}
}
use of boofcv.struct.feature.AssociatedIndex in project BoofCV by lessthanoptimal.
the class BaseAssociateLocation2DFilter method associate.
@Override
public void associate() {
unassociatedSrc.reset();
matched.reset();
for (int i = 0; i < locationSrc.size(); i++) {
Point2D_F64 p_s = locationSrc.get(i);
D d_s = descSrc.get(i);
setActiveSource(p_s);
double bestScore = maxError;
int bestIndex = -1;
// find the best match in destination list
for (int j = 0; j < locationDst.size(); j++) {
D d_d = descDst.get(j);
// compute distance between the two features
double distance = computeDistanceToSource(locationDst.get(j));
if (distance > maxDistance)
continue;
double score = scoreAssociation.score(d_s, d_d);
if (score < bestScore) {
bestScore = score;
bestIndex = j;
}
}
if (bestIndex == -1) {
unassociatedSrc.add(i);
continue;
}
if (backwardsValidation && !backwardsValidation(i, bestIndex)) {
unassociatedSrc.add(i);
continue;
}
AssociatedIndex m = matched.grow();
m.src = i;
m.dst = bestIndex;
m.fitScore = bestScore;
}
}
use of boofcv.struct.feature.AssociatedIndex in project BoofCV by lessthanoptimal.
the class VisOdomQuadPnP method removeUnassociated.
private void removeUnassociated(FastQueue<Point2D_F64> leftLoc, FastQueue<TD> leftDesc, FastQueue<Point2D_F64> rightLoc, FastQueue<TD> rightDesc, FastQueue<AssociatedIndex> matches) {
int N = Math.max(leftLoc.size, rightLoc.size);
if (usedLeft.length < N) {
usedLeft = new boolean[N];
usedRight = new boolean[N];
oldToNewLeft = new int[N];
oldToNewRight = new int[N];
} else {
for (int i = 0; i < N; i++) {
usedLeft[i] = false;
usedRight[i] = false;
}
}
for (int i = 0; i < matches.size; i++) {
AssociatedIndex a = matches.get(i);
usedLeft[a.src] = true;
usedRight[a.dst] = true;
}
removeUnused(leftLoc, leftDesc, usedLeft, oldToNewLeft);
removeUnused(rightLoc, rightDesc, usedRight, oldToNewRight);
// update association list
for (int i = 0; i < matches.size; i++) {
AssociatedIndex a = matches.get(i);
a.src = oldToNewLeft[a.src];
a.dst = oldToNewRight[a.dst];
}
}
use of boofcv.struct.feature.AssociatedIndex in project BoofCV by lessthanoptimal.
the class VisOdomQuadPnP method setMatches.
private void setMatches(GrowQueue_I32 matches, FastQueue<AssociatedIndex> found, int sizeSrc) {
matches.resize(sizeSrc);
for (int j = 0; j < sizeSrc; j++) {
matches.data[j] = -1;
}
for (int j = 0; j < found.size; j++) {
AssociatedIndex a = found.get(j);
matches.data[a.src] = a.dst;
}
}
Aggregations