Search in sources :

Example 26 with PointTrack

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

the class VisOdomMonoPlaneInfinity method addNewTracks.

/**
 * Requests that new tracks are spawned, determines if they are on the plane or not, and computes other required
 * data structures.
 */
private void addNewTracks() {
    tracker.spawnTracks();
    List<PointTrack> spawned = tracker.getNewTracks(null);
    // estimate 3D coordinate using stereo vision
    for (PointTrack t : spawned) {
        // System.out.println("track spawn "+t.x+" "+t.y);
        VoTrack p = t.getCookie();
        if (p == null) {
            t.cookie = p = new VoTrack();
        }
        // compute normalized image coordinate
        pixelToNorm.compute(t.x, t.y, n);
        // See if the point ever intersects the ground plane or not
        if (planeProjection.normalToPlane(n.x, n.y, p.ground)) {
            // the line above computes the 2D plane position of the point
            p.onPlane = true;
        } else {
            // Handle points at infinity which are off plane.
            // rotate observation pointing vector into plane reference frame
            pointing.set(n.x, n.y, 1);
            GeometryMath_F64.mult(cameraToPlane.getR(), pointing, pointing);
            pointing.normalize();
            // save value of y-axis in pointing vector
            double normXZ = Math.sqrt(pointing.x * pointing.x + pointing.z * pointing.z);
            p.pointingY = pointing.y / normXZ;
            // save the angle as a vector
            p.ground.x = pointing.z;
            p.ground.y = -pointing.x;
            // normalize to make later calculations easier
            p.ground.x /= normXZ;
            p.ground.y /= normXZ;
            p.onPlane = false;
        }
        p.lastInlier = tick;
    }
}
Also used : PointTrack(boofcv.abst.feature.tracker.PointTrack)

Example 27 with PointTrack

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

the class VisOdomPixelDepthPnP 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<>();
    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);
    }
    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 28 with PointTrack

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

the class VisOdomPixelDepthPnP method addNewTracks.

/**
 * Detects new features and computes their 3D coordinates
 */
private void addNewTracks() {
    // System.out.println("----------- Adding new tracks ---------------");
    tracker.spawnTracks();
    List<PointTrack> spawned = tracker.getNewTracks(null);
    // estimate 3D coordinate using stereo vision
    for (PointTrack t : spawned) {
        Point2D3DTrack p = t.getCookie();
        if (p == null) {
            t.cookie = p = new Point2D3DTrack();
        }
        // discard point if it can't localized
        if (!pixelTo3D.process(t.x, t.y) || pixelTo3D.getW() == 0) {
            tracker.dropTrack(t);
        } else {
            Point3D_F64 X = p.getLocation();
            double w = pixelTo3D.getW();
            X.set(pixelTo3D.getX() / w, pixelTo3D.getY() / w, pixelTo3D.getZ() / w);
            // translate the point into the key frame
            // SePointOps_F64.transform(currToKey,X,X);
            // not needed since the current frame was just set to be the key frame
            p.lastInlier = tick;
            pixelToNorm.compute(t.x, t.y, p.observation);
        }
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) PointTrack(boofcv.abst.feature.tracker.PointTrack) Point2D3DTrack(boofcv.struct.sfm.Point2D3DTrack)

Example 29 with PointTrack

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

the class VisOdomPixelDepthPnP 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)

Example 30 with PointTrack

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

the class WrapImageMotionPtkSmartRespawn method checkInitialize.

private void checkInitialize() {
    if (!inliersMarked) {
        inliersMarked = true;
        List<PointTrack> active = alg.getMotion().getTracker().getActiveTracks(null);
        allTracks.clear();
        long tick = alg.getMotion().getTotalFramesProcessed();
        inliers.resize(active.size());
        for (int i = 0; i < active.size(); i++) {
            PointTrack t = active.get(i);
            AssociatedPairTrack info = t.getCookie();
            allTracks.add(t);
            // if it was used in the previous update then it is in the inlier set
            inliers.data[i] = info.lastUsed == tick;
        }
    }
}
Also used : AssociatedPairTrack(boofcv.alg.sfm.d2.AssociatedPairTrack) PointTrack(boofcv.abst.feature.tracker.PointTrack)

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