//模板匹配就是在一张图片中匹配另外一张图片
//这里添加了for循环是为了处理图片尺度的问题,也是参考了大佬的博客的。
int matchtem()
{
Mat temp = imread("temp.jpg");//模板图
Mat sample = imread("sample.jpg");//原图
if (!temp.data || !sample.data)
{
cout << "conld not load image...." << endl;
return -1;
}
vector<double> res_max;
vector<Point> res_Loc;
vector<Point> temp_size;
Point minLoc;
Point maxLoc;
double min, max;
int matchMethod = cv::TemplateMatchModes::TM_CCOEFF_NORMED;
/*
res_image中值越大越好
cv::TemplateMatchModes::TM_CCOEFF;//相关性系数匹配
cv::TemplateMatchModes::TM_CCOEFF_NORMED;//标准相关性系数匹配
res_image中值越大越好
cv::TemplateMatchModes::TM_CCORR;//相关匹配
cv::TemplateMatchModes::TM_CCORR_NORMED;//标准相关匹配
在res_image中值越小表示匹配程度越高,所以应该求其中的最小值
cv::TemplateMatchModes::TM_SQDIFF;//平方差匹配
cv::TemplateMatchModes::TM_SQDIFF_NORMED;//标准平方差匹配
以上几种标
opencv模式识别之模板匹配
最新推荐文章于 2024-05-25 14:58:37 发布