pcd=o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image,o3d.camera.PinholeCameraIntrinsic(o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))# Flip it, otherwise the pointcloud will be upside downpcd.transform([[1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,1]])o3d.visualization.draw_geometries([pcd])
pcd=o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image,o3d.camera.PinholeCameraIntrinsic(o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))# Flip it, otherwise the pointcloud will be upside downpcd.transform([[1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,1]])o3d.visualization.draw_geometries([pcd])
3. TUM Dataset [Strum2012]
Set convert_rgb_to_intensity=False, we can visualize Color Image with 3 channels instead of Grayscale Image
pcd=o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image,o3d.camera.PinholeCameraIntrinsic(o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))# Flip it, otherwise the pointcloud will be upside downpcd.transform([[1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,1]])o3d.visualization.draw_geometries([pcd])
4. NYU Dataset [Silberman2012]
4.1. Preprocess and Read Dataset
Since NYU images are not in standard jpg or png formats, we use mpimg.imread to read the color image as a numpy array and convert it to an Open3D Image
An additional helper function read_nyu_pgm() is called to read depth images from the special big endian pgm format used in the NYU dataset.
importmatplotlib.imageasmpimgimportre# This is special function used for reading NYU pgm format# as it is written in big endian byte order.defread_nyu_pgm(filename,byteorder='>'):withopen(filename,'rb')asf:buffer=f.read()try:header,width,height,maxval=re.search(b"(^P5\s(?:\s*#.*[\r\n])*"b"(\d+)\s(?:\s*#.*[\r\n])*"b"(\d+)\s(?:\s*#.*[\r\n])*"b"(\d+)\s(?:\s*#.*[\r\n]\s)*)",buffer).groups()exceptAttributeError:raiseValueError("Not a raw PGM file: '%s'"%filename)img=np.frombuffer(buffer,dtype=byteorder+'u2',count=int(width)*int(height),offset=len(header)).reshape((int(height),int(width)))img_out=img.astype('u2')returnimg_outprint("Read NYU dataset")# Open3D does not support ppm/pgm file yet. Not using o3d.io.read_image here.# MathplotImage having some ISSUE with NYU pgm file. Not using imread for pgm.nyu_rgbd=o3d.data.SampleNYURGBDImage()color_raw=mpimg.imread(nyu_rgbd.color_path)depth_raw=read_nyu_pgm(nyu_rgbd.depth_path)color=o3d.geometry.Image(color_raw)depth=o3d.geometry.Image(depth_raw)rgbd_image=o3d.geometry.RGBDImage.create_from_nyu_format(color,depth)
4.2. Visualize RGBD Images and Point Cloud
1
2
3
4
5
6
7
8
9
o3d.visualization.draw_geometries([rgbd_image])pcd=o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image,o3d.camera.PinholeCameraIntrinsic(o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))# Flip it, otherwise the pointcloud will be upside downpcd.transform([[1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,1]])o3d.visualization.draw_geometries([pcd])