#include#include #include #include using namespace std; using namespace cv; int main() { Mat src = imread("src1.png"); //待搜索图像 Mat temp = imread("temp.png"); //模板图像 Mat dst = src.clone(); //原图的克隆图像 imshow("src", src); imshow("temp", temp); //创建一个映射图像 result int width = src.cols - temp.cols + 1; int height = src.rows - temp.rows + 1; Mat result(height, width, CV_32FC1); //单模板匹配 matchTemplate(src, temp, result, TM_CCORR_NORMED); //imshow("result", result); //归一化0-1 normalize(result, result, 0, 1, NORM_MINMAX, -1); //标记模板位置画出矩形框 double minValue, maxValue; Point minLoc, maxLoc; minMaxLoc(result, &minValue, &maxValue, &minLoc, &maxLoc); rectangle(dst, maxLoc, Point(maxLoc.x + temp.cols, maxLoc.y + temp.rows), Scalar(0, 255, 0), 2, 8); imshow("dst", dst); waitKey(0); }
后续继续更新。


![opencv [c++] 单模板匹配与多模板匹配 opencv [c++] 单模板匹配与多模板匹配](http://www.mshxw.com/aiimages/31/942438.png)
