Search in sources :

Example 16 with PointTrack

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

the class ExamplePointFeatureTracker method updateGUI.

/**
 * Draw tracked features in blue, or red if they were just spawned.
 */
private void updateGUI(SimpleImageSequence<T> sequence) {
    BufferedImage orig = sequence.getGuiImage();
    Graphics2D g2 = orig.createGraphics();
    // draw tracks with semi-unique colors so you can track individual points with your eyes
    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.pixel.x, (int) p.pixel.y, new Color(red, green, blue));
    }
    // draw tracks which have just been spawned green
    for (PointTrack p : tracker.getNewTracks(null)) {
        VisualizeFeatures.drawPoint(g2, (int) p.pixel.x, (int) p.pixel.y, Color.green);
    }
    // tell the GUI to update
    gui.setImage(orig);
    gui.repaint();
}
Also used : PointTrack(boofcv.abst.tracker.PointTrack) BufferedImage(java.awt.image.BufferedImage)

Example 17 with PointTrack

use of boofcv.abst.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
    ConfigPointDetector configDetector = new ConfigPointDetector();
    configDetector.type = PointDetectorTypes.SHI_TOMASI;
    configDetector.general.radius = 8;
    configDetector.general.threshold = 1;
    ConfigPKlt configKlt = new ConfigPKlt(3);
    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.pixel.x, (int) t.pixel.y, Color.RED);
        }
        gui.setImageUI(image);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) PointTrack(boofcv.abst.tracker.PointTrack) Webcam(com.github.sarxos.webcam.Webcam) ConfigPKlt(boofcv.alg.tracker.klt.ConfigPKlt) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ConfigPointDetector(boofcv.abst.feature.detect.interest.ConfigPointDetector) ImagePanel(boofcv.gui.image.ImagePanel)

Example 18 with PointTrack

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

the class DetectDescribeAssociateTracker method performTracking.

/**
 * Associate detections to tracks
 */
protected void performTracking() {
    // Create a list for association from all tracks
    final int numTracks = tracksAll.size();
    srcDesc.resize(numTracks);
    srcPixels.resize(numTracks);
    srcSet.resize(numTracks);
    for (int i = 0; i < numTracks; i++) {
        PointTrack t = tracksAll.get(i);
        srcDesc.data[i] = t.getDescription();
        srcPixels.data[i] = t.pixel;
        srcSet.data[i] = t.detectorSetId;
    }
    // Associate existing tracks with detections
    UtilFeature.setSource(srcDesc, srcSet, srcPixels, associate);
    UtilFeature.setDestination(dstDesc, dstSet, dstPixels, associate);
    associate.associate();
    FastAccess<AssociatedIndex> matches = associate.getMatches();
    for (int i = 0; i < matches.size; i++) {
        AssociatedIndex indexes = matches.data[i];
        PointTrack track = tracksAll.get(indexes.src);
        Point2D_F64 loc = dstPixels.data[indexes.dst];
        track.pixel.setTo(loc.x, loc.y);
        track.lastSeenFrameID = frameID;
        tracksActive.add(track);
        // update the description
        if (updateDescription) {
            ((TD) track.getDescription()).setTo(dstDesc.get(indexes.dst));
        }
    }
}
Also used : PointTrack(boofcv.abst.tracker.PointTrack) Point2D_F64(georegression.struct.point.Point2D_F64) DetectDescribePoint(boofcv.abst.feature.detdesc.DetectDescribePoint) AssociatedIndex(boofcv.struct.feature.AssociatedIndex)

Example 19 with PointTrack

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

the class TestPruneCloseTracks method bruteForce.

List<PointTrack> bruteForce(List<PointTrack> tracks, int radius) {
    List<PointTrack> dropped = new ArrayList<>();
    for (int i = 0; i < tracks.size(); i++) {
        PointTrack a = tracks.get(i);
        boolean keep = true;
        for (int j = 0; j < tracks.size(); j++) {
            if (i == j)
                continue;
            PointTrack b = tracks.get(j);
            double d = Math.max(Math.abs(a.pixel.x - b.pixel.x), Math.abs(a.pixel.y - b.pixel.y));
            if (d < radius) {
                if (a.featureId > b.featureId) {
                    keep = false;
                    break;
                }
            }
        }
        if (!keep) {
            dropped.add(tracks.get(i));
        }
    }
    return dropped;
}
Also used : PointTrack(boofcv.abst.tracker.PointTrack) ArrayList(java.util.ArrayList)

Example 20 with PointTrack

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

the class TestPruneCloseTracks method negative.

@Test
void negative() {
    var alg = PruneCloseTracks.prunePointTrack(2);
    alg.init(10, 20);
    var tracks = new ArrayList<PointTrack>();
    // 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, 6, 6));
    var dropped = new ArrayList<PointTrack>();
    alg.process(tracks, dropped);
    assertEquals(0, dropped.size());
}
Also used : PointTrack(boofcv.abst.tracker.PointTrack) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

PointTrack (boofcv.abst.tracker.PointTrack)44 Test (org.junit.jupiter.api.Test)11 Frame (boofcv.alg.similar.SimilarImagesFromTracks.Frame)5 ArrayList (java.util.ArrayList)5 BTrack (boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack)3 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)3 Point2D_F64 (georegression.struct.point.Point2D_F64)3 Point3D_F64 (georegression.struct.point.Point3D_F64)3 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)2 Match (boofcv.alg.similar.SimilarImagesFromTracks.Match)2 CameraPinhole (boofcv.struct.calib.CameraPinhole)2 GrayU8 (boofcv.struct.image.GrayU8)2 BufferedImage (java.awt.image.BufferedImage)2 DogArray (org.ddogleg.struct.DogArray)2 ScoreAssociateEuclideanSq (boofcv.abst.feature.associate.ScoreAssociateEuclideanSq)1 ConfigPointDetector (boofcv.abst.feature.detect.interest.ConfigPointDetector)1 AssociatedPairTrack (boofcv.alg.sfm.d2.AssociatedPairTrack)1 VisOdomMonoPlaneInfinity (boofcv.alg.sfm.d3.VisOdomMonoPlaneInfinity)1 ConfigPKlt (boofcv.alg.tracker.klt.ConfigPKlt)1 ImagePanel (boofcv.gui.image.ImagePanel)1