Search in sources :

Example 1 with TrackerMeanShiftLikelihood

use of boofcv.alg.tracker.meanshift.TrackerMeanShiftLikelihood in project BoofCV by lessthanoptimal.

the class ExampleTrackerMeanShiftLikelihood method main.

public static void main(String[] args) {
    MediaManager media = DefaultMediaManager.INSTANCE;
    String fileName = UtilIO.pathExample("tracking/balls_blue_red.mjpeg");
    RectangleLength2D_I32 location = new RectangleLength2D_I32(394, 247, 475 - 394, 325 - 247);
    ImageType<Planar<GrayU8>> imageType = ImageType.pl(3, GrayU8.class);
    SimpleImageSequence<Planar<GrayU8>> video = media.openVideo(fileName, imageType);
    // Return a higher likelihood for pixels close to this RGB color
    RgbLikelihood likelihood = new RgbLikelihood(64, 71, 69);
    TrackerMeanShiftLikelihood<Planar<GrayU8>> tracker = new TrackerMeanShiftLikelihood<>(likelihood, 50, 0.1f);
    // specify the target's initial location and initialize with the first frame
    Planar<GrayU8> frame = video.next();
    // Note that the tracker will not automatically invoke RgbLikelihood.createModel() in its initialize function
    tracker.initialize(frame, location);
    // For displaying the results
    TrackerObjectQuadPanel gui = new TrackerObjectQuadPanel(null);
    gui.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight()));
    gui.setImageUI((BufferedImage) video.getGuiImage());
    gui.setTarget(location, true);
    ShowImages.showWindow(gui, "Tracking Results", true);
    // Track the object across each video frame and display the results
    while (video.hasNext()) {
        frame = video.next();
        boolean visible = tracker.process(frame);
        gui.setImageUI((BufferedImage) video.getGuiImage());
        gui.setTarget(tracker.getLocation(), visible);
        gui.repaint();
        BoofMiscOps.pause(20);
    }
}
Also used : TrackerMeanShiftLikelihood(boofcv.alg.tracker.meanshift.TrackerMeanShiftLikelihood) MediaManager(boofcv.io.MediaManager) DefaultMediaManager(boofcv.io.wrapper.DefaultMediaManager) RectangleLength2D_I32(georegression.struct.shapes.RectangleLength2D_I32) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) TrackerObjectQuadPanel(boofcv.gui.tracker.TrackerObjectQuadPanel)

Aggregations

TrackerMeanShiftLikelihood (boofcv.alg.tracker.meanshift.TrackerMeanShiftLikelihood)1 TrackerObjectQuadPanel (boofcv.gui.tracker.TrackerObjectQuadPanel)1 MediaManager (boofcv.io.MediaManager)1 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)1 GrayU8 (boofcv.struct.image.GrayU8)1 Planar (boofcv.struct.image.Planar)1 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)1