OpenCV C++接口如何管理ROI

Har*_*ris 2 c++ opencv

使用OpenCV C++接口如何编写用于设置和重置ROI的代码用于例如:如果我需要编写类似的代码

-> Load image
-> SetImageRoi
-> Do some processing on ROI region
-> Reset ROI
-> Do some operation on entire image 
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我如何使用c ++界面进行管理?

提前致谢....

Bul*_*ull 6

以下是您需要的步骤:

// Load image
cv::Mat image = cv::imread("image_filname");

// SetImageRoi
cv::Rect roi(x, y, width, height);
cv::Mat image_roi = image(roi);
// note: this assignment does not copy data
// image and image_roi now share data

// Do some processing on ROI region
process(image_roi);
// any changes to image_roi will also be in image

// Reset ROI  
//     -- nothing required

// Do some operation on entire image 
operations(image);
Run Code Online (Sandbox Code Playgroud)