import open3d as o3d import numpy as np import matplotlib.pyplot as plt import os import sys # monkey patches visualization and provides helpers to load geometries sys.path.append('..') # import open3d_tutorial as o3dtut # change to True if you want to interact with the visualization windows # o3dtut.interactive = not "CI" in os.environ print("Read SUN dataset") color_raw = o3d.io.read_image( r"D:\sunrgbd\sunrgbd_trainval\image\000001.jpg") depth_raw = o3d.io.read_image( r"D:sunrgbd\sunrgbd_trainval\depth_png\000001.png") rgbd_image = o3d.geometry.RGBDImage.create_from_sun_format(color_raw, depth_raw) print(rgbd_image) # attention, the depth is nonzero, the point will be constructed rows, columns = np.nonzero(np.asarray(rgbd_image.depth)) plt.subplot(1, 2, 1) plt.title('SUN grayscale image') plt.imshow(rgbd_image.color) plt.subplot(1, 2, 2) plt.title('SUN depth image') plt.imshow(rgbd_image.depth) plt.show() 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 down pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]]) color_condidate = [] # get the rgb color color_list = np.asarray(color_raw)/255 # according the index information, to fill the color at the point for x, y in zip(rows, columns): color_condidate.append(color_list[x][y]) point_cloud = o3d.geometry.PointCloud() point_cloud.points = o3d.utility.Vector3dVector(np.asarray(pcd.points)) # # color = [1, 0, 0] # colors = [color for i in range(len(np.asarray(pcd.points)))] point_cloud.colors = o3d.utility.Vector3dVector(color_condidate) # o3d.visualization.draw_geometries([point_cloud])