我想使用分段掩模(矩形)和深度图像裁剪点云(我可以认为现在没有旋转)。
import open3d as o3d
## dummy pointcloud
demo_icp_pcds = o3d.data.DemoICPPointClouds()
pcd = o3d.io.read_point_cloud(demo_icp_pcds.paths[0])
## dummy depth mask
depth_mask = np.ones((640, 480), dtype=np.uint8)
## Crop PCD
## mask boundaries: [(xmin, xmax), (y_min, y_max)]
rect = [(20, 50), (70, 75)]
o_box = o3d.geometry.OrientedBoundingBox()
o_box.center = [0.0, 0.0, 0.0]
o_box.extent = [1.0, 2.0, 3.0]
o_box.R = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
cropped_pcd = pcd.crop(o_box)
我想将矩形 (x, y) 和深度 z 的信息提供给定向边界框。有人能告诉我该怎么做吗?谢谢。
这是我的解决方案供参考:
def obbs_from_depth_mask(
depth: np.ndarray, rects: List[List]
) -> List[o3d.geometry.OrientedBoundingBox]:
obbs = []
for rect in rects:
obb = o3d.geometry.OrientedBoundingBox()
## [xmin, xmax, ymin, ymax]
x_min = rect[0]
y_min = rect[2]
z_min = depth[y_min, x_min]
##
x_max = rect[1]
y_max = rect[3]
z_max = depth[y_max, x_max]
center = [
(x_min + x_max) / 2,
(y_min, y_max) / 2,
(z_min + z_max) / 2,
]
half_extent = [
math.abs(x_max - x_min) / 2,
math.abs(y_max - y_min) / 2,
math.abs(z_max - z_min) / 2,
]
scaling_matrix = np.array([
[half_extent[0], 0.0, 0.0],
[0.0, half_extent[1], 0.0],
[0.0, 0.0, half_extent[2]]
])
translation_matrix = np.array([
[1.0, 0.0, 0.0, -center[0]],
[0.0, 1.0, 0.0, -center[1]],
[0.0, 0.0, 1.0, -center[2]],
[0.0, 0.0, 0.0, 1.0 ]
])
rotation_matrix = translation_matrix * scaling_matrix
obb.center = center
obb.extent = half_extent
obb.R = rotation_matrix
obbs.append(obb)
return obbs