Convert 3-D point cloud into 2-D lidar scan
Convert Point Cloud to Lidar Scan
Create a velodyne PCAP file reader object.
veloReader = velodyneFileReader("lidarData_ConstructionRoad.pcap","HDL32E");
Read point cloud data from 0.3 seconds after the start time of the file by using the
readFrame method. Display the point cloud.
veloReader.CurrentTime = veloReader.StartTime + seconds(0.3); ptCloud = readFrame(veloReader); pcshow(ptCloud)
Segment the point cloud and remove ground points.
groundPtsIdx = segmentGroundFromLidarData(ptCloud); nonGroundPtCloud= select(ptCloud,~groundPtsIdx,OutputSize="full");
Convert the point cloud into 2-D lidar scan and display the output.
scan = pc2scan(nonGroundPtCloud); figure plot(scan)
ptCloudIn — Input point cloud
Input point cloud, specified as a
By default, the function assumes the input point cloud is in the sensor coordinate system with the point cloud origin at the sensor center, and the sensor capturing the point cloud has no rotations about the coordinate axes.
You must specify the
Location property of the
pointCloud object in meters.
tform — Rigid transformation between lidar sensor and point cloud origin
Rigid transformation between the 2-D lidar sensor and the point cloud origin,
specified as a
object. The function uses
tform to convert the input point cloud
into the 2-D lidar sensor coordinate system.
By default, the function assumes the input point cloud is in the sensor coordinate
system, and the sensor capturing the point cloud has no rotations about the coordinate
axes if you do not specify
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
pc2scan(ptCloudIn,ElevationAngleTolerance=5) selects points
with elevation angles in the range [
5] degrees to
generate the scan.
ElevationAngleTolerance — Elevation angle tolerance
1 (default) | positive scalar
Elevation angle tolerance, specified as a positive scalar. When generating the 2-D
lidar scan, the function selects only the points of the input point cloud with
elevation angles in the range [
ElevationAngleTolerance]. Lower values of
ElevationAngleTolerance can result in a more accurate output
scan. Units are in degrees.
ScanAngleResolution — Angle between consecutive scan lines
0.5 (default) | positive scalar
Angle between the consecutive scan lines of the 2-D lidar sensor, specified as a positive scalar. Lower values can result in a finer scan output. Units are in degrees.
ScanRangeLimits — Scanning range of lidar sensor
[eps 80] (default) | two-element vector
Scanning range of the 2-D lidar sensor, specified as a two-element vector of the
[min max]. Units are in meters.
ScanAngleLimits — Scanning angle limits of lidar sensor
[-90 90] (default) | two-element vector
Scanning angle limits of the 2-D lidar sensor, specified as a two-element vector
of the form
[min max]. This vector defines the horizontal field of
view of the sensor. Units are in degrees.
The function follows these steps to convert a point cloud into a 2-D lidar scan.
Converts the input point cloud to the 2-D lidar sensor coordinate system using the specified transformation
tform. If you do not specify
tform, the function assumes the data is in the sensor coordinate system.
Projects the points on the xy-plane. For each projected point, the function computes the angle and range. The angle is counter-clockwise positive along the x-axis, and the range is the distance from the origin.
Selects the points whose elevation angle is within the specified
Computes the scan line index for each point from the measured angle. The function assigns a scan angle to each scan line, starting from the first scan line and assigning it the value of the first element of
ScanAngleLimits. The function then increments the angle in steps of the specified
ScanAngleResolutionto the remaining scan lines.
By default, each scan line index has the maximum range. For multiple scan lines with same index, the function assigns the range value of the point closest to the origin.
Generates the 2-D lidar scan using the scan angles and the range values.
Version HistoryIntroduced in R2022a
You can now specify
tform as a
object, which uses the premultiply convention. Although you can still specify
tform as a
this object is not recommended because it uses the postmultiply convention. For more
information, see Migrate Geometric Transformations to Premultiply Convention.