python深度图转点云图并可视化示例代码
时间: 2023-06-04 13:08:08 浏览: 155
好的,以下是Python深度图转点云图并可视化的示例代码:
```
import numpy as np
import cv2
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
# 读取深度图
depth_img = cv2.imread('depth.png', cv2.IMREAD_UNCHANGED).astype(np.float32)
# 参数设置
w = 640
h = 480
fx = 525.0
fy = 525.0
cx = 319.5
cy = 239.5
factor = 5000
# 得到相机坐标系下每个像素点对应的三维坐标
x, y = np.meshgrid(np.arange(w), np.arange(h))
z = depth_img / factor
x = (x - cx) * z / fx
y = (y - cy) * z / fy
# 将三维坐标格式化为点云格式
point_cloud = np.concatenate((x[..., None], y[..., None], z[..., None]), axis=2)
# 可视化点云
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(point_cloud[:, :, 0].ravel(),
point_cloud[:, :, 1].ravel(),
point_cloud[:, :, 2].ravel(),
c=depth_img.ravel())
ax.view_init(elev=20., azim=-90.)
plt.show()
```
希望能帮到你。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)