最近工作需要,需要获取PCD点云数据的强度等信息,给出open3d和pypcd两种方法获取强度信息。读取的PCD数据头格式如下:
VERSION 0.7
FIELDS x y z intensity laserid timeoffset yawangle
SIZE 4 4 4 1 2 8 4
TYPE F F F U U F F
COUNT 1 1 1 1 1 1 1
WIDTH 230400
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 230400
DATA binary_compressed
一、使用open3d库
1、安装
pip install open3d==0.15.1
2、获取点云强度
网上给出通过 open3d.io.read_point_cloud() 的方式只能获取点云的 x,y,z 坐标,是无法获取强度等信息的。要想获取强度信息,open3d给出另一种方法,即通过 open3d.t.io.read_point_cloud().point["intensity"] 方式,转换为numpy类型后获取。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import open3d as o3d
filePath = "pcd_file.pcd"
pcd_type = o3d.t.io.read_point_cloud(filePath)
pcd_positions = o3d.t.io.read_point_cloud(filePath).point["positions"].numpy()
pcd_intensity = o3d.t.io.read_point_cloud(filePath).point["intensity"].numpy()
print(f"type:\n {pcd_type}")
print(f"positions:\n {pcd_positions}")
print(f"intensity:\n {pcd_intensity}")
代码结果如下:
type:
PointCloud on CPU:0 [230400 points (Float32)]
Attributes:
yawangle (dtype = Float32, shape = {230400, 1}),
intensity (dtype = UInt8, shape = {230400, 1}),
laserid (dtype = UInt16, shape = {230400, 1}),
timeoffset (dtype = Float64, shape = {230400, 1}).
positions:
[[ 7.8483152e+00 -8.6269194e-01 -1.8956374e+00]
[ 6.6055817e+01 -5.3120365e+00 -1.2601746e+00]
[ 2.4348343e+01 -1.2318233e+00 -1.8688463e+00]
...
[ 2.2996552e+01 8.9388782e-01 -1.8850820e+00]
[ 3.6149435e-02 -2.0189864e-04 0.0000000e+00]
[ 5.2160694e+01 5.1382108e+00 -1.5453696e+00]]
intensity:
[[10]
[44]
[20]
...
[ 8]
[ 1]
[58]]
参考:Support reading PCD files with intensities · Issue #3341 · isl-org/Open3D · GitHub
二、使用Pypcd库
1、安装
pip install pypcd3==0.1.1
2、获取点云强度
使用 pypcd.PointCloud.from_path() 方法获取,数据保存在属性 pc_data 中。转换为numpy类型后获取。数据按照PCD数据头的顺序排列,切片获取指定列即可。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from pypcd import pypcd
filePath = "pcd_file.pcd"
pcd = np.array(pypcd.PointCloud.from_path(filePath).pc_data)
print(pcd)
代码结果如下:
[(7.8483152e+00, -8.6269194e-01, -1.8956374, 10, 3, 1.71318198e+18, 630.)
(6.6055817e+01, -5.3120365e+00, -1.2601746, 44, 66, 1.71318198e+18, 460.)
(2.4348343e+01, -1.2318233e+00, -1.8688463, 20, 33, 1.71318198e+18, 290.)
...
(2.2996552e+01, 8.9388782e-01, -1.885082 , 8, 30, 1.71318198e+18, -223.)
(3.6149435e-02, -2.0189864e-04, 0. , 1, 93, 1.71318198e+18, -393.)
(5.2160694e+01, 5.1382108e+00, -1.5453696, 58, 60, 1.71318198e+18, -563.)]