I am working with a stereo camera and capturing frames with opencv. The captured frame contains image from left and right sensor joined together in one image. So with a resolution of 640*480, I have an image with 1280 columns and 480 rows. The first 640 columns belong to one sensor and the 641 to 1280 to the second sensor. I need to split it into left and right frame. I am trying to crop the left and right frames but i am getting an error. I have removed the extra code and showing only the problem area.
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
The error comes in cmd.exe and is :
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
Which I don't understand. If I have 1280 columns, why can't I just keep the 641 to 1280 columns. Anything above 0 gives the same error, So even if I use:
Mat rightframe= frame(Rect(1,0,1280,480)); // I still get same error
Any help?
Go through the documentation of Rect(x, y, width, height) where x, y are coordinates of top left corner. Accordingly it should be Mat rightframe= frame(Rect(641,0,640,480));// this gives an error
.