ubuntu18.04+python3+pycharm+pcl1.8实现点云的保存和读取

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

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等工具库,安装说明见我上一个博客,这里直接给代码了,大概流程是:

  1. 启动相机获取彩色图,深度图,着色深度图,
  2. 深度图转为点云图,这里把深度的一些信息写入到txt文件中
  3. 然后读取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)<
评论 14
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值