代码:
# BIWI头部姿态估计数据集使用说明与点云图像融合 https://blog.csdn.net/weixin_43038346/article/details/120097266
import cv2
import numpy as np
import struct
from math import ceil, floor
import open3d as o3d
data_dir = r'E:\Downloads\datasets\BIWI\kinect_head_pose_db\hpdb\01'
def read_depth_image(depth_path):
p = 0
depth_image = []
with open(depth_path, 'rb') as f:
width = struct.unpack('i', f.read(4))[0]
height = struct.unpack('i', f.read(4))[0]
while p < width * height:
empty_num = struct.unpack('i', f.read(4))[0]
for i in range(empty_num):
depth_image.append(0)
full_num = struct.unpack('i', f.read(4))[0]
for i in range(full_num):
depth = struct.unpack('h', f.read(2))[0]
depth_image.append(depth)
p += empty_num + full_num
depth_image = np.reshape(depth_image, (height, width))
# depth_image = depth_image / depth_image.max() * 255
# depth_image = depth_image.astype('uint8')
depth_image = depth_image.astype('uint16')
# cv2.imshow('depth', depth_image * 16)
# cv2.waitKey(0)
return depth_image
img = cv2.imread(data_dir + '/frame_00054_rgb.png')
depth = read_depth_image(data_dir + '/frame_00054_depth.bin')
depth_intrinsic = np.genfromtxt(data_dir + '/depth.cal', skip_footer=6)
inter = o3d.camera.PinholeCameraIntrinsic()
inter.set_intrinsics(640, 480, depth_intrinsic[0][0], depth_intrinsic[1][1], depth_intrinsic[0,2], depth_intrinsic[1,2])
depth = o3d.geometry.Image(depth)
points = o3d.geometry.PointCloud.create_from_depth_image(depth, inter)
o3d.visualization.draw_geometries([points])
结果:
参考文献:
1.open3d.geometry.Image — Open3D 0.15.1 documentation