Search in sources :

Example 1 with TrackerObjectQuadPanel

use of boofcv.gui.tracker.TrackerObjectQuadPanel in project BoofCV by lessthanoptimal.

the class ExampleTrackerObjectQuad method main.

public static void main(String[] args) {
    MediaManager media = DefaultMediaManager.INSTANCE;
    String fileName = UtilIO.pathExample("tracking/wildcat_robot.mjpeg");
    // Create the tracker.  Comment/Uncomment to change the tracker.
    TrackerObjectQuad tracker = FactoryTrackerObjectQuad.circulant(null, GrayU8.class);
    // FactoryTrackerObjectQuad.sparseFlow(null,GrayU8.class,null);
    // FactoryTrackerObjectQuad.tld(null,GrayU8.class);
    // FactoryTrackerObjectQuad.meanShiftComaniciu2003(new ConfigComaniciu2003(), ImageType.pl(3, GrayU8.class));
    // FactoryTrackerObjectQuad.meanShiftComaniciu2003(new ConfigComaniciu2003(true),ImageType.pl(3,GrayU8.class));
    // Mean-shift likelihood will fail in this video, but is excellent at tracking objects with
    // a single unique color.  See ExampleTrackerMeanShiftLikelihood
    // FactoryTrackerObjectQuad.meanShiftLikelihood(30,5,255, MeanShiftLikelihoodType.HISTOGRAM,ImageType.pl(3,GrayU8.class));
    SimpleImageSequence video = media.openVideo(fileName, tracker.getImageType());
    // specify the target's initial location and initialize with the first frame
    Quadrilateral_F64 location = new Quadrilateral_F64(211.0, 162.0, 326.0, 153.0, 335.0, 258.0, 215.0, 249.0);
    ImageBase frame = video.next();
    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
    long previous = 0;
    while (video.hasNext()) {
        frame = video.next();
        boolean visible = tracker.process(frame, location);
        gui.setImageUI((BufferedImage) video.getGuiImage());
        gui.setTarget(location, visible);
        gui.repaint();
        // shoot for a specific frame rate
        long time = System.currentTimeMillis();
        BoofMiscOps.pause(Math.max(0, 80 - (time - previous)));
        previous = time;
    }
}
Also used : SimpleImageSequence(boofcv.io.image.SimpleImageSequence) Quadrilateral_F64(georegression.struct.shapes.Quadrilateral_F64) MediaManager(boofcv.io.MediaManager) DefaultMediaManager(boofcv.io.wrapper.DefaultMediaManager) FactoryTrackerObjectQuad(boofcv.factory.tracker.FactoryTrackerObjectQuad) TrackerObjectQuad(boofcv.abst.tracker.TrackerObjectQuad) TrackerObjectQuadPanel(boofcv.gui.tracker.TrackerObjectQuadPanel) ImageBase(boofcv.struct.image.ImageBase)

Example 2 with TrackerObjectQuadPanel

use of boofcv.gui.tracker.TrackerObjectQuadPanel 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

TrackerObjectQuadPanel (boofcv.gui.tracker.TrackerObjectQuadPanel)2 MediaManager (boofcv.io.MediaManager)2 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)2 TrackerObjectQuad (boofcv.abst.tracker.TrackerObjectQuad)1 TrackerMeanShiftLikelihood (boofcv.alg.tracker.meanshift.TrackerMeanShiftLikelihood)1 FactoryTrackerObjectQuad (boofcv.factory.tracker.FactoryTrackerObjectQuad)1 SimpleImageSequence (boofcv.io.image.SimpleImageSequence)1 GrayU8 (boofcv.struct.image.GrayU8)1 ImageBase (boofcv.struct.image.ImageBase)1 Planar (boofcv.struct.image.Planar)1 Quadrilateral_F64 (georegression.struct.shapes.Quadrilateral_F64)1 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)1