【发布时间】:2017-03-20 20:53:45
【问题描述】:
我正在使用立体相机并使用 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
有什么帮助吗?
【问题讨论】:
-
cv::Rect-- 第三个参数是宽度。如果您从第 641 列开始并尝试从 1280 列图像中获取额外的 1280 列,则其中一半将来自原始图像之外。这是一个错误(原因很明显)。
标签: opencv c++11 computer-vision stereo-3d