Search in sources :

Example 1 with VisualDepthParameters

use of boofcv.struct.calib.VisualDepthParameters in project BoofCV by lessthanoptimal.

the class ExampleVisualOdometryDepth method main.

public static void main(String[] args) throws IOException {
    MediaManager media = DefaultMediaManager.INSTANCE;
    String directory = UtilIO.pathExample("kinect/straight");
    // load camera description and the video sequence
    VisualDepthParameters param = CalibrationIO.load(media.openFile(directory + "visualdepth.yaml"));
    // specify how the image features are going to be tracked
    PkltConfig configKlt = new PkltConfig();
    configKlt.pyramidScaling = new int[] { 1, 2, 4, 8 };
    configKlt.templateRadius = 3;
    PointTrackerTwoPass<GrayU8> tracker = FactoryPointTrackerTwoPass.klt(configKlt, new ConfigGeneralDetector(600, 3, 1), GrayU8.class, GrayS16.class);
    DepthSparse3D<GrayU16> sparseDepth = new DepthSparse3D.I<>(1e-3);
    // declares the algorithm
    DepthVisualOdometry<GrayU8, GrayU16> visualOdometry = FactoryVisualOdometry.depthDepthPnP(1.5, 120, 2, 200, 50, true, sparseDepth, tracker, GrayU8.class, GrayU16.class);
    // Pass in intrinsic/extrinsic calibration.  This can be changed in the future.
    visualOdometry.setCalibration(param.visualParam, new DoNothing2Transform2_F32());
    // Process the video sequence and output the location plus number of inliers
    SimpleImageSequence<GrayU8> videoVisual = media.openVideo(directory + "rgb.mjpeg", ImageType.single(GrayU8.class));
    SimpleImageSequence<GrayU16> videoDepth = media.openVideo(directory + "depth.mpng", ImageType.single(GrayU16.class));
    while (videoVisual.hasNext()) {
        GrayU8 visual = videoVisual.next();
        GrayU16 depth = videoDepth.next();
        if (!visualOdometry.process(visual, depth)) {
            throw new RuntimeException("VO Failed!");
        }
        Se3_F64 leftToWorld = visualOdometry.getCameraToWorld();
        Vector3D_F64 T = leftToWorld.getT();
        System.out.printf("Location %8.2f %8.2f %8.2f      inliers %s\n", T.x, T.y, T.z, inlierPercent(visualOdometry));
    }
}
Also used : VisualDepthParameters(boofcv.struct.calib.VisualDepthParameters) GrayU16(boofcv.struct.image.GrayU16) PkltConfig(boofcv.alg.tracker.klt.PkltConfig) ConfigGeneralDetector(boofcv.abst.feature.detect.interest.ConfigGeneralDetector) DoNothing2Transform2_F32(boofcv.struct.distort.DoNothing2Transform2_F32) Vector3D_F64(georegression.struct.point.Vector3D_F64) MediaManager(boofcv.io.MediaManager) DefaultMediaManager(boofcv.io.wrapper.DefaultMediaManager) GrayU8(boofcv.struct.image.GrayU8) Se3_F64(georegression.struct.se.Se3_F64)

Example 2 with VisualDepthParameters

use of boofcv.struct.calib.VisualDepthParameters in project BoofCV by lessthanoptimal.

the class IntrinsicToDepthParameters method main.

public static void main(String[] args) {
    String baseDir = UtilIO.pathExample("kinect/basket");
    CameraPinholeRadial intrinsic = CalibrationIO.load(new File(baseDir, "intrinsic.yaml"));
    VisualDepthParameters depth = new VisualDepthParameters();
    depth.setVisualParam(intrinsic);
    depth.setMaxDepth(UtilOpenKinect.FREENECT_DEPTH_MM_MAX_VALUE);
    depth.setPixelNoDepth(UtilOpenKinect.FREENECT_DEPTH_MM_NO_VALUE);
    CalibrationIO.save(depth, baseDir + "visualdepth.yaml");
}
Also used : VisualDepthParameters(boofcv.struct.calib.VisualDepthParameters) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) File(java.io.File)

Example 3 with VisualDepthParameters

use of boofcv.struct.calib.VisualDepthParameters in project BoofCV by lessthanoptimal.

the class ExampleDepthPointCloud method main.

public static void main(String[] args) throws IOException {
    String nameRgb = UtilIO.pathExample("kinect/basket/basket_rgb.png");
    String nameDepth = UtilIO.pathExample("kinect/basket/basket_depth.png");
    String nameCalib = UtilIO.pathExample("kinect/basket/visualdepth.yaml");
    VisualDepthParameters param = CalibrationIO.load(nameCalib);
    BufferedImage buffered = UtilImageIO.loadImage(nameRgb);
    Planar<GrayU8> rgb = ConvertBufferedImage.convertFromPlanar(buffered, null, true, GrayU8.class);
    GrayU16 depth = ConvertBufferedImage.convertFrom(UtilImageIO.loadImage(nameDepth), null, GrayU16.class);
    FastQueue<Point3D_F64> cloud = new FastQueue<>(Point3D_F64.class, true);
    FastQueueArray_I32 cloudColor = new FastQueueArray_I32(3);
    VisualDepthOps.depthTo3D(param.visualParam, rgb, depth, cloud, cloudColor);
    DMatrixRMaj K = PerspectiveOps.calibrationMatrix(param.visualParam, (DMatrixRMaj) null);
    PointCloudViewer viewer = new PointCloudViewer(K, 15);
    viewer.setPreferredSize(new Dimension(rgb.width, rgb.height));
    for (int i = 0; i < cloud.size; i++) {
        Point3D_F64 p = cloud.get(i);
        int[] color = cloudColor.get(i);
        int c = (color[0] << 16) | (color[1] << 8) | color[2];
        viewer.addPoint(p.x, p.y, p.z, c);
    }
    // ---------- Display depth image
    // use the actual max value in the image to maximize its appearance
    int maxValue = ImageStatistics.max(depth);
    BufferedImage depthOut = VisualizeImageData.disparity(depth, null, 0, maxValue, 0);
    ShowImages.showWindow(depthOut, "Depth Image");
    // ---------- Display colorized point cloud
    ShowImages.showWindow(viewer, "Point Cloud");
    System.out.println("Total points = " + cloud.size);
}
Also used : VisualDepthParameters(boofcv.struct.calib.VisualDepthParameters) Point3D_F64(georegression.struct.point.Point3D_F64) GrayU16(boofcv.struct.image.GrayU16) FastQueue(org.ddogleg.struct.FastQueue) DMatrixRMaj(org.ejml.data.DMatrixRMaj) FastQueueArray_I32(boofcv.struct.FastQueueArray_I32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) PointCloudViewer(boofcv.gui.d3.PointCloudViewer) GrayU8(boofcv.struct.image.GrayU8)

Aggregations

VisualDepthParameters (boofcv.struct.calib.VisualDepthParameters)3 GrayU16 (boofcv.struct.image.GrayU16)2 GrayU8 (boofcv.struct.image.GrayU8)2 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)1 PkltConfig (boofcv.alg.tracker.klt.PkltConfig)1 PointCloudViewer (boofcv.gui.d3.PointCloudViewer)1 MediaManager (boofcv.io.MediaManager)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)1 FastQueueArray_I32 (boofcv.struct.FastQueueArray_I32)1 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)1 DoNothing2Transform2_F32 (boofcv.struct.distort.DoNothing2Transform2_F32)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 File (java.io.File)1 FastQueue (org.ddogleg.struct.FastQueue)1 DMatrixRMaj (org.ejml.data.DMatrixRMaj)1