custom generated pointcloud2 is displayed as line on rviz
I am new in ROS, We are developing LiDAR camera and I am trying to interface out LiDAR camera with ROS. I am using ROS 1 noetic on windows 10 I write a python script to convert the depth image generated from out camera to PointCloud2 format and then publish the generated PointCloud2 format.
When I try to display the PiontCloud2 on Rviz , the pointcloud is dislayed as line on screen
here is a single PointCloud2 sample
header:
seq: 8
stamp:
secs: 1661780280
nsecs: 110538482
frame_id: "LiDAR1"
height: 80
width: 260
fields:
-
name: "x"
offset: 0
datatype: 7
count: 20800
-
name: "y"
offset: 0
datatype: 7
count: 20800
-
name: "z"
offset: 0
datatype: 7
count: 20800
is_bigendian: True
point_step: 12
row_step: 3120
data: [130, 115, 134, 191, 118, 171, 231, 190, 23, 217, 78, 64, 103 ....]
is_dense: True
---
I corrected the offset to be 4 for Y and 8 for z
I generate the Point Cloud by converting my depth image using camera parameters, applying the following command and then convert it to string
#cx shift of camera center from sensor center in x direction measured in pixels
#cy shift of camera center from sensor center in y direction measured in pixels
#fx=fy focal length in meters
#rows no of rows per frame
#cols no of columns per frame
c, r = np.meshgrid(np.arange(-cols/2,cols/2), np.arange(-rows/2,rows/2), sparse=True)
z = np.float32(depth/1000)
x = np.float32(z * (c - cx) * pixel_width / fx )
y = np.float32(z * (r - cy) * pixel_higth / fy )
ptcloud = np.dstack((x, y, z)).tostring()
my question is where's my mistake, is it in the PointCloud2 Format, or data or in Rviz configuration?
ptcloud = np.dstack((x, y, z)).tostring().
What istostring()
doing here?1> the reported pointcloud was before correction, now When echo the pointcloud2 message , I get offset 4 for y and 8 for z 2>I use tostring to convert numpy 32bit values to list of little endian 8 bits 3>I tried but I am facing some problems as well
I suspect the way you are composing point cloud. BTW, I have used the depth_image_proc package, and it works smoothly. Would you please share the problems you are facing with it? Then, you can open a new question.