【发布时间】:2018-02-15 23:40:58
【问题描述】:
您好,我正在尝试使用 matchTamplate 函数,但它给出了错误
OpenCV 错误:在 cv::matchTemplate 文件 C:\ 中断言失败 ((depth == 0 || depth == 5) && type == _templ.type() && _img.dims()
这是代码
import cv2
import numpy as np
img = cv2.imread("tempmatch1.jpg")
img2gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
template = cv2.imread("tempmatch2.jpg")
w, h,_ = template.shape[::-1]
res = cv2.matchTemplate(img2gray, template, cv2.TM_CCOEFF_NORMED)
threshold = 0.80
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]):
cv2.rectangle(img, pt, (pt[0]+w, pt[1]+h), (0,0,255), 2)
cv2.imshow("detected", img)
k= cv2.waitKey(5) & 0xFF
if k==27:
cv2.destroyAllWindows()
【问题讨论】:
标签: python python-3.x opencv image-processing