我想检查模板匹配是否正确
就像这样:
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
img = cv.imread('messi5.jpg',0)
img2 = img.copy()
template = cv.imread('template.jpg',0)
w, h = template.shape[::-1]
methods = ['cv.TM_CCOEFF', 'cv.TM_CCOEFF_NORMED', 'cv.TM_CCORR',
'cv.TM_CCORR_NORMED', 'cv.TM_SQDIFF', 'cv.TM_SQDIFF_NORMED']
for meth in methods:
img = img2.copy()
method = eval(meth)
res = cv.matchTemplate(img,template,method)
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
if template_match:
//do something
我读过这篇文章,但我不明白
谢谢你的回答
例如:如果下面是你的模板,那么找到它的特征
cv2.TM_CCOEFF
只是一个选项,您可以使用许多其他templatesresult
变量的最小值和最大值因此,如果检测到模板,
found
变量返回长度为3的元组,这意味着模板匹配。例如:495.000是数组中的最大值
(148,26)正在开始查找对象的
(x, y)
坐标1.0是半径
相关问题 更多 >
编程相关推荐