Rosanswers logo

Hello, after storing each points' coordinates of a point cloud in an array, then converting them to a ROSmessage and publishing them I get the following error message while running:

array: /opt/ros/fuerte/include/pcl-1.5/pcl/ros/conversions.h:248: void pcl::toROSMsg(const pcl::PointCloud&, sensor_msgs::PointCloud2&) [with PointT = pcl::PointXYZ, sensor_msgs::PointCloud2 = sensor_msgs::PointCloud2_std::allocator<void >]: Assertion `cloud.points.size () == cloud.width * cloud.height' failed. Aborted (core dumped)

What does the last part about size, width and height mean?

Here's the part that might be the source of the error. The array's declared as 'field' with x,y,z as its elements.

msg->header.frame_id = "some_tf_frame";
msg->height = 1;
msg->width = pc.points.size();

//Storing the vector values in msg->points

for(i = msg->points.begin();i != msg->points.end();++i){
    msg->points.push_back (pcl::PointXYZ(field[j].x,field[j].y,field[j].z));
sensor_msgs::PointCloud2 output;

Originally posted by tordalk on ROS Answers with karma: 1 on 2012-10-04

Post score: 0


1 Answer 1


Rosanswers logo

Keep in mind that setting msg->width and msg->height has no effect over msg->points. The problem is that you are trying to iterate over msg->points when it is still empty.

You can verify that actually, the inside of the for loop is never being executed and msg->points.size() will be 0. msg->width * msg->height will be equal to pc.points.size() and hence the assertion failure.

You should iterate over the correct variable. Probably pc.points

I might be wrong, but I hope this helps.

Originally posted by Martin Peris with karma: 5625 on 2012-10-04

This answer was ACCEPTED on the original site

Post score: 3


Your Answer

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