Search in sources :

Example 11 with AssociatedIndex

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");
        }
    }
}
Also used : BrightFeature(boofcv.struct.feature.BrightFeature) FastQueue(org.ddogleg.struct.FastQueue) AssociatedIndex(boofcv.struct.feature.AssociatedIndex) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 12 with AssociatedIndex

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)));
    }
}
Also used : DetectDescribePoint(boofcv.abst.feature.detdesc.DetectDescribePoint) AssociatedPair(boofcv.struct.geo.AssociatedPair) BrightFeature(boofcv.struct.feature.BrightFeature) ConfigFastHessian(boofcv.abst.feature.detect.interest.ConfigFastHessian) DetectDescribePoint(boofcv.abst.feature.detdesc.DetectDescribePoint) AssociatedIndex(boofcv.struct.feature.AssociatedIndex)

Example 13 with AssociatedIndex

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));
        }
    }
}
Also used : AssociatedIndex(boofcv.struct.feature.AssociatedIndex)

Example 14 with AssociatedIndex

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;
        }
    }
}
Also used : AssociatedIndex(boofcv.struct.feature.AssociatedIndex)

Example 15 with AssociatedIndex

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);
    }
}
Also used : AssociatedIndex(boofcv.struct.feature.AssociatedIndex) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Aggregations

AssociatedIndex (boofcv.struct.feature.AssociatedIndex)24 Point2D_F64 (georegression.struct.point.Point2D_F64)10 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)8 ArrayList (java.util.ArrayList)8 GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)6 AssociatedPair (boofcv.struct.geo.AssociatedPair)4 BrightFeature (boofcv.struct.feature.BrightFeature)3 Point3D_F64 (georegression.struct.point.Point3D_F64)3 Test (org.junit.Test)3 ConfigFastHessian (boofcv.abst.feature.detect.interest.ConfigFastHessian)2 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)2 GrayF32 (boofcv.struct.image.GrayF32)2 Se3_F64 (georegression.struct.se.Se3_F64)2 FastQueue (org.ddogleg.struct.FastQueue)2 AssociateDescription2D (boofcv.abst.feature.associate.AssociateDescription2D)1 DescribeRegionPoint (boofcv.abst.feature.describe.DescribeRegionPoint)1 PointTrack (boofcv.abst.feature.tracker.PointTrack)1 ExampleAssociatePoints (boofcv.examples.features.ExampleAssociatePoints)1 AssociationPanel (boofcv.gui.feature.AssociationPanel)1 TupleDesc (boofcv.struct.feature.TupleDesc)1