Search in sources :

Example 31 with PointTrack

use of boofcv.abst.feature.tracker.PointTrack in project BoofCV by lessthanoptimal.

the class MonoPlaneInfinity_to_MonocularPlaneVisualOdometry method isInlier.

@Override
public boolean isInlier(int index) {
    if (active == null)
        active = alg.getTracker().getActiveTracks(null);
    PointTrack t = active.get(index);
    VisOdomMonoPlaneInfinity.VoTrack v = t.getCookie();
    return v.lastInlier == alg.getTick();
}
Also used : PointTrack(boofcv.abst.feature.tracker.PointTrack) VisOdomMonoPlaneInfinity(boofcv.alg.sfm.d3.VisOdomMonoPlaneInfinity)

Example 32 with PointTrack

use of boofcv.abst.feature.tracker.PointTrack in project BoofCV by lessthanoptimal.

the class ImageMotionPointTrackerKey method process.

/**
 * Processes the next frame in the sequence.
 *
 * @param frame Next frame in the video sequence
 * @return true if motion was estimated and false if no motion was estimated
 */
public boolean process(I frame) {
    keyFrame = false;
    // update the feature tracker
    tracker.process(frame);
    totalFramesProcessed++;
    List<PointTrack> tracks = tracker.getActiveTracks(null);
    if (tracks.size() == 0)
        return false;
    List<AssociatedPair> pairs = new ArrayList<>();
    for (PointTrack t : tracks) {
        pairs.add((AssociatedPair) t.getCookie());
    }
    // fit the motion model to the feature tracks
    if (!modelMatcher.process((List) pairs)) {
        return false;
    }
    if (modelRefiner != null) {
        if (!modelRefiner.fitModel(modelMatcher.getMatchSet(), modelMatcher.getModelParameters(), keyToCurr))
            return false;
    } else {
        keyToCurr.set(modelMatcher.getModelParameters());
    }
    // mark that the track is in the inlier set
    for (AssociatedPair p : modelMatcher.getMatchSet()) {
        ((AssociatedPairTrack) p).lastUsed = totalFramesProcessed;
    }
    // prune tracks which aren't being used
    pruneUnusedTracks();
    // Update the motion
    worldToKey.concat(keyToCurr, worldToCurr);
    return true;
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) PointTrack(boofcv.abst.feature.tracker.PointTrack) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 33 with PointTrack

use of boofcv.abst.feature.tracker.PointTrack in project BoofCV by lessthanoptimal.

the class ImageMotionPointTrackerKey method changeKeyFrame.

/**
 * Change the current frame into the keyframe. p1 location of existing tracks is set to
 * their current location and new tracks are spawned.  Reference frame transformations are also updated
 */
public void changeKeyFrame() {
    // drop all inactive tracks since their location is unknown in the current frame
    List<PointTrack> inactive = tracker.getInactiveTracks(null);
    for (PointTrack l : inactive) {
        tracker.dropTrack(l);
    }
    // set the keyframe for active tracks as their current location
    List<PointTrack> active = tracker.getActiveTracks(null);
    for (PointTrack l : active) {
        AssociatedPairTrack p = l.getCookie();
        p.p1.set(l);
        p.lastUsed = totalFramesProcessed;
    }
    tracker.spawnTracks();
    List<PointTrack> spawned = tracker.getNewTracks(null);
    for (PointTrack l : spawned) {
        AssociatedPairTrack p = l.getCookie();
        if (p == null) {
            l.cookie = p = new AssociatedPairTrack();
            // little bit of trickery here.  Save the reference so that the point
            // in the current frame is updated for free as PointTrack is
            p.p2 = l;
        }
        p.p1.set(l);
        p.lastUsed = totalFramesProcessed;
    }
    worldToKey.set(worldToCurr);
    keyToCurr.reset();
    keyFrame = true;
}
Also used : PointTrack(boofcv.abst.feature.tracker.PointTrack)

Example 34 with PointTrack

use of boofcv.abst.feature.tracker.PointTrack in project MAVSlam by ecmnet.

the class MAVOdomPixelDepthPnP method estimateMotion.

/**
 * Estimates motion from the set of tracks and their 3D location
 *
 * @return true if successful.
 */
private boolean estimateMotion() {
    List<PointTrack> active = tracker.getActiveTracks(null);
    List<Point2D3D> obs = new ArrayList<Point2D3D>();
    for (PointTrack t : active) {
        Point2D3D p = t.getCookie();
        pixelToNorm.compute(t.x, t.y, p.observation);
        obs.add(p);
    }
    // estimate the motion up to a scale factor in translation
    if (!motionEstimator.process(obs))
        return false;
    if (doublePass) {
        if (!performSecondPass(active, obs))
            return false;
    }
    tracker.finishTracking();
    Se3_F64 keyToCurr;
    if (refine != null) {
        keyToCurr = new Se3_F64();
        refine.fitModel(motionEstimator.getMatchSet(), motionEstimator.getModelParameters(), keyToCurr);
    } else {
        keyToCurr = motionEstimator.getModelParameters();
    }
    keyToCurr.invert(currToKey);
    // mark tracks as being inliers and add to inlier list
    int N = motionEstimator.getMatchSet().size();
    for (int i = 0; i < N; i++) {
        int index = motionEstimator.getInputIndex(i);
        Point2D3DTrack t = active.get(index).getCookie();
        t.lastInlier = tick;
        inlierTracks.add(t);
    }
    this.quality = (3 * quality + motionEstimator.getFitQuality()) / 4f;
    return true;
}
Also used : Point2D3D(boofcv.struct.geo.Point2D3D) PointTrack(boofcv.abst.feature.tracker.PointTrack) ArrayList(java.util.ArrayList) Point2D3DTrack(boofcv.struct.sfm.Point2D3DTrack) Se3_F64(georegression.struct.se.Se3_F64)

Example 35 with PointTrack

use of boofcv.abst.feature.tracker.PointTrack in project MAVSlam by ecmnet.

the class MAVOdomPixelDepthPnP method dropUnusedTracks.

/**
 * Removes tracks which have not been included in the inlier set recently
 *
 * @return Number of dropped tracks
 */
private int dropUnusedTracks() {
    List<PointTrack> all = tracker.getAllTracks(null);
    int num = 0;
    for (PointTrack t : all) {
        Point2D3DTrack p = t.getCookie();
        if (tick - p.lastInlier > thresholdRetire) {
            tracker.dropTrack(t);
            num++;
        }
    }
    return num;
}
Also used : PointTrack(boofcv.abst.feature.tracker.PointTrack) Point2D3DTrack(boofcv.struct.sfm.Point2D3DTrack)

Aggregations

PointTrack (boofcv.abst.feature.tracker.PointTrack)37 Se3_F64 (georegression.struct.se.Se3_F64)9 Point2D3DTrack (boofcv.struct.sfm.Point2D3DTrack)8 ArrayList (java.util.ArrayList)7 DescribeRegionPoint (boofcv.abst.feature.describe.DescribeRegionPoint)6 Point2D3D (boofcv.struct.geo.Point2D3D)5 Point3D_F64 (georegression.struct.point.Point3D_F64)5 Stereo2D3D (boofcv.struct.sfm.Stereo2D3D)3 BufferedImage (java.awt.image.BufferedImage)3 Test (org.junit.Test)3 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)2 PkltConfig (boofcv.alg.tracker.klt.PkltConfig)2 ImagePanel (boofcv.gui.image.ImagePanel)2 Webcam (com.github.sarxos.webcam.Webcam)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 AssociatedPairTrack (boofcv.alg.sfm.d2.AssociatedPairTrack)1 VisOdomMonoPlaneInfinity (boofcv.alg.sfm.d3.VisOdomMonoPlaneInfinity)1 ConvertBufferedImage (boofcv.core.image.ConvertBufferedImage)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)1