Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

pcl::PointCloud to cv::Mat -> optimal way?

Hi everybody!

I would like to transform my point cloud 3D coordinates:

pcl::PointCloud<pcl::PointXYZ> point_cloud;

to an OpenCV matrix:

cv::Mat point_cloud_matrix;

I could define a 3 channel float matrix with one row per point in the point cloud, like this:

cv::Mat point_cloud_matrix(point_cloud.points.size(), 1, CV_32FC3);

and then manually copy each point on the point cloud to the matrix. But, it feels like a little bit brute force approach.

Can anyone suggest a more elegant way to do it? My ultimate goal is to apply OpenCV's k-means algorithm to extract clusters of points.

Thanks in advance!