Search in sources :

Example 1 with AssociatedIndex

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

Example 2 with AssociatedIndex

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

Example 3 with AssociatedIndex

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;
    }
}
Also used : AssociateDescription2D(boofcv.abst.feature.associate.AssociateDescription2D) Point2D_F64(georegression.struct.point.Point2D_F64) AssociatedIndex(boofcv.struct.feature.AssociatedIndex)

Example 4 with AssociatedIndex

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

Example 5 with AssociatedIndex

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

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