1
votes

I have to convert ply data to mat data. For this i have used plyreader of pcl and convert in into point cloud and now my next step is to convert it into mat data from point cloud. I guess the point cloud which i obtained from plyreader is unorganised. I have been trying to extract the xyz values of point cloud and then copying it in at data.

pcl::PointCloud::Ptr cloud (new pcl::PointCloud); // create a new point cloud (POINTXYZ)

pcl::PLYReader reader;               
reader.read(filename,*cloud);         // read the ply file

cv::Mat output;
//...
output = cv::Mat(1,cloud->points.size(),CV_32FC3);
for(size_t i=0; i<cloud->points.size();++i)
{
    int m = cloud->points[i].x;
    int n = cloud->points[i].y;
    int l = cloud->points[i].z;

    float x0;
    float x1;
    float x2;

    output.at<cv::Vec3f>(x0,x1,x2)= cv::Vec3f(m,n,l);

}

I know it is wrong. I found one post about this but that is for organised cloud Link is here -->

Visit [pointcloud to mat]

Coversion from PointCloud to Mat

I am new to this field. If anyone know or could help!!!

Thanks in advance

2

2 Answers

0
votes

It should be:

output.at<cv::Vec3f>(1,i)[0] = cloud->points[i].x; //(1,i) is (row,col)
output.at<cv::Vec3f>(1,i)[1] = cloud->points[i].y; // [1] is y float
output.at<cv::Vec3f>(1,i)[2] = cloud->points[i].z;
0
votes
cv::Size sz;
sz= cv::Size(cloud->width,cloud->height);


cv::Mat output(sz,CV_32FC3);
cvWaitKey(50);



for (int j=0; j<output.rows;++j)
{
     for(int i= 0; i<output.cols;++i)
      {
    output.at<cv::Vec3f>(1,i)[0] = cloud->points[i].x;
    output.at<cv::Vec3f>(1,i)[1] = cloud->points[i].y;
    output.at<cv::Vec3f>(1,i)[2] = cloud->points[i].z;

      }}

There is no error in the code and runs properly but still at the cv:: Mat output, the values are not copying and giving some absurd result. Does anyone know the mistake or how to get values at output as cvmat data only.