图像模板匹配知识:
//图像模板匹配
#include <stdio.h>
#include <iostream>
#include <string>
#include <opencv2\opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("person2.jpeg");
Mat temp = imread("person2_temp.jpeg");
Mat result;
matchTemplate(img, temp, result, TM_CCOEFF_NORMED);
Point max_index, min_index;
//在原图像中标注处匹配结果
double min_value, max_value;
minMaxLoc(result, &min_value, &max_value, &min_index, &max_index);//注意result中的元素位置与原图像被匹配的部分图像的最左上角的元素位置一致
rectangle(img, Rect(max_index.x, max_index.y, temp.cols, temp.rows), Scalar(255, 255, 255), 2);
namedWindow("result", WINDOW_NORMAL);
namedWindow("temp", WINDOW_NORMAL);
namedWindow("img", WINDOW_NORMAL);
imshow("result", result);
imshow("temp", temp);
imshow("img", img);
waitKey(0);
return 0;
}