Search in sources :

Example 1 with DisparityToColorPointCloud

use of boofcv.alg.cloud.DisparityToColorPointCloud in project BoofCV by lessthanoptimal.

the class ExampleStereoTwoViewsOneCamera method showPointCloud.

/**
 * Show results as a point cloud
 */
public static void showPointCloud(ImageGray disparity, BufferedImage left, Se3_F64 motion, DMatrixRMaj rectifiedK, DMatrixRMaj rectifiedR, int disparityMin, int disparityRange) {
    DisparityToColorPointCloud d2c = new DisparityToColorPointCloud();
    PointCloudWriter.CloudArraysF32 cloud = new PointCloudWriter.CloudArraysF32();
    double baseline = motion.getT().norm();
    d2c.configure(baseline, rectifiedK, rectifiedR, new DoNothing2Transform2_F64(), disparityMin, disparityRange);
    d2c.process(disparity, UtilDisparitySwing.wrap(left), cloud);
    CameraPinhole rectifiedPinhole = PerspectiveOps.matrixToPinhole(rectifiedK, disparity.width, disparity.height, null);
    // skew the view to make the structure easier to see
    Se3_F64 cameraToWorld = SpecialEuclideanOps_F64.eulerXyz(-baseline * 5, 0, 0, 0, 0.2, 0, null);
    PointCloudViewer pcv = VisualizeData.createPointCloudViewer();
    pcv.setCameraHFov(PerspectiveOps.computeHFov(rectifiedPinhole));
    pcv.setCameraToWorld(cameraToWorld);
    pcv.setTranslationStep(baseline / 3);
    pcv.addCloud(cloud.cloudXyz, cloud.cloudRgb);
    pcv.setDotSize(1);
    pcv.setTranslationStep(baseline / 10);
    pcv.getComponent().setPreferredSize(new Dimension(left.getWidth(), left.getHeight()));
    ShowImages.showWindow(pcv.getComponent(), "Point Cloud", true);
}
Also used : DisparityToColorPointCloud(boofcv.alg.cloud.DisparityToColorPointCloud) DoNothing2Transform2_F64(boofcv.struct.distort.DoNothing2Transform2_F64) PointCloudViewer(boofcv.visualize.PointCloudViewer) PointCloudWriter(boofcv.alg.cloud.PointCloudWriter) CameraPinhole(boofcv.struct.calib.CameraPinhole) Se3_F64(georegression.struct.se.Se3_F64)

Example 2 with DisparityToColorPointCloud

use of boofcv.alg.cloud.DisparityToColorPointCloud in project BoofCV by lessthanoptimal.

the class VisualizeStereoDisparity method changeImageView.

/**
 * Changes which image is being displayed depending on GUI selection
 */
private synchronized void changeImageView() {
    if (!SwingUtilities.isEventDispatchThread())
        throw new RuntimeException("Must be in UI thread");
    if (control.selectedView < 3) {
        BufferedImage img;
        switch(control.selectedView) {
            case 0:
                img = disparityOut;
                break;
            case 1:
                img = colorLeft;
                break;
            case 2:
                img = colorRight;
                break;
            default:
                throw new RuntimeException("Unknown option");
        }
        if (img == null)
            return;
        imagePanel.setImage(img);
        imagePanel.setPreferredSize(new Dimension(origLeft.getWidth(), origLeft.getHeight()));
        swapVisualizationPanel(imagePanel, pcv.getComponent());
    } else {
        // TODO is thread safety a concern here? What happens if these settings are changed at the same time?
        if (!computedCloud) {
            computedCloud = true;
            DisparityToColorPointCloud d2c = new DisparityToColorPointCloud();
            PointCloudWriter.CloudArraysF32 cloud = new PointCloudWriter.CloudArraysF32();
            double baseline = calib.getRightToLeft().getT().norm();
            d2c.configure(baseline, rectK, rectR, leftRectToPixel, disparityMin, disparityRange);
            if (// has the user defined the ROI?
            imagePanel.state == 2)
                d2c.setRegionOfInterest(imagePanel.x0, imagePanel.y0, imagePanel.x1, imagePanel.y1);
            d2c.process(disparityImage, UtilDisparitySwing.wrap(colorLeft), cloud);
            CameraPinhole rectifiedPinhole = PerspectiveOps.matrixToPinhole(rectK, colorLeft.getWidth(), colorLeft.getHeight(), null);
            pcv.clearPoints();
            pcv.setCameraHFov(PerspectiveOps.computeHFov(rectifiedPinhole));
            pcv.addCloud(cloud.cloudXyz, cloud.cloudRgb);
            changeView3D();
        }
        swapVisualizationPanel(pcv.getComponent(), imagePanel);
    }
}
Also used : DisparityToColorPointCloud(boofcv.alg.cloud.DisparityToColorPointCloud) PointCloudWriter(boofcv.alg.cloud.PointCloudWriter) CameraPinhole(boofcv.struct.calib.CameraPinhole) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

DisparityToColorPointCloud (boofcv.alg.cloud.DisparityToColorPointCloud)2 PointCloudWriter (boofcv.alg.cloud.PointCloudWriter)2 CameraPinhole (boofcv.struct.calib.CameraPinhole)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 DoNothing2Transform2_F64 (boofcv.struct.distort.DoNothing2Transform2_F64)1 PointCloudViewer (boofcv.visualize.PointCloudViewer)1 Se3_F64 (georegression.struct.se.Se3_F64)1 BufferedImage (java.awt.image.BufferedImage)1