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);
|
|
The easiest way is usually to use a cv::Rect to specifiy the ROI:
|

本文介绍了使用OpenCV进行图像区域(ROI)操作的方法。通过示例代码展示了如何定义ROI并进行图像拷贝、位运算等操作。这些技巧对于图像处理任务非常有用。
1431







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