ubuntu18.04+python3+pycharm+pcl1.8实现点云的保存和读取
从开始学习opencv时,就一直用python,现在在学习3D视觉,pointcloud是个难啃的骨头,pcl库的一些函数用法大部分都是C++,深度转点云。点云图的保存和读取,大部分教程都是C,python很少,这里我来分享python-pcl的一些函数的参数使用,后续会更新python版本的pcl库的一些使用,点云滤波器、过滤器、3D测量、3D的物体分割与识别等
1.点云图的获取
首先要使用realsense D415获取点云图,需要安装PCL,realsense等工具库,安装说明见我上一个博客,这里直接给代码了,大概流程是:
- 启动相机获取彩色图,深度图,着色深度图,
- 深度图转为点云图,这里把深度的一些信息写入到txt文件中
- 然后读取txt文件,使用pcl.save()保存为PCD点云文件
import pyrealsense2 as rs
import numpy as np
import cv2
import pcl
from pcl import pcl_visualization
def get_image():
# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
# Start streaming
pipeline.start(config)
#获取图像,realsense刚启动的时候图像会有一些失真,我们保存第100帧图片。
for i in range(100):
data = pipeline.wait_for_frames()
depth = data.get_depth_frame()
color = data.get_color_frame()
#获取内参
dprofile = depth.get_profile()
cprofile = color.get_profile()
cvsprofile = rs.video_stream_profile(cprofile)
dvsprofile = rs.video_stream_profile(dprofile)
color_intrin=cvsprofile.get_intrinsics()
print(color_intrin)
depth_intrin=dvsprofile.get_intrinsics()
print(color_intrin)
extrin = dprofile.get_extrinsics_to(cprofile)
print(extrin)
depth_image = np.asanyarray(depth.get_data())
color_image = np.asanyarray(color.get_data())
# Apply colormap on depth image (image must be converted to 8-bit per pixel first)
depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)<

本文详细介绍如何在Ubuntu 18.04环境下利用Python、PyCharm及PCL 1.8进行点云的获取、保存及读取。通过Realsense D415相机获取深度图并转化为点云,最终保存为PCD文件。此外,还介绍了点云的可视化方法。
最低0.47元/天 解锁文章
2220





