plasmodic / ecto_opencv

ecto bindings for opencv
21 stars 25 forks source link

RgbdPlane sample #23

Closed ilysenkov closed 12 years ago

ilysenkov commented 12 years ago

Hi,

I'm trying to use RgbdPlane on a depth image located in object_recognition_transparent_objects/sample/depth.xml.gz but I get a segmentation fault when calling RgbdPlane::operator(..). I use ecto_opencv from the commit c2eda9364b and here is my code:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/rgbd/rgbd.hpp>

using namespace cv;

int main()
{
  const string depthFilename = "depth.xml.gz";

  //read depth image
  Mat depth;
  FileStorage fs(depthFilename, FileStorage::READ);
  CV_Assert(fs.isOpened());
  fs["depth_image"] >> depth;
  fs.release();
  CV_Assert(!depth.empty());
  imshow("depth", depth);
  waitKey(3000);

  Mat cameraMatrix = (Mat_<double>(3, 3) << 525.,   0., 3.1950000000000000e+02,
                                              0., 525., 2.3950000000000000e+02,
                                              0.,   0., 1.);

  Mat points3d;
  depthTo3d(depth, cameraMatrix, points3d);
  RgbdNormals normalsEstimator(depth.rows, depth.cols, depth.depth(), cameraMatrix);
  Mat normals = normalsEstimator(points3d);

  RgbdPlane planeEstimator;
  Mat planesMask;
  vector<Vec4f> planeCoefficients;
  //planeEstimator(depth, planesMask, planeCoefficients);
  planeEstimator(depth, normals, planesMask, planeCoefficients);

  return 0;
}

Also I get a segmentation fault if I call the plane estimator this way: planeEstimator(depth, planesMask, planeCoefficients). Am I missing something?

vrabaud commented 12 years ago

sorry, the API was badly documented, you need to do: planeEstimator(points3d, normals, planesMask, planeCoefficients);

Thx !

ilysenkov commented 12 years ago

Thank you. It works perfectly now.

a-nooj commented 9 years ago

A related question: how did you figure out the values for cameraMatrix? If you could point me to any resources, that'd be awesome.