最近在处理激光雷达点云数据时,点云数据在csv文件中长这个样子:

如果直接用Python处理csv非常方便。通过Pandas很容易处理:
import numpy as np
import pandas as pd
import open3d as o3d
pcd = o3d.geometry.PointCloud() # pcd类型的数据。
with open("2.csv", encoding="utf-8") as f:
data = pd.read_csv(f, header=None).values.tolist()
print(data[:5])
np_points = np.array(data)[:, 1:4]
print(np_points.shape)
pcd.points = o3d.utility.Vector3dVector(np_points)
o3d.visualization.draw_geometries([pcd])
# o3d.io.write_point_cloud('E:/project/3.ply', pcd)
通过python下pandas处理效率高,速度快,简单操作。
但是我需要研究学习通过halcon中正则表达实现对csv文件的正则匹配,所以需要看到halcon代码中的每个变量的变换情况,同时好好学习一下正则表达。
在halcon代码中:通过文件读取之后输出出来的是tuple的字符数组类型列表构成的向量VecOutLine。把向量转为tuple元组。如变量监控中的P。生成的字符串。这个字符串就需要我们来正则处理来提取数字,以构成X、Y、Z。
dev_update_off ()
Filename := './0.csv' // 点云数据的名称,.txt、.csv、.asc等格式的都可以
NumColumns := 5 //如果点云的每行数据有3个数字就写3 (只有xyz 的数据)
count_seconds (Then)
open_file (Filename, 'input', FileHandle)
VecOutLine.clear()
repeat
fread_line (FileHandle, VecOutLine.at(VecOutLine.length()), IsEOF)
until (IsEOF)
convert_vector_to_tuple (VecOutLine, P)
S := P[354540]
stop()
P1 := split(P, '\n')
P2 := split(P1, ',')
P3 := number(regexp_replace(P2,'^\\s*(.+?)\\s*\n*$', '$1'))
// tuple_number负责字符转数字,tuple_string负责数字转字符。
// tuple_number (P2, P3)
// P4 := number(P2)
// convert_vector_to_tuple({P2},P4)
IndexIsString := find(type_elem(P3),H_TYPE_STRING)
if (IndexIsString > -1)
throw ('could not convert "' + P3[IndexIsString] + '" to a number')
endif
X := P3[[1:NumColumns:|P3|-1]]
Y := P3[[2:NumColumns:|P3|-1]]
Z := P3[[3:NumColumns:|P3|-1]]
stop()

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



