2

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

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Akash
  • 103
  • 1
  • 14

2 Answers2

0

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;
Deepfreeze
  • 1,755
  • 1
  • 13
  • 18
  • Yes.. I have done the same thing yesterday. But will try and build it tomorrow. Thanks for the help. Will update whatever the result will be. :) – Akash Apr 06 '15 at 12:21
  • : It is creating an Exception while after the loop has been initialized at this statement ' output.at(1,i)[0] = cloud->points[i].x; ' – Akash Apr 13 '15 at 09:55
0
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.

Akash
  • 103
  • 1
  • 14
  • Solved....Just need to add zeroes while defining the cvmat so that it can overwrite the values. cv::Mat output; output = cv::Mat::zeros(1,cloud->points.size(),CV_32FC3); – Akash Apr 23 '15 at 07:16