1

Situation: I am trying to get point cloud with pcl::AdaptiveCostSOStereoMatching, which uses two rectified images (pics are ok).

I used these tutorials to learn how to do this:
First tutorial
Second tutorial

Error: programm crashes in runtime when calling "compute" method of AdaptiveCostSOStereoMatching

Question: how to correctly pass images to "compute" method?

I tried:
1) Images converted by png2pcd (command line: "png2pcd.exe in.png out.pcd")
2) Images converted with function below from cv::Mat
But no luck.

Function which converts cv::Mat to pcl::PointCloud

void MatToPointCloud(Mat& mat, pcl::PointCloud<RGB>::Ptr cloud)
{
 int width = mat.cols;
 int height = mat.rows;
 pcl::RGB val;
 val.r = 0; val.g = 0; val.b = 0;

 for (int i = 0; i < mat.rows; i++)
  for (int j = 0; j < mat.cols; j++)
  {
   auto point = mat.at<Vec3b>(i, j);
   //std::cout << j << " " << i << "\n";
   val.b = point[0];
   val.g = point[1];
   val.r = point[2];
   cloud->at(j, i) = val;
  }
 }

pcl::AdaptiveCostSOStereoMatching (compute)

    // Input
    Mat leftMat, rightMat;
    leftMat = imread("left.png");
    rightMat = imread("right.png");

    int width = leftMat.cols;
    int height = rightMat.rows;
    pcl::RGB val;
    val.r = 0; val.g = 0; val.b = 0;

    pcl::PointCloud<pcl::RGB>::Ptr left_cloud(new pcl::PointCloud<pcl::RGB>(width, height, val));
    pcl::PointCloud<pcl::RGB>::Ptr right_cloud(new pcl::PointCloud<pcl::RGB>(width, height, val));

    MatToPointCloud(leftMat, left_cloud);
    MatToPointCloud(rightMat, right_cloud);

    // Calculation
    pcl::AdaptiveCostSOStereoMatching stereo;
    stereo.setMaxDisparity(60);
    //stereo.setXOffest(0); Почему-то не распознается
    stereo.setRadius(5);
    stereo.setSmoothWeak(20);
    stereo.setSmoothStrong(100);
    stereo.setGammaC(25);
    stereo.setGammaS(10);
    stereo.setRatioFilter(20);
    stereo.setPeakFilter(0);
    stereo.setLeftRightCheck(true);
    stereo.setLeftRightCheckThreshold(1);
    stereo.setPreProcessing(true);

    stereo.compute(*left_cloud, *right_cloud); // <-- CRASHING THERE 
    stereo.medianFilter(4);

    pcl::PointCloud<pcl::PointXYZRGB>::Ptr out_cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
    stereo.getPointCloud(318.11220, 224.334900, 368.534700, 0.8387445, out_cloud, left_cloud);

Error information:
Output log: HEAP[App.exe]:
Heap block at 0000006B0F828460 modified at 0000006B0F8284A8 past requested size of 38
App.exe has triggered a breakpoint.

left_cloud (a right cloud looks like left_cloud) enter image description here

Mini question: if AdaptiveCostSOStereoMatching really allows build point cloud from 2 images, how ACSSM doing this without insintric and excentic parameters?

  • could you add the actual error string please – chris Aug 24 '15 at 23:21
  • I added error information. (Post updated) – Алексей Титов Aug 25 '15 at 06:58
  • in my experience with PCL the pointers are not so intuitive. `compute` takes pointers to a cloud, and you are using an inbuilt `Ptr`. a few suggestions to try: either drop the dereferencing (i.e. `left_cloud` not `*left_cloud`), pass it as a reference with and `&` instead of the `*`, or just use a straight point cloud not the `Ptr` and pass them as references with `&` – chris Aug 25 '15 at 09:51
  • I did this, but error still there. Also I have strange situation: when I turn off preProcessing (stereo.setPreProcessing(false)), programm not crashing, but output cloud is empty (after stereo.getPointCloud). – Алексей Титов Aug 26 '15 at 08:47
  • My PCL(`x64 VS2013`) pack did not contain `stereo` libruary. I downloaded it manually from other PCL pack(`x64 VS2010`). Could this be the cause of the error? – Алексей Титов Aug 28 '15 at 06:34

1 Answers1

0

Problem: I downloaded and installed old version of PCL without stereo.
After that, I downloaded stereo from other PCL pack and add this library to my PCL pack. And it worked incorrectly.

Solution: I compilled PCL 1.8 and my programm is ok now.
OS: Windows
IDE: MSVS 12 2013 x64

If you will try to compile PCL, these links can help you:
Official-tutorial-1
Official-tutorial-2
Good help with FLANN and VTK

Example to verify installation

Community
  • 1
  • 1