//ROI截取
#include <stdio.h>
#include <iostream>
#include <string>
#include <opencv2\opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img = Mat::zeros(Size(400, 400), CV_8UC1);//创建一个黑色背景,注意是Size(x,y),即(列,行)
putText(img, "A", Point(1, 200), 1, 15, Scalar(255), 1);
putText(img, "B", Point(200, 200), 1, 15, Scalar(255), 1);
putText(img, "C", Point(1, 400), 1, 15, Scalar(255), 1);
putText(img, "D", Point(200, 400), 1, 15, Scalar(255), 1);
//使用Rect类型获取ROI--Rect(x,y,width,height)
Mat ROI_Rect;
ROI_Rect = img(Rect(0, 0, 200, 200));
//使用Range类型获取ROI--Range(start,end)
Mat ROI_Range;
ROI_Range = img(Range(200,400),Range(0,200));
imshow("img", img);
imshow("ROI_Rect", ROI_Rect);
imshow("ROI_Range", ROI_Range);
waitKey(0);
return 0;
}