I have a cv::Mat
that is a depth image.
I am converting it to a PCL pointcloud like this:
PointCloud::Ptr RGBDtoPCL3(cv::Mat depth_image)
{
PointCloud::Ptr pointcloud(new PointCloud);
float fx = 481.20;
float fy = 480.00;
float cx = 319.50;
float cy = 239.50;
float factor = 1;
depth_image.convertTo(depth_image, CV_32F); // convert the image data to float type
if (!depth_image.data) {
std::cerr << "No depth data!!!" << std::endl;
exit(EXIT_FAILURE);
}
pointcloud->width = depth_image.cols; //Dimensions must be initialized to use 2-D indexing
pointcloud->height = depth_image.rows;
pointcloud->points.resize(pointcloud->height * pointcloud->width);
pointcloud->resize(pointcloud->width*pointcloud->height);
for (int v = 0; v < depth_image.rows; v++)
{
for (int u = 0; u < depth_image.cols; u++)
{
float Z = depth_image.at<float>(v, u) / factor;
PointT p;
p.z = Z;
p.x = (u - cx) * Z / fx;
p.y = (v - cy) * Z / fy;
p.z = p.z / 1000;
p.x = p.x / 1000;
p.y = p.y / 1000;
pointcloud->points.push_back(p);
}
}
return pointcloud;
}
I am also getting the data from the Mat like this:
unsigned short* dataMat1 = depth_image.ptr<unsigned short>();
What i need to do now is Convert the pointcloud into an unsigned short *
that matches the dataMat1
above.
What would this conversion look like?
Does the depth_image.ptr<unsigned short>
just read row 0: col1, col2, col3.... row 1: col1,col2
etc?
Thank you!