初识Opencv4.X----ROI截取

//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;
}

初识Opencv4.X----ROI截取
初识Opencv4.X----ROI截取
初识Opencv4.X----ROI截取

上一篇:OpenCV4【3】- GUI特性:轨迹栏作为调色板


下一篇:Android Studio 配置 OpenCV4+