Search in sources :

Example 11 with PointTrack

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);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) PointTrack(boofcv.abst.feature.tracker.PointTrack) PkltConfig(boofcv.alg.tracker.klt.PkltConfig) ConfigGeneralDetector(boofcv.abst.feature.detect.interest.ConfigGeneralDetector) Webcam(com.github.sarxos.webcam.Webcam) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ImagePanel(boofcv.gui.image.ImagePanel)

Example 12 with PointTrack

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);
}
Also used : PointTrack(boofcv.abst.feature.tracker.PointTrack)

Example 13 with PointTrack

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);
}
Also used : PointTrack(boofcv.abst.feature.tracker.PointTrack) GrayU8(boofcv.struct.image.GrayU8) Se2_F32(georegression.struct.se.Se2_F32) Test(org.junit.Test)

Example 14 with PointTrack

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());
}
Also used : PointTrack(boofcv.abst.feature.tracker.PointTrack) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 15 with PointTrack

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());
}
Also used : PointTrack(boofcv.abst.feature.tracker.PointTrack) ArrayList(java.util.ArrayList) Test(org.junit.Test)

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