opencv学习日记——图像的模板匹配
1、图像输出结果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d22822d062a493a08f941583a3c19838.png)
2、代码部分
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("reba.png");
Rect rect(400, 200, 150, 250);
Mat temp = img(rect);
imshow("", temp);
if (img.empty() || temp.empty())
{
cout << "输入为空";
return -1;
}
Mat result;
matchTemplate(img, temp, result, TM_CCOEFF_NORMED);
double minVal, maxVal;
Point minLoc, maxLoc;
minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc);
rectangle(img, Rect(maxLoc.x, maxLoc.y, temp.cols, temp.rows), Scalar(0, 0, 255), 2);
imshow("原图", img);
imshow("result", result);
waitKey(0);
return 0;
}