ROI creation [closed]

asked 2015-02-11 08:21:27 -0600

Ribs gravatar image

Hey guys,

can you help me create a ROI of the type "vector < vector < rect> > & rois" for the function stitch? Its a vector of vector of the image's ROIs (rectangles) ?

thank you.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by StevenPuttemans
close date 2015-02-12 06:08:16.501483

Comments

1

You could have waited until your previous question was answered ... basically you can do it with the following pseudocode.

vector< vector<Rect> > all_matches;
vector<Rect> first_match, second_match;
Rect roi_first_image = Rect(x1,y1,w1,h1);
Rect roi_second_image = Rect(x2,y2,w2,h2);
Rect roi_third_image = Rect(x3,y3,w3,h3);
Rect roi_fourth_image = Rect(x4,y4,w4,h4);
first_match.push_back(roi_first_image);
first_match.push_back(roi_second_image);
second_match.push_back(roi_third_image);
second_match.push_back(roi_fourth_image);
all_matches.push_back(first_match);
all_matches.push_back(second_match);

Now you can push all_matches to the stitcher pipeline.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-02-11 08:35:13 -0600 )edit

sorry, it was a different question, I thought it was better to create another question. I'll try this pseudocode and give the feedback. thanks =)

Ribs gravatar imageRibs ( 2015-02-11 09:08:46 -0600 )edit
1

it partially works!

for (int i = initial_num; i<= num_img ; i++) {

    vector< Rect> roi;
    Rect left = cvRect(0, 0, imgs[i].cols*0.2, imgs[i].rows);
    Rect right = cvRect(imgs[i].cols*0.5, 0, imgs[i].cols*0.5, imgs[i].rows);
    //cout << imgs[i].cols*0.8<<"cols\n";
    roi.push_back(left);
    roi.push_back(right);

    roisFinal.push_back(roi);
}

this code works. But when I change 0.5 to 0.8 ( to get the last 20% of the image) or any other number, it gives an error:

Ribs gravatar imageRibs ( 2015-02-11 09:37:39 -0600 )edit

error:

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 /opt/local/var/macports/build/_opt_mports_dports_graphics_opencv/opencv/work/opencv-2.4.10/modules/core/src/matrix.cpp, line 323
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /opt/local/var/macports/build/_opt_mports_dports_graphics_opencv/opencv/work/opencv-2.4.10/modules/core/src/matrix.cpp:323: error: (-215) 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 function Mat

Abort trap: 6
Ribs gravatar imageRibs ( 2015-02-11 09:38:46 -0600 )edit

I will look into it tomorrow!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-02-11 12:27:29 -0600 )edit
1

ok, and I found this code:

if (i == 1) {
        Rect newSize(0, 0, tmp.cols * 2 / 5, tmp.rows);
        roi1.push_back(newSize);
        rois.push_back(roi1);
        roi1.clear();
    } else if (i == argc - 2) {
        Rect newSize(tmp.cols * 3 / 5, 0, tmp.cols * 2 / 5, tmp.rows);
        roi2.push_back(newSize);
        rois.push_back(roi2);
        roi2.clear();
    } else {
        Rect newSize(0, 0, tmp.cols * 2 / 5, tmp.rows);
        roi1.push_back(newSize);
        newSize = cvRect(tmp.cols * 3 / 5, 0, tmp.cols * 2 / 5, tmp.rows);
        roi1.push_back(newSize);
        rois.push_back(roi1);
        roi1.clear();
    }

and it worked. But I didn't understand the values 2/5 and 3/5.

Ribs gravatar imageRibs ( 2015-02-11 12:31:21 -0600 )edit
1

its the subdimensions of the rectangle that you want to match. That code does exactly what I gave you :P

StevenPuttemans gravatar imageStevenPuttemans ( 2015-02-12 02:11:02 -0600 )edit
1

thanks man

Ribs gravatar imageRibs ( 2015-02-12 05:50:23 -0600 )edit