Difference between revisions of "Example Point Cloud Depth Image"

From BoofCV
Jump to navigationJump to search
m
m
Line 9: Line 9:


Example Code:
Example Code:
* [https://github.com/lessthanoptimal/BoofCV/blob/v0.25/examples/src/boofcv/examples/geometry/ExampleDepthPointCloud.java ExampleDepthPointCloud.java]
* [https://github.com/lessthanoptimal/BoofCV/blob/v0.27/examples/src/boofcv/examples/geometry/ExampleDepthPointCloud.java ExampleDepthPointCloud.java]


Concepts:
Concepts:
Line 32: Line 32:
String nameRgb = UtilIO.pathExample("kinect/basket/basket_rgb.png");
String nameRgb = UtilIO.pathExample("kinect/basket/basket_rgb.png");
String nameDepth = UtilIO.pathExample("kinect/basket/basket_depth.png");
String nameDepth = UtilIO.pathExample("kinect/basket/basket_depth.png");
String nameCalib = UtilIO.pathExample("kinect/basket/visualdepth.xml");
String nameCalib = UtilIO.pathExample("kinect/basket/visualdepth.yaml");


VisualDepthParameters param = UtilIO.loadXML(nameCalib);
VisualDepthParameters param = CalibrationIO.load(nameCalib);


BufferedImage buffered = UtilImageIO.loadImage(nameRgb);
BufferedImage buffered = UtilImageIO.loadImage(nameRgb);
Planar<GrayU8> rgb = ConvertBufferedImage.convertFromMulti(buffered,null,true,GrayU8.class);
Planar<GrayU8> rgb = ConvertBufferedImage.convertFromPlanar(buffered,null,true,GrayU8.class);
GrayU16 depth =
GrayU16 depth =
ConvertBufferedImage.convertFrom(UtilImageIO.loadImage(nameDepth),null,GrayU16.class);
ConvertBufferedImage.convertFrom(UtilImageIO.loadImage(nameDepth),null,GrayU16.class);
Line 46: Line 46:
VisualDepthOps.depthTo3D(param.visualParam, rgb, depth, cloud, cloudColor);
VisualDepthOps.depthTo3D(param.visualParam, rgb, depth, cloud, cloudColor);


DenseMatrix64F K = PerspectiveOps.calibrationMatrix(param.visualParam,null);
DMatrixRMaj K = PerspectiveOps.calibrationMatrix(param.visualParam, (DMatrixRMaj)null);


PointCloudViewer viewer = new PointCloudViewer(K, 15);
PointCloudViewer viewer = new PointCloudViewer(K, 15);

Revision as of 07:45, 17 August 2017

This example demonstrates how to create a 3D point cloud from a RGB-D sensor, such as the Kinect, and visualize it. RGB-D sensors have both visual and depth information. In this example the depth information is stored in a 16-bit image and the visual image in a standard color image. Calibration matching RGB an depth pixels to each other has already been done by the sensor.

Example Code:

Concepts:

  • RGB-D
  • Point clouds

Related Examples:

Example Code

/**
 * Example of how to create a point cloud from a RGB-D (Kinect) sensor.  Data is loaded from two files, one for the
 * visual image and one for the depth image.
 *
 * @author Peter Abeles
 */
public class ExampleDepthPointCloud {

	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);
	}
}