Search in sources :

Example 1 with PanelGridPanel

use of boofcv.gui.PanelGridPanel 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)

Example 2 with PanelGridPanel

use of boofcv.gui.PanelGridPanel in project BoofCV by lessthanoptimal.

the class ExamplePoseOfCalibrationTarget method main.

public static void main(String[] args) {
    // Load camera calibration
    CameraPinholeBrown intrinsic = CalibrationIO.load(UtilIO.pathExample("calibration/mono/Sony_DSC-HX5V_Chess/intrinsic.yaml"));
    LensDistortionNarrowFOV lensDistortion = new LensDistortionBrown(intrinsic);
    // load the video file
    String fileName = UtilIO.pathExample("tracking/chessboard_SonyDSC_01.mjpeg");
    SimpleImageSequence<GrayF32> video = DefaultMediaManager.INSTANCE.openVideo(fileName, ImageType.single(GrayF32.class));
    // DefaultMediaManager.INSTANCE.openCamera(null, 640, 480, ImageType.single(GrayF32.class));
    // Let's use the FiducialDetector interface since it is much easier than coding up
    // the entire thing ourselves. Look at FiducialDetector's code if you want to understand how it works.
    CalibrationFiducialDetector<GrayF32> detector = FactoryFiducial.calibChessboardX(null, new ConfigGridDimen(4, 5, 0.03), GrayF32.class);
    detector.setLensDistortion(lensDistortion, intrinsic.width, intrinsic.height);
    // Get the 2D coordinate of calibration points for visualization purposes
    List<Point2D_F64> calibPts = detector.getCalibrationPoints();
    // Set up visualization
    PointCloudViewer viewer = VisualizeData.createPointCloudViewer();
    viewer.setCameraHFov(PerspectiveOps.computeHFov(intrinsic));
    viewer.setTranslationStep(0.01);
    // white background
    viewer.setBackgroundColor(0xFFFFFF);
    // make the view more interest. From the side.
    DMatrixRMaj rotY = ConvertRotation3D_F64.rotY(-Math.PI / 2.0, null);
    viewer.setCameraToWorld(new Se3_F64(rotY, new Vector3D_F64(0.75, 0, 1.25)).invert(null));
    var imagePanel = new ImagePanel(intrinsic.width, intrinsic.height);
    var viewerComponent = viewer.getComponent();
    viewerComponent.setPreferredSize(new Dimension(intrinsic.width, intrinsic.height));
    var gui = new PanelGridPanel(1, imagePanel, viewerComponent);
    gui.setMaximumSize(gui.getPreferredSize());
    ShowImages.showWindow(gui, "Calibration Target Pose", true);
    // Allows the user to click on the image and pause
    var pauseHelper = new MousePauseHelper(gui);
    // saves the target's center location
    var path = new ArrayList<Point3D_F64>();
    // Process each frame in the video sequence
    var targetToCamera = new Se3_F64();
    while (video.hasNext()) {
        // detect calibration points
        detector.detect(video.next());
        if (detector.totalFound() == 1) {
            detector.getFiducialToCamera(0, targetToCamera);
            // Visualization. Show a path with green points and the calibration points in black
            viewer.clearPoints();
            Point3D_F64 center = new Point3D_F64();
            SePointOps_F64.transform(targetToCamera, center, center);
            path.add(center);
            for (Point3D_F64 p : path) {
                viewer.addPoint(p.x, p.y, p.z, 0x00FF00);
            }
            for (int j = 0; j < calibPts.size(); j++) {
                Point2D_F64 p = calibPts.get(j);
                Point3D_F64 p3 = new Point3D_F64(p.x, p.y, 0);
                SePointOps_F64.transform(targetToCamera, p3, p3);
                viewer.addPoint(p3.x, p3.y, p3.z, 0);
            }
        }
        imagePanel.setImage((BufferedImage) video.getGuiImage());
        viewerComponent.repaint();
        imagePanel.repaint();
        BoofMiscOps.pause(30);
        while (pauseHelper.isPaused()) {
            BoofMiscOps.pause(30);
        }
    }
}
Also used : ConfigGridDimen(boofcv.abst.fiducial.calib.ConfigGridDimen) Point3D_F64(georegression.struct.point.Point3D_F64) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) LensDistortionBrown(boofcv.alg.distort.brown.LensDistortionBrown) LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) DMatrixRMaj(org.ejml.data.DMatrixRMaj) ArrayList(java.util.ArrayList) Vector3D_F64(georegression.struct.point.Vector3D_F64) PanelGridPanel(boofcv.gui.PanelGridPanel) GrayF32(boofcv.struct.image.GrayF32) Point2D_F64(georegression.struct.point.Point2D_F64) PointCloudViewer(boofcv.visualize.PointCloudViewer) Se3_F64(georegression.struct.se.Se3_F64) ImagePanel(boofcv.gui.image.ImagePanel) MousePauseHelper(boofcv.gui.MousePauseHelper)

Aggregations

PanelGridPanel (boofcv.gui.PanelGridPanel)2 GrayF32 (boofcv.struct.image.GrayF32)2 FDistort (boofcv.abst.distort.FDistort)1 ConfigGridDimen (boofcv.abst.fiducial.calib.ConfigGridDimen)1 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)1 LensDistortionBrown (boofcv.alg.distort.brown.LensDistortionBrown)1 MousePauseHelper (boofcv.gui.MousePauseHelper)1 AnimatePanel (boofcv.gui.image.AnimatePanel)1 ImagePanel (boofcv.gui.image.ImagePanel)1 MediaManager (boofcv.io.MediaManager)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)1 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)1 ImageFlow (boofcv.struct.flow.ImageFlow)1 PointCloudViewer (boofcv.visualize.PointCloudViewer)1 Point2D_F64 (georegression.struct.point.Point2D_F64)1 Point3D_F64 (georegression.struct.point.Point3D_F64)1 Vector3D_F64 (georegression.struct.point.Vector3D_F64)1 Se3_F64 (georegression.struct.se.Se3_F64)1 BufferedImage (java.awt.image.BufferedImage)1