介绍:
图像ROI(region of interest)是指图像中感兴趣的区域。
在OpenCV中设置图像ROI区域,只对图像感兴趣的区域操作。
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat img;
img = imread("D:/learn/c++/opencv/ROI/ROI/3.jpg");
if (img.empty())
{
cout << "read error" << endl;
}
imshow("img", img);
int height = img.rows;
int width = img.cols;
cout << "img: height*width" << height << "*" << width << endl;
Rect rect(Point(50, 20), Point(100, 120));
Mat roi = img(rect);
imshow("roi", roi);
roi.setTo(Scalar(255, 255, 255));
imshow("img-1", img);
Mat img2 = roi.clone();
img2.setTo(Scalar(0, 0, 0));
imshow("img-2", img);
imshow("img-3", img);
waitKey(0);
}