use of boofcv.struct.feature.AssociatedIndex in project BoofCV by lessthanoptimal.
the class TestAssociateSurfBasic method basicAssociation.
@Test
public void basicAssociation() {
FastQueue<BrightFeature> src = new FastQueue<>(10, BrightFeature.class, false);
FastQueue<BrightFeature> dst = new FastQueue<>(10, BrightFeature.class, false);
// create a list where some should be matched and others not
src.add(createDesc(true, 10));
src.add(createDesc(true, 12));
src.add(createDesc(false, 5));
src.add(createDesc(false, 2344));
src.add(createDesc(false, 1000));
dst.add(createDesc(true, 0));
dst.add(createDesc(true, 10.1));
dst.add(createDesc(true, 13));
dst.add(createDesc(false, 0.1));
dst.add(createDesc(false, 7));
alg.setSrc(src);
alg.setDst(dst);
alg.associate();
FastQueue<AssociatedIndex> matches = alg.getMatches();
assertEquals(3, matches.size());
assertTrue(matches.get(0).fitScore != 0);
assertEquals(0, matches.get(0).src);
assertEquals(1, matches.get(0).dst);
assertTrue(matches.get(1).fitScore != 0);
assertEquals(1, matches.get(1).src);
assertEquals(2, matches.get(1).dst);
assertTrue(matches.get(2).fitScore != 0);
assertEquals(2, matches.get(2).src);
assertEquals(4, matches.get(2).dst);
// see if the expected number of features are in the unassociated list
GrowQueue_I32 unassoc = alg.unassociatedSrc;
assertEquals(2, unassoc.size);
// make sure none of the unassociated are contained in the associated list
for (int i = 0; i < unassoc.size; i++) {
int index = unassoc.data[i];
for (int j = 0; j < matches.size(); j++) {
if (matches.get(j).src == index)
fail("match found");
}
}
}
use of boofcv.struct.feature.AssociatedIndex in project narchy by automenta.
the class ExampleStereoTwoViewsOneCamera method computeMatches.
/**
* Use the associate point feature example to create a list of {@link AssociatedPair} for use in computing the
* fundamental matrix.
*/
public void computeMatches(GrayF32 left, GrayF32 right) {
DetectDescribePoint detDesc = FactoryDetectDescribe.surfStable(new ConfigFastHessian(1, 2, 0, 1, 9, 4, 4), null, null, GrayF32.class);
// DetectDescribePoint detDesc = FactoryDetectDescribe.sift(null,new ConfigSiftDetector(2,0,200,5),null,null);
ScoreAssociation<BrightFeature> scorer = FactoryAssociation.scoreEuclidean(BrightFeature.class, true);
AssociateDescription<BrightFeature> associate = FactoryAssociation.greedy(scorer, 0.9, true);
ExampleAssociatePoints<GrayF32, BrightFeature> findMatches = new ExampleAssociatePoints<>(detDesc, associate, GrayF32.class);
findMatches.associate(left, right);
FastQueue<AssociatedIndex> matchIndexes = associate.getMatches();
matchedFeatures.clear();
for (int i = 0; i < matchIndexes.size; i++) {
AssociatedIndex a = matchIndexes.get(i);
matchedFeatures.add(new AssociatedPair(findMatches.pointsA.get(a.src), findMatches.pointsB.get(a.dst)));
}
}
use of boofcv.struct.feature.AssociatedIndex in project BoofCV by lessthanoptimal.
the class AssociateUniqueByScoreAlg method processSource.
/**
* Selects a subset of matches that have at most one association for each source feature.
*/
private void processSource(FastQueue<AssociatedIndex> matches, int numSource, FastQueue<AssociatedIndex> output) {
// set up data structures
scores.resize(numSource);
solutions.resize(numSource);
for (int i = 0; i < numSource; 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.src];
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.src];
int result = type.compareTo(bestScore, a.fitScore);
if (result < 0) {
// found a better one, use this now
solutions.data[a.src] = i;
scores.data[a.src] = 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.src] = i;
scores.data[a.src] = a.fitScore;
} else if (result == 0) {
// two solutions have the same score
solutions.data[a.src] = -2;
}
}
} else {
// no previous match found
solutions.data[a.src] = i;
scores.data[a.src] = a.fitScore;
}
}
output.reset();
for (int i = 0; i < numSource; 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 EnsureUniqueAssociation method process.
/**
* Removes ambiguous associations. Call {@link #getMatches()} to get the list of unambiguous
* matches.
*
* @param matches List of candidate associations
* @param sizeDst Number of 'dst' features
*/
public void process(FastQueue<AssociatedIndex> matches, int sizeDst) {
// initialize data structures
if (bestScores.length < sizeDst)
bestScores = new AssociatedIndex[sizeDst];
for (int i = 0; i < matches.size; i++) {
AssociatedIndex match = matches.data[i];
if (bestScores[match.dst] == null || match.fitScore < bestScores[match.dst].fitScore) {
bestScores[match.dst] = match;
}
}
// add the best unambiguous pairs back
unambiguous.reset();
for (int i = 0; i < sizeDst; i++) {
if (bestScores[i] != null) {
unambiguous.add(bestScores[i]);
// clean up so that you don't have a dangling reference
bestScores[i] = null;
}
}
}
use of boofcv.struct.feature.AssociatedIndex in project BoofCV by lessthanoptimal.
the class AssociateSurfBasic method associate.
/**
* Associates the features together.
*/
public void associate() {
// initialize data structures
matches.reset();
unassociatedSrc.reset();
if (srcPositive.size == 0 && srcNegative.size == 0)
return;
if (dstPositive.size == 0 && dstNegative.size == 0)
return;
// find and add the matches
assoc.setSource((FastQueue) srcPositive);
assoc.setDestination((FastQueue) dstPositive);
assoc.associate();
FastQueue<AssociatedIndex> m = assoc.getMatches();
for (int i = 0; i < m.size; i++) {
AssociatedIndex a = m.data[i];
int globalSrcIndex = srcPositive.data[a.src].index;
int globalDstIndex = dstPositive.data[a.dst].index;
matches.grow().setAssociation(globalSrcIndex, globalDstIndex, a.fitScore);
}
GrowQueue_I32 un = assoc.getUnassociatedSource();
for (int i = 0; i < un.size; i++) {
unassociatedSrc.add(srcPositive.data[un.get(i)].index);
}
assoc.setSource((FastQueue) srcNegative);
assoc.setDestination((FastQueue) dstNegative);
assoc.associate();
m = assoc.getMatches();
for (int i = 0; i < m.size; i++) {
AssociatedIndex a = m.data[i];
int globalSrcIndex = srcNegative.data[a.src].index;
int globalDstIndex = dstNegative.data[a.dst].index;
matches.grow().setAssociation(globalSrcIndex, globalDstIndex, a.fitScore);
}
un = assoc.getUnassociatedSource();
for (int i = 0; i < un.size; i++) {
unassociatedSrc.add(srcNegative.data[un.get(i)].index);
}
}
Aggregations