将立体相机框架分成左右传感器框架

时间:2017-03-20 20:53:45

标签: opencv c++11 computer-vision stereo-3d

我正在使用立体相机并使用opencv捕获帧。捕获的帧包含来自左和右传感器的图像在一个图像中连接在一起。因此,分辨率为640 * 480,我有一个1280列和480行的图像。前640列属于一个传感器,641到1280属于第二传感器。我需要把它分成左右两帧。我试图裁剪左右框架,但我收到一个错误。我删除了额外的代码,只显示问题区域。

  cap >> frame; // get a new frame from camera
  Mat fullframe = frame(Rect(0, 0, 1280, 480 )); //only to check that I have 1280 columns and 480 rows.and this line works
  Mat leftframe= frame(Rect(0,0,640,480)); // This also works
  Mat rightframe= frame(Rect(641,0,1280,480));// this gives an error

错误来自cmd.exe,并且是:

    OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x +roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <=m.rows) in cv::Mat::Mat, file C:\builds\2_4_PackSlave-win64-vc11-shared\opencv\modules\core\src\matrix.cpp, line 323

我不明白。如果我有1280列,为什么我不能保留641到1280列。高于0的任何值都会产生相同的错误,所以即使我使用:

    Mat rightframe= frame(Rect(1,0,1280,480)); // I still get same error

任何帮助?

2 个答案:

答案 0 :(得分:0)

浏览Rect(x,y,width,height)的文档,其中x,y是左上角的坐标。因此,它应该是Mat rightframe= frame(Rect(641,0,640,480));// this gives an error

答案 1 :(得分:0)

OpenCV通常假设矩形的顶部和左边界是包含的,而右边界和底边界不是。因此,我建议你的代码应该是这样的。

cap >> frame;
Mat fullframe = frame(Rect(0, 0, 1280, 480 ));
Mat leftframe= frame(Rect(0, 0, 640, 480));
Mat rightframe= frame(Rect(640, 0, 640, 480));

我知道这有点晚了,但它可能有助于其他人在将来看看这个问题。