Ask Your Question
0

ROI Errors and the Stitcher module

asked 2012-09-21 00:40:04 -0600

zenberg gravatar image

updated 2012-09-22 22:11:45 -0600

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2012-09-21 01:58:27 -0600

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

edit flag offensive delete link more

Comments

Thank you.

zenberg gravatar imagezenberg ( 2012-09-21 03:46:11 -0600 )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 ( 2012-09-22 02:42:26 -0600 )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 ( 2012-09-24 00:59:48 -0600 )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 ( 2012-09-24 12:19:42 -0600 )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 ( 2012-09-24 23:01:10 -0600 )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 ( 2012-09-28 02:42:12 -0600 )edit

Question Tools

Stats

Asked: 2012-09-21 00:40:04 -0600

Seen: 3,901 times

Last updated: Sep 22 '12