How to convert the pts format data collected by lidar into pcd format


foreword

Due to the needs of the work project, a large amount of data in pts format was downloaded from the customer, and the available .pcd file needs to be transferred. The following is the introduction and solution;

1. What data is in .pts?

There are many formats for saving lidar 3D point clouds; among them, .pts is the fastest way to save point clouds, directly store point clouds in XYZ order, and can be saved as integer or floating point; can be saved in ASCII code or binary, and each parameter is directly separated by a space; as shown in the following figure:
insert image description here

2. What is .pcd data?

PCD format is a brand-new point cloud format, please refer to the following address for specific explanations;

Reprint address: http://www.pclcn.org/study/shownews.php?lang=cn&id=54

3. Conversion steps

1. PCD data format

The .pcd file can not only be opened by the PCL tool, the following is opened by editors such as VSCODE or gedit;

By comparing pts, it can be found that the .pcd file is composed of the first 4 parameters of a line of .pts data + the header file;

# .PCD v0.7 - Point Cloud Data file format
VERSION 0.7
FIELDS x y z intensity
SIZE 4 4 4 4
TYPE F F F F
COUNT 1 1 1 1
WIDTH 35067435
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 35067435
DATA ascii
0 0 0 4
-1.32 -2.761 0.084 23
2.916 -2.93 0.147 26
2.317 -0.563 0.098 21
-0.081 -7.745 0.073 24
3.239 -4.546 0.117 12
-1.094 -3.617 0.109 6
......

2. Transform data

After knowing the above process, we use Python to perform circular conversion and export. After all, there are 35067435 point clouds; the
script content is as follows:

### pts_pcd
f = open("DATA.pts")
o = open('DATA_out.txt', 'w')
line = f.readline()
line = f.readline()
while line:
    w = line.split(" ", 6)
    print(w[0] + " " + w[1] + " " + w[2] + " " + w[3])
    o.write(w[0] + " " + w[1] + " " + w[2] + " " + w[3] + "\r\n")
    line = f.readline()

f.close()
o.close()

Wait for the data to be refreshed, and you can see that a DATA_out.txt file is generated in the same directory;

3. Load the header file

The content of the header file is as follows, note that the WIDTH and POINTS parameters must correspond to the pts parameters;

# .PCD v0.7 - Point Cloud Data file format
VERSION 0.7
FIELDS x y z intensity
SIZE 4 4 4 4
TYPE F F F F
COUNT 1 1 1 1
WIDTH 35067435
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 35067435
DATA ascii

Copy the header file directly to DATA_out.txt or use the following command to copy directly from head.txt to DATA.txt;

sed -ne '1 r head.txt' -e '1N;P' -i DATA_out.txt 

4. View PCD

Change the suffix of DATA_out.txt to .pcd; open the .pcd file with pcl_viewer
$ pcl_viewer DATA_out.pcd

insert image description here

Guess you like

Origin blog.csdn.net/m0_54792870/article/details/112970845