windows点云pcd转bin

代码链接,该代码中pypcd依赖python2,python3中不好用

GitHub - Zhou-Renjie/pcd2bin: .pcd to .bin converter (python)

$ pip install numpy
$ pip install argparse
$ pip install pypcd
$ pip install tqdm

安装pypcd时报错:

1.

building 'lzf' extension
error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27

双击安装VCForPython27.msi即可

2.

error: command ‘C:\Users\***\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe’ failed with exit status 2

把stdin.h复制到下面的路径下即可

C:\Users\***\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\include

3.

使用pypcd时出现ValueError: field '__0000' occurs more than once

打开pypcd安装位置的pypcd.py,安装位置可以在报错界面查看:

C:\Users\***\.conda\envs\py27\Lib\site-packages\pypcd\pypcd.py

找到77行左右

def parse_header(lines): 
     """ Parse header of PCD files. 
     """ 
     metadata = {} 
     for ln in lines: 
         if ln.startswith('#') or len(ln) < 2: 
             continue 
         match = re.match('(\w+)\s+([\w\s\.]+)', ln) 

改为

def parse_header(lines): 
     """ 
     Parse header of PCD files. 
     """ 
    metadata = {} 
    for ln in lines: 
        if ln.startswith('#') or len(ln) < 2: 
        	continue 
        ln = ln.replace('_','s',1)
        ln = ln.replace('_','m',1)
    	match = re.match('(\w+)\s+([\w\s.]+)', str(ln))

其他的pypcd问题在下面网站找到:

Issues · dimatura/pypcd (github.com)

运行程序:

python pcd2bin.py --pcd_path={path of input pcd file directory} --bin_path={path of output bin file directory}

或者在程序中直接填写你的文件路径

实时点云数据深度图需要使用到相机的内参矩阵和外参矩阵,以及点云数据的坐标系和深度图像的坐标系之间的变换关系。如果你已经有了这些信息,可以使用 Python 中的 NumPy 和 OpenCV 库来实现实时点云数据深度图的功能。 以下是一个示例代码,假设你已经安装了 NumPy 和 OpenCV 库: ```python import numpy as np import cv2 # 相机内参矩阵 K = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]]) # 相机外参矩阵 R = np.array([[r11, r12, r13], [r21, r22, r23], [r31, r32, r33]]) t = np.array([tx, ty, tz]) T = np.hstack((R, t.reshape(3, 1))) P = np.dot(K, T) # 点云数据坐标系到深度图像坐标系的变换矩阵 M = np.array([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]]) # 循环读取点云数据并换为深度图像 while True: # 读取点云数据 pcd_data = np.loadtxt('input.pcd', skiprows=10) # 将点云数据换为深度图像 pcd_data_homo = np.hstack((pcd_data, np.ones((pcd_data.shape[0], 1)))) pcd_data_cam = np.dot(P, pcd_data_homo.T).T pcd_data_img = np.dot(M, pcd_data_cam.T).T[:, :3] / pcd_data_cam[:, 2:] depth_img = np.zeros((h, w), dtype=np.float32) for i in range(pcd_data_img.shape[0]): x, y, z = pcd_data_img[i] if x >= 0 and x < w and y >= 0 and y < h and z > 0: depth_img[int(y), int(x)] = z # 显示深度图像 cv2.imshow('depth', depth_img) cv2.waitKey(1) ``` 这里假设你已经有了相机的内参矩阵和外参矩阵,以及点云数据的坐标系和深度图像的坐标系之间的变换关系,分别存储在 K、R、t 和 M 矩阵中。代码中的循环读取点云数据并换为深度图像的过程可以实现实时换。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值