Alessia Adele
Alessia Adele

Reputation: 3

Problem converting cv::Mat to pcl::pointcloud

I wrote a program that executes a segmentation of an image: it takes a rgb frame and a depth frame, and it combines them obtaining a frame in which only my interesting objects are visible. This image is putted into a cv::Mat object. I have to convert this cv::Mat into a pcl object to see the point cloud of visible objects.

I have followed the guide seen in the following link:

How to convert cv::Mat to pcl::pointcloud

but an error turns out:

/home/alessiadele/mano_cloud/src/mano/src/mano.cpp:155:37: error: >‘SimpleOpenNIViewer’ has not been declared pcl::PointCloud::Ptr SimpleOpenNIViewer::MatToPoinXYZ >(cv::Mat O

As I said before, I have taken the code from the previous link:

pcl::PointCloud<pcl::PointXYZ>::Ptr SimpleOpenNIViewer::MatToPoinXYZ(cv::Mat OpencVPointCloud)
     {
         /*
         *  Function: Get from a Mat to pcl pointcloud datatype
         *  In: cv::Mat
         *  Out: pcl::PointCloud
         */

         //char pr=100, pg=100, pb=100;
         pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud_ptr(new pcl::PointCloud<pcl::PointXYZ>);//(new pcl::pointcloud<pcl::pointXYZ>);

         for(int i=0;i<OpencVPointCloud.cols;i++)
         {
            //std::cout<<i<<endl;

            pcl::PointXYZ point;
            point.x = OpencVPointCloud.at<float>(0,i);
            point.y = OpencVPointCloud.at<float>(1,i);
            point.z = OpencVPointCloud.at<float>(2,i);

            // when color needs to be added:
            //uint32_t rgb = (static_cast<uint32_t>(pr) << 16 | static_cast<uint32_t>(pg) << 8 | static_cast<uint32_t>(pb));
            //point.rgb = *reinterpret_cast<float*>(&rgb);

            point_cloud_ptr -> points.push_back(point);


         }
         point_cloud_ptr->width = (int)point_cloud_ptr->points.size();
         point_cloud_ptr->height = 1;

         return point_cloud_ptr;

     }

From the moment that I have to use an image created into the same code, I don't think I should use SimpleOpenNIViewer, but I think I should recall the cv::Mat object from the code (In my case, it's called depth_marker); Could you please correct me? Thanks a lot!

Upvotes: 0

Views: 337

Answers (0)

Related Questions