0

What would be the best way to visulaize the lidar point cloud data. I am using cv_bridge for image data.

def __init__(self):

    self.bridge = CvBridge()

    self.depth_sub = message_filters.Subscriber("/os1_cloud_node/points", PointCloud2)
    self.image_sub = message_filters.Subscriber("/pylon_camera_node/image_rect_color", Image)
    ts = message_filters.ApproximateTimeSynchronizer([self.image_sub, self.depth_sub], 10, 1)
    ts.registerCallback(self.callback)
    

def callback(self, color, depth):
    pass # TODO

Edit [from comment below]:
Sorry I have used rviz to visualize the topic itself. Is there a way to extract points and diplay using opencv, pcl etc.

pc = ros_numpy.numpify(depth)
height = pc.shape[0]
width = pc.shape[1] 
np_points = np.zeros((height * width, 3), dtype=np.float32)
np_points[:, 0] = np.resize(pc['x'], height * width)
np_points[:, 1] = np.resize(pc['y'], height * width)
np_points[:, 2] = np.resize(pc['z'], height * width) 
JWCS
  • 1,120
  • 1
  • 7
  • 17
Priya Narayanan
  • 1,197
  • 2
  • 10
  • 16

1 Answers1

0

In RViz, add a visualization-subscription to the topic where your pointcloud is, then it will be automatically frame-transformed. You can save the config file, and call rviz from the launch file as well.

<launch>
  <node type="rviz" name="rviz" pkg="rviz" args="-d $(find package_name)/rviz/config_file.rviz" />
</launch>

Edit:

This is still the best way to visualize lidar data with ros. If you want to see a subset of the data, you can filter it in the node (the pointcloud2 msg is the same type as a PCL pointcloud! (see docs)), and publish it as a new topic.

If you want to do visualization with OpenCV, then you use the highgui module, assuming your data is a grayscale or rgb matrix. If you want to use PCL, they have many tutorials on their Visualization module.

From SO: this example shows fool-proof minimum example from opencv mat to ros pointcloud (and the reverse, iterating and copying data into mat, is equally valid), using ros_numpy to convert pointcloud msg, and an extensive example.

JWCS
  • 1,120
  • 1
  • 7
  • 17
  • In your case, I suppose, it would be the topic "/os1_cloud_nodes/points" – JWCS Jul 19 '20 at 17:06
  • Sorry I have used rviz to visualize the topic itself. Is there a way to extract points and diplay using opencv, pcl etc. pc = ros_numpy.numpify(depth) height = pc.shape[0] width = pc.shape[1] np_points = np.zeros((height * width, 3), dtype=np.float32) np_points[:, 0] = np.resize(pc['x'], height * width) np_points[:, 1] = np.resize(pc['y'], height * width) np_points[:, 2] = np.resize(pc['z'], height * width) – Priya Narayanan Jul 19 '20 at 19:54