This C language sample demonstrates how to quickly obtain LiDAR point cloud data using the SDK C API and save it to a PLY file when triggered by user input.
ob_error structure for comprehensive error reportingInitialize pipeline and start with default configuration
ob_error *error = NULL;
ob_pipeline *pipe = ob_create_pipeline(&error);
ob_pipeline_start(pipe, &error);
Interactive control loop for point cloud capture
while(true) {
char key = ob_smpl_wait_for_key_press(10);
if(key == ESC_KEY) {
break;
}
if(key == 'r' || key == 'R') {
// Capture and save point cloud
}
}
Capture frameset and extract LiDAR point cloud data
ob_frame *frameset = ob_pipeline_wait_for_frameset(pipe, 1000, &error);
ob_frame *frame = ob_frameset_get_frame(frameset, OB_FRAME_LIDAR_POINTS, &error);
Save point cloud to PLY file with proper cleanup
bool result = ob_save_pointcloud_to_ply("LiDARPoints.ply", frame, false, false, 50, &error);
ob_delete_frame(frameset, &error);
Proper resource cleanup on exit
ob_pipeline_stop(pipe, &error);
ob_delete_pipeline(pipe, &error);
ob_error parameterThe program generates “LiDARPoints.ply” file containing 3D point cloud data when the R key is pressed. The C API provides the same functionality as the C++ version but with explicit memory management and error handling typical of C programming patterns.
LiDAR stream is started!
Press R or r to create LiDAR PointCloud and save to ply file!
Press ESC to exit!
Save LiDAR PointCloud to ply file, this will take some time...
LiDARPoints.ply Saved
Save LiDAR PointCloud to ply file, this will take some time...
LiDARPoints.ply Saved