convert pcl point cloud to CV32FC3
Hi,
I am writing a callbak function for point cloud. I want to convert pcl::PointCloud< pcl::PointXYZ > to a cv::Mat format 32FC3, so three channel for X Y Z coordinates, I don't need color information at all. The toROSMsg could convert the pcl point cloud to ROS image, but it is bgr8.
I have tried convert it explicitly with something like this in a for loop.
pcl_mat.at<cv::Vec3f>(i,j)[0] = curr_cloud_.at(i,j).x;
pcl_mat.at<cv::Vec3f>(i,j)[1] = curr_cloud_.at(i,j).y;
pcl_mat.at<cv::Vec3f>(i,j)[2] = curr_cloud_.at(i,j).z;
However it gives me core dumped when the for loop FINISHED. Anyone would suggest me a way to convert properly?
Best, waschbaer
If you add the code that iterates through the curr_cloud_ and creates pcl_mat the cause of the crash could be determined. Most likely the width and height of point cloud don't match the width and height of the pcl_mat.
yes, you are correct. I answer more details in my answer below.