0
$\begingroup$

Rosanswers logo

I search for a long time on wikis/forums... but i found nothing which fits to me. I still don't know how to get coordinates x y z from every point in this topic, how many points they are and, possibly, RGB values.

This is the content of a message in this topic:

header: seq: 19 stamp: secs: 124 nsecs: 110000000 frame_id: "camera_depth_optical_frame" height: 480 width: 640 fields:

name: "x"
offset: 0
datatype: 7
count: 1
  • name: "y" offset: 4 datatype: 7 count: 1
  • name: "z" offset: 8 datatype: 7 count: 1
  • name: "rgb" offset: 16 datatype: 7 count: 1 is_bigendian: False point_step: 32 row_step: 20480 data: [0, 0, 192, 127, 0, 0, 192, 127, 0, 0, 192, 127, 0, 0, 0, 0, 178, 178, 178, 0, 0, 0, 0, 0, 0, 0, 0, ...] is_dense: False

Originally posted by jvj00 on ROS Answers with karma: 3 on 2022-01-20

Post score: 0


Original comments

Comment by dembele123 on 2022-01-20:
If message is type sensor_msgs/PointCloud2.msg my advice would be to look pcl library. The pcl library has a lot of implemented things for pointclouds.

Comment by Mike Scheutzow on 2022-01-22:
Are you using roscpp or rospy?

Comment by jvj00 on 2022-01-24:
I'm using roscpp

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Hi @jvj00:

What you have here is a message of type" sensor_msgs/PointCloud2.msg: Reference: http://docs.ros.org/en/noetic/api/sensor_msgs/html/msg/PointCloud2.html

# This message holds a collection of N-dimensional points, which may
# contain additional information such as normals, intensity, etc. The
# point data is stored as a binary blob, its layout described by the
# contents of the "fields" array.

# The point cloud data may be organized 2d (image-like) or 1d
# (unordered). Point clouds organized as 2d images may be produced by
# camera depth sensors such as stereo or time-of-flight.

# Time of sensor data acquisition, and the coordinate frame ID (for 3d
# points).
Header header

# 2D structure of the point cloud. If the cloud is unordered, height is
# 1 and width is the length of the point cloud.
uint32 height
uint32 width

# Describes the channels and their layout in the binary data blob.
PointField[] fields

bool    is_bigendian # Is this data bigendian?
uint32  point_step   # Length of a point in bytes
uint32  row_step     # Length of a row in bytes
uint8[] data         # Actual point data, size is (row_step*height)

bool is_dense        # True if there are no invalid points

Let's break it a little further: The header message is of type std_msgs/Header.msg

uint32 seq
time stamp
string frame_id

In your case: header: seq: 19 stamp: secs: 124 nsecs: 110000000

uint32 height
uint32 width

frame_id: "camera_depth_optical_frame" height: 480 width: 640

Then comes

PointField[] fields

PointField[] fields is of type sensor_msgs/PointField.msg

The sensor_msgs/PointField.msg is composed of:

# This message holds the description of one point entry in the
# PointCloud2 message format.
uint8 INT8    = 1
uint8 UINT8   = 2
uint8 INT16   = 3
uint8 UINT16  = 4
uint8 INT32   = 5
uint8 UINT32  = 6
uint8 FLOAT32 = 7
uint8 FLOAT64 = 8

string name      # Name of field
uint32 offset    # Offset from start of point struct
uint8  datatype  # Datatype enumeration, see above
uint32 count     # How many elements in the field

In your case: fields: - name: "x" offset: 0 datatype: 7 count: 1 - name: "y" offset: 4 datatype: 7 count: 1 - name: "z" offset: 8 datatype: 7 count: 1

is_bigendian, point_step and row_step and is_dense are straight forward to understand.

Finally,

uint8[] data 

data contains the Actual point data, size is (row_step*height) In your case: data: [0, 0, 192, 127, 0, 0, 192, 127, 0, 0, 192, 127, 0, 0, 0, 0, 178, 178, 178, 0, 0, 0, 0, 0, 0, 0, 0, ...]

If you like to learn how to read this point with code, refer to this tutorial: http://wiki.ros.org/pcl/Tutorials


Originally posted by osilva with karma: 1650 on 2022-01-20

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by jvj00 on 2022-01-21:
Thanks a lot! I'll try to write a program with this information that you give to me

Comment by osilva on 2022-01-21:
Glad it helped. Kindly accept the answer by clicking on the check mark. Thank you.

Comment by Mike Scheutzow on 2022-01-22:
@jvj00 You do not need to convert this PointCloud2 msg to "useful" form yourself, there is already standard code in pcl_ros to do it (although I feel it is documented poorly.) See Section 3.1 on this page: http://wiki.ros.org/pcl_ros?distro=noetic

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.