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();
}
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;
}
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;
}
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;
}
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;
}
Aggregations