Ask Your Question

Revision history [back]

3D clod point to 2D image

Hello,

I have 3D point cloud data which I want to convert into 2D image and save to the disk as 16 bit png image. I am using projectPoints() function which is giving me the projected points in the form vector<>point2d> which is a 2 channel image which i cannot use in imWrite(). Is there any other way to do this? Kindly help. Code:

  std::vector<cv::Point3d> objectPoints;
  std::vector<cv::Point2d> imagePoints;
  projectPoints(objectPoints, rVec, tVec, intrisicMat, distCoeffs, imagePoints);
  depthImage = Mat(imagePoints);
  imwrite("E:/softwares/1.8.0.71/bin/depthImage1.png", depthImage);

I am getting assertion failed error because of the channel value. I have also tried the below code which is a 24 bit png image. Can I convert this to 16 bit?

 Mat depthImage = cv::Mat(height, width, CV_16UC3);
 int i = 0;
    for (int h = 0; h < depthImage.rows; h++)
    {
        for (int w = 0; w < depthImage.cols; w++)
        {
            depthImage.at<cv::Vec3f>(h, w)[0] = imagePoints[i].x ;
                depthImage.at<cv::Vec3f>(h, w)[1] = imagePoints[i].y;
            depthImage.at<cv::Vec3f>(h, w)[2] = 1;

            i++;
        }
    }

3D clod point to 2D image

Hello,

I have 3D point cloud data which I want to convert into 2D image and save to the disk as 16 bit png image. I am using projectPoints() function which is giving me the projected points in the form vector<>point2d> which is a 2 channel image which i cannot use in imWrite(). Is there any other way to do this? Kindly help. Code:

  std::vector<cv::Point3d> objectPoints;
  std::vector<cv::Point2d> imagePoints;
  projectPoints(objectPoints, rVec, tVec, intrisicMat, distCoeffs, imagePoints);
  depthImage = Mat(imagePoints);
  imwrite("E:/softwares/1.8.0.71/bin/depthImage1.png", depthImage);

I am getting assertion failed error because of the channel value. I have also tried the below code which is a 24 bit png image. Can I convert this to 16 bit?

 Mat depthImage = cv::Mat(height, width, CV_16UC3);
CV_32FC3);
 int i = 0;
    for (int h = 0; h < depthImage.rows; h++)
    {
        for (int w = 0; w < depthImage.cols; w++)
        {
            depthImage.at<cv::Vec3f>(h, w)[0] = imagePoints[i].x ;
                depthImage.at<cv::Vec3f>(h, w)[1] = imagePoints[i].y;
            depthImage.at<cv::Vec3f>(h, w)[2] = 1;

            i++;
        }
    }