Ask Your Question
0

ROI Errors and the Stitcher module

asked Sep 21 '12

zenberg gravatar image

updated Sep 23 '12

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?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Sep 21 '12

Alexey Spizhevoy gravatar image

Hi,

You're trying to stitch two images, but there is only one roi in the rois vector. Make sure that the vectors rois and images have the same size.

Alexey

Preview: (hide)

Comments

Thank you.

zenberg gravatar imagezenberg (Sep 21 '12)edit

The 'rois' vector contains only one element, while there must be two elements. You added two ROIs for the first image only. It should look like this: rois.resize(2); rois[0] = "the 1st image ROIs vector"; rois[1] = "the 2nd image ROIs vector";

Alexey Spizhevoy gravatar imageAlexey Spizhevoy (Sep 22 '12)edit

Alexey, unfortunately I still get the same error.

Please take a look at my second update of the post if you can.

Thanks again for your help.

zenberg gravatar imagezenberg (Sep 24 '12)edit

Possibly this is a bug. Create a new issue here: http://code.opencv.org/projects/opencv/issues, attach your code, both images, and assign the issue to me -- I'll take a look.

Alexey Spizhevoy gravatar imageAlexey Spizhevoy (Sep 24 '12)edit

Many thanks.

Here's the issue that I created(all the information is included in the attached archive): http://code.opencv.org/issues/2385

zenberg gravatar imagezenberg (Sep 25 '12)edit

Alexey, the stitching works with ROI after your awesome fix(Thanks again), but there's a new issue that I can't solve.

Can you please help me with it?

http://answers.opencv.org/question/2696/stitching-module-finding-features-and-match_conf/

zenberg gravatar imagezenberg (Sep 28 '12)edit

Question Tools

Stats

Asked: Sep 21 '12

Seen: 4,070 times

Last updated: Sep 22 '12