Вопрос

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

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

Это было полезно?

Решение

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;
cv::bitwise_not(roi,complement);
complement.copyTo(roi);

cv::imshow("Image",img);
cv::waitKey();

The example you provided can be done as follows:

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

Другие советы

Yes, you have a few options, see the docs.

The easiest way is usually to use a cv::Rect to specifiy the ROI:

cv::Mat img1(...);
cv::Mat dst(...);
...
cv::Rect roi(0, 0, img1.cols, img1.rows);
img1.copyTo(dst(roi));
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top