ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
3

Problems of NaN positions when converting PointCloud2 to pcl::PointCloud PointXYZRGB

asked 2011-10-31 20:50:09 -0600

showtime gravatar image

updated 2011-10-31 20:51:10 -0600

Hello

I have tried to convert PointCloud2 message from openni_kinect to pcl::PointCloud<pcl::pointxyzrgb>. And I have some critical problem when I check position information of PointXYZRGB. All position data is written as 'nan'.

OS: Ubuntu Linux 10.04
ROS version: Electric
Sensor: Primesensor

The procedure of my code is like bellow:

A. get sensor_msg(camera/depth_registered/points) from openni_launch

B. convert sensor_msgs::PointCloud2 data (=pc2) to pcl::PointCloud<pcl::pointxyzrgb> data (=pcl_pc) as

 pcl::fromROSMsg(pc2, pcl_pc);

at this time, I check the data of pcl_pc data like bellow

cout << pcl_pc.points[0].x << endl;

the result is 'nan'

C. I convert inversely from pcl::PointCloud<pcl::pointxyzrgb> data (=pcl_pc) to convert sensor_msgs::PointCloud2 data (=pc2) for publishing to rviz a

 pcl::toROSMsg(pcl_pc, pc2);
 pub_pc_rgb.publish(pc2);

and I can make certain that point clouds data displayed correctly on rviz.

D. Moreover Moreover I saved pcl::PointCloud<pcl::pointxyzrgb> into pcd format. the values of position in this case also 'nan' like below:

# .PCD v.7 - Point Cloud Data file format
VERSION .7
FIELDS x y z rgb
SIZE 4 4 4 4
TYPE F F F F
COUNT 1 1 1 1
WIDTH 640
HEIGHT 480
VIEWPOINT 0 0 0 1 0 0 0
POINTS 307200
DATA ascii
nan nan nan 7.1023033e-39
nan nan nan 7.1023033e-39
nan nan nan 6.8275213e-39
nan nan nan 6.9197169e-39
nan nan nan 6.8278744e-39
nan nan nan 6.7356788e-39
nan nan nan 6.367262e-39
...
...

I guess this problem is associated with conversion of data format. Because the type of PointCloud2.data is unsigned char and the type of PointXYZRGB.points is float. Inside of function pcl::fromROSMsg, they copy data between these two data structure using memcpy. That's the reason that it displays correctly on rviz when I convert inversely because the function toROSMsg also use memcpy between float data(pcl::PointCloud.points) and corresponding 4 unsigned char data (PointCloud2.data).

Is there any idea about this problem?? or this only happen to me ??

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2012-02-15 22:33:15 -0600

TomTUM gravatar image

You will always find NaNs where the sensor could not detect a depth value, such as on metal surfaces, dark spots or looking out of the window. Are you sure this is not the case here? Are all position values NaNs?

edit flag offensive delete link more
0

answered 2017-04-27 04:45:44 -0600

zubair gravatar image

no not all values should be Nan even i am using pcl for my realsense r200 camera with blob detection ,, i am feeding pixel values of x and y from blob to pcl to calculate x y and z,, though i am also getting Nan values,, but i think averaging the values of x and y from blob will help you with good values,, though i am also trying to find out way to just remove Nan values from the pcl cloud,, if it sees the blob it should return me all values except NAn,, please try to do averaging on your image.

thanks

edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-10-31 20:50:09 -0600

Seen: 3,926 times

Last updated: Apr 27 '17