i1000123 i1000123 - 9 months ago 91
C++ Question

setImageROI using MAT image instead of Iplimage

cvSetImageROI(dst, cvRect(0, 0,img1->width,img1->height) );

I was using these commands to set image ROI but now i m using MAT object and these functions take only Iplimage as a parameter. Is there any similar command for Mat object?
thanks for any help

Answer Source

You can use the cv::Mat::operator() to get a reference to the selected image ROI.

Consider the following example where you want to perform Bitwise NOT operation on a specific image ROI. You would do something like this:

img = imread("image.jpg",  CV_LOAD_IMAGE_COLOR);  

int x = 20, y = 20, width = 50, height = 50;

cv::Rect roi_rect(x,y,width,height);

cv::Mat roi = img(roi_rect);

/* ROI data pointer points to a location in the same memory as img. i.e.
 No separate memory is created for roi data */

cv::Mat complement;


The example you provided can be done as follows:

cv::Mat roi = dst(cv::Rect(0, 0,img1.cols,img1.rows));