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

How to get the separate value from the data of pcl::pointxyz ?

asked 2019-03-06 03:50:52 -0600

七小丘人 gravatar image

updated 2019-03-10 21:35:07 -0600

I can get the result (x,y,z) through the at function of pcl::PointCloud<pcl::pointxyz>,but I don't know how to get the separate value of x,y,z since my IDE can't go to the definition and I haven't seen related explanation.

std::cout << "x" << u << std::endl;
std::cout << "y" << v << std::endl;
int pcl_index;
 //std::cout << "msg_height = " << point_cloud_msg->height << std::endl;

pcl::PointCloud<pcl::PointXYZ> point_pcl;
pcl::fromROSMsg(*point_cloud_msg, point_pcl);
pcl_index = (v*640) + u; 
//std::cout<< "pcl_index" << pcl_index <<std::endl;
std::cout << "(x,y,z) = " << point_pcl.at(pcl_index) << std::endl;
edit retag flag offensive close merge delete

Comments

@七小丘人 you closed this question marking it as a right answer was chose, but you didn't mark @Dyson sphere's answer as correct. If it answered your question, can you please mark it as correct?

jayess gravatar image jayess  ( 2019-04-15 22:33:33 -0600 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2019-03-11 01:31:23 -0600

Dyson sphere gravatar image

I would suggest you to first go through Wiki on using pcl_ros module (this) before asking here, but since you already asked, refer to this wiki on section 3.2. where it explains how to subscribe to a pointcloud topic using pcl::PointCloud<pcl::PointXYZ> message type (in the end it prints results). This wiki page should help you understand how this module works (in a very limited but a good starting point way) and how to use common Pointcloud data structures, one of which is PointXYZ (as it is essentially a C-style struct with x,y,z floats).

Also good references:

edit flag offensive delete link more

Comments

cloud: width = 299018 height = 1

cloud: width = 299018 height = 1

cloud: width = 299036 height = 1

Thank you for your answer! But now I find the pointcloud is not organized and the width is not equal to 640*480. Is there another way to get the value of specific point?

七小丘人 gravatar image 七小丘人  ( 2019-03-11 07:01:12 -0600 )edit

The way pointcloud data is usually presented is 1D vector (x) instead of 2D vector (x,y) you were expecting so that width data you have is the count of all points you have in your data. To get the single point information like it was a point in 2D matrix, you have to use a little trick where you can do something like this:

point = pointcloud[ width * y + x ];

where width is the length of your data set on x axis (based on resolution, in your case 640), y is the row number you are looking for (in range from 0-480 in your case, again based on resolution) and x is the column number. You are basically handling 1D data as it was 2D but without direct access to row pointer ( example: pointcloud[x][y] ).

Also, please confirm that your data is truly 640 * 480 as when you multiply ...(more)

Dyson sphere gravatar image Dyson sphere  ( 2019-03-11 20:46:30 -0600 )edit

Thank you for your answer! I found that the pointcloud I had subscribed is Filtered and I have found the right organized pointcloud topic.

七小丘人 gravatar image 七小丘人  ( 2019-03-11 21:30:54 -0600 )edit

Question Tools

Stats

Asked: 2019-03-06 03:50:52 -0600

Seen: 1,575 times

Last updated: Mar 11 '19