use of boofcv.abst.feature.tracker.PointTrack in project BoofCV by lessthanoptimal.
the class ExampleTrackingKlt method main.
public static void main(String[] args) {
// tune the tracker for the image size and visual appearance
ConfigGeneralDetector configDetector = new ConfigGeneralDetector(-1, 8, 1);
PkltConfig configKlt = new PkltConfig(3, new int[] { 1, 2, 4, 8 });
PointTracker<GrayF32> tracker = FactoryPointTracker.klt(configKlt, configDetector, GrayF32.class, null);
// Open a webcam at a resolution close to 640x480
Webcam webcam = UtilWebcamCapture.openDefault(640, 480);
// Create the panel used to display the image and feature tracks
ImagePanel gui = new ImagePanel();
gui.setPreferredSize(webcam.getViewSize());
ShowImages.showWindow(gui, "KLT Tracker", true);
int minimumTracks = 100;
while (true) {
BufferedImage image = webcam.getImage();
GrayF32 gray = ConvertBufferedImage.convertFrom(image, (GrayF32) null);
tracker.process(gray);
List<PointTrack> tracks = tracker.getActiveTracks(null);
// Spawn tracks if there are too few
if (tracks.size() < minimumTracks) {
tracker.spawnTracks();
tracks = tracker.getActiveTracks(null);
minimumTracks = tracks.size() / 2;
}
// Draw the tracks
Graphics2D g2 = image.createGraphics();
for (PointTrack t : tracks) {
VisualizeFeatures.drawPoint(g2, (int) t.x, (int) t.y, Color.RED);
}
gui.setImageUI(image);
}
}
use of boofcv.abst.feature.tracker.PointTrack in project BoofCV by lessthanoptimal.
the class VideoTrackerPointFeaturesApp method renderFeatures.
void renderFeatures(BufferedImage orig, double trackerFPS) {
Graphics2D g2 = workImage.createGraphics();
g2.drawImage(orig, 0, 0, orig.getWidth(), orig.getHeight(), null);
for (PointTrack p : tracker.getActiveTracks(null)) {
int red = (int) (2.5 * (p.featureId % 100));
int green = (int) ((255.0 / 150.0) * (p.featureId % 150));
int blue = (int) (p.featureId % 255);
VisualizeFeatures.drawPoint(g2, (int) p.x, (int) p.y, new Color(red, green, blue));
}
for (PointTrack p : tracker.getNewTracks(null)) {
int x = (int) p.x;
int y = (int) p.y;
VisualizeFeatures.drawPoint(g2, x, y, Color.green);
}
g2.setColor(Color.WHITE);
g2.fillRect(5, 15, 140, 20);
g2.setColor(Color.BLACK);
g2.drawString(String.format("Tracker FPS: %3.1f", trackerFPS), 10, 30);
}
use of boofcv.abst.feature.tracker.PointTrack in project BoofCV by lessthanoptimal.
the class TestImageMotionPointTrackerKey method testPrune.
/**
* See if tracks are pruned after not being in inlier set for X time
*/
@Test
public void testPrune() {
Se2_F32 computed = new Se2_F32(4, 5, 6);
Se2_F32 model = new Se2_F32();
DummyTracker tracker = new DummyTracker();
DummyModelMatcher<Se2_F32> matcher = new DummyModelMatcher<>(computed, 5);
GrayU8 input = new GrayU8(20, 30);
ImageMotionPointTrackerKey<GrayU8, Se2_F32> alg = new ImageMotionPointTrackerKey<>(tracker, matcher, null, model, 5);
// create tracks such that only some of them will be dropped
alg.totalFramesProcessed = 9;
for (int i = 0; i < 10; i++) {
PointTrack t = new PointTrack();
AssociatedPairTrack a = new AssociatedPairTrack();
a.lastUsed = i;
t.cookie = a;
tracker.list.add(t);
}
// update
alg.process(input);
// check to see how many were dropped
assertEquals(6, tracker.numDropped);
}
use of boofcv.abst.feature.tracker.PointTrack in project BoofCV by lessthanoptimal.
the class TestPruneCloseTracks method positive.
@Test
public void positive() {
PruneCloseTracks alg = new PruneCloseTracks(2, 10, 20);
List<PointTrack> tracks = new ArrayList<>();
tracks.add(new PointTrack(0, 3, 4));
tracks.add(new PointTrack(0, 0, 0));
tracks.add(new PointTrack(0, 2, 4));
List<PointTrack> dropped = new ArrayList<>();
alg.process(tracks, dropped);
assertEquals(1, dropped.size());
}
use of boofcv.abst.feature.tracker.PointTrack in project BoofCV by lessthanoptimal.
the class TestPruneCloseTracks method negative.
@Test
public void negative() {
PruneCloseTracks alg = new PruneCloseTracks(2, 10, 20);
List<PointTrack> tracks = new ArrayList<>();
// space them out far enough so that non of them should be dropped
tracks.add(new PointTrack(0, 3, 4));
tracks.add(new PointTrack(0, 0, 0));
tracks.add(new PointTrack(0, 5, 6));
List<PointTrack> dropped = new ArrayList<>();
alg.process(tracks, dropped);
assertEquals(0, dropped.size());
}
Aggregations