ROI Errors and the Stitcher module
I have two pictures, each one of them has these dimensions: 2592x1926.
When I try to stitch them using the Stitcher module it takes about 3-4 minutes on the iPhone 4, so I decided to specify ROI to decrease the calculation time.
Here's my code:
cv::Rect rect = cvRect(img1_1.cols/2, 0, img1_1.cols/2, img1_1.rows); //roi is half of image
cv::vector<cv::Rect> roi;
roi.push_back(rect);
cv::vector<cv::vector<cv::Rect>> rois;
rois.push_back(roi);
cv::Mat imgOut;
cv::Stitcher::Status status = stitcher.stitch(images, rois, imgOut);
At the end I got this error:
Finding features...
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 Mat, file /Users/user/slave/ios_framework/src/opencv/modules/core/src/matrix.cpp, line 322
UPDATE
I tried to put two ROIs into the vector. The code looks like this:
cv::Rect rect = cvRect(img1_1.cols/2, 0, img1_1.cols/2, img1_1.rows); //second half of the first image
cv::Rect rect2 = cvRect(0, 0, img2_1.cols/2, img2_1.rows); //first half of the second image
cv::vector<cv::Rect> roi;
roi.push_back(rect);
roi.push_back(rect2);
rois.push_back(roi);
cv::Mat imgOut;
cv::Stitcher::Status status = stitcher.stitch(images, rois, imgOut);
And still I get the same error. Both images have the same size(2592x1936).
Actually I tried to find the appropriate parameters for ROI and found out that the max possible value is:
cv::Rect rect = cvRect(0, 0, 550, 550);
When I'm trying to do this:
cv::Rect rect = cvRect(0, 0, 600, 600);
it sometimes doesn't show the error, but in most cases it does.
UPDATE #2
Now my code looks like this:
cv::Rect rect = cvRect(img1_1.cols/2, 0, img1_1.cols/2, img1_1.rows);
cv::vector<cv::Rect> roi;
roi.push_back(rect);
cv::Rect rect2 = cvRect(0, 0, img2_1.cols/2, img2_1.rows);
cv::vector<cv::Rect> roi2;
roi2.push_back(rect2);
cv::vector<cv::vector<cv::Rect>> rois;
rois.resize(2);
rois[0] = roi;
rois[1] = roi2;
cv::Mat imgOut;
cv::Stitcher::Status status = stitcher.stitch(images, rois, imgOut);
And I still get the same error.
Can you please tell me what's the problem?