Search in sources :

Example 11 with MediaManager

use of boofcv.io.MediaManager 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)

Example 12 with MediaManager

use of boofcv.io.MediaManager in project BoofCV by lessthanoptimal.

the class ExampleDenseOpticalFlow method main.

public static void main(String[] args) {
    MediaManager media = DefaultMediaManager.INSTANCE;
    // String fileName0 = UtilIO.pathExample("denseflow/dogdance07.png");
    // String fileName1 = UtilIO.pathExample("denseflow/dogdance08.png");
    String fileName0 = UtilIO.pathExample("denseflow/Urban2_07.png");
    String fileName1 = UtilIO.pathExample("denseflow/Urban2_08.png");
    // String fileName0 = UtilIO.pathExample("denseflow/Grove2_07.png");
    // String fileName1 = UtilIO.pathExample("denseflow/Grove2_09.png");
    DenseOpticalFlow<GrayF32> denseFlow = // FactoryDenseOpticalFlow.hornSchunckPyramid(null,GrayF32.class);
    FactoryDenseOpticalFlow.broxWarping(null, GrayF32.class);
    BufferedImage buff0 = media.openImage(fileName0);
    BufferedImage buff1 = media.openImage(fileName1);
    GrayF32 full = new GrayF32(buff0.getWidth(), buff0.getHeight());
    // Dense optical flow is very computationally expensive.  Just process the image at 1/2 resolution
    GrayF32 previous = new GrayF32(full.width / 2, full.height / 2);
    GrayF32 current = previous.createSameShape();
    ImageFlow flow = new ImageFlow(previous.width, previous.height);
    ConvertBufferedImage.convertFrom(buff0, full);
    new FDistort(full, previous).scaleExt().apply();
    ConvertBufferedImage.convertFrom(buff1, full);
    new FDistort(full, current).scaleExt().apply();
    // compute dense motion
    denseFlow.process(previous, current, flow);
    // Visualize the results
    PanelGridPanel gui = new PanelGridPanel(1, 2);
    BufferedImage converted0 = new BufferedImage(current.width, current.height, BufferedImage.TYPE_INT_RGB);
    BufferedImage converted1 = new BufferedImage(current.width, current.height, BufferedImage.TYPE_INT_RGB);
    BufferedImage visualized = new BufferedImage(current.width, current.height, BufferedImage.TYPE_INT_RGB);
    ConvertBufferedImage.convertTo(previous, converted0, true);
    ConvertBufferedImage.convertTo(current, converted1, true);
    VisualizeOpticalFlow.colorized(flow, 10, visualized);
    AnimatePanel animate = new AnimatePanel(150, converted0, converted1);
    gui.add(animate);
    gui.add(visualized);
    animate.start();
    ShowImages.showWindow(gui, "Dense Optical Flow", true);
}
Also used : PanelGridPanel(boofcv.gui.PanelGridPanel) GrayF32(boofcv.struct.image.GrayF32) FDistort(boofcv.abst.distort.FDistort) AnimatePanel(boofcv.gui.image.AnimatePanel) MediaManager(boofcv.io.MediaManager) DefaultMediaManager(boofcv.io.wrapper.DefaultMediaManager) ImageFlow(boofcv.struct.flow.ImageFlow) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

MediaManager (boofcv.io.MediaManager)12 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)12 GrayU8 (boofcv.struct.image.GrayU8)7 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)6 BufferedImage (java.awt.image.BufferedImage)6 GrayF32 (boofcv.struct.image.GrayF32)5 ImageGridPanel (boofcv.gui.image.ImageGridPanel)4 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)4 SimpleImageSequence (boofcv.io.image.SimpleImageSequence)4 PkltConfig (boofcv.alg.tracker.klt.PkltConfig)3 ImageBase (boofcv.struct.image.ImageBase)3 Planar (boofcv.struct.image.Planar)3 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)3 Vector3D_F64 (georegression.struct.point.Vector3D_F64)3 Se3_F64 (georegression.struct.se.Se3_F64)3 PlToGrayMotion2D (boofcv.abst.sfm.d2.PlToGrayMotion2D)2 ConfigBackgroundBasic (boofcv.factory.background.ConfigBackgroundBasic)2 ConfigBackgroundGmm (boofcv.factory.background.ConfigBackgroundGmm)2 TrackerObjectQuadPanel (boofcv.gui.tracker.TrackerObjectQuadPanel)2 ImageType (boofcv.struct.image.ImageType)2