【发布时间】:2019-07-17 08:40:35
【问题描述】:
我正在做一个模板匹配
现在,我要做的是找到模板匹配的准确性
我已经完成了模板匹配,但我如何获得准确性
我想我必须减去匹配的区域和模板图像。
我如何实现这一目标
代码
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
img = cv.imread('image.jpg',0)
img1 = img.copy()
template = cv.imread('template.jpg',0)
w, h = template.shape[::-1]
method = ['cv.TM_CCOEFF_NORMED','cv.TM_CCORR_NORMED']
for meth in method:
img = img1.copy()
method = eval(meth)
res = cv.matchTemplate(img,template,method)
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
bottom_right = (top_left[0] + w, top_left[1] + h)
cv.rectangle(img,top_left, bottom_right, 255, 2)
plt.subplot(121)
plt.imshow(res,cmap = 'gray')
plt.title('Matching Result')
plt.subplot(122)
plt.imshow(img,cmap = 'gray')
plt.title('Detected Point')
plt.show()
【问题讨论】:
-
opencv有absdiff功能
标签: python numpy opencv image-processing computer-vision