错误提示:
Traceback (most recent call last):
File "D:/学习办公盘/python学习代码/opencv/moban.py", line 12, in
res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
error: ........\opencv\modules\imgproc\src\templmatch.cpp:249: error: (-215) (img.depth() == CV_8U || img.depth() == CV_32F) && img.type() == templ.type() in function cv::matchTemplate
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('d:/学习办公盘/python学习代码/opencv/捕获.png')
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
template = cv2.imread('d:/学习办公盘/python学习代码/opencv/text3.jpg')
w= template.shape[0]
w= template.shape[1]
res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)
#cv2.imwrite('res.png',img_rgb)
cv2.imshow('res',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
有大神遇到过这样的错误吗?还望指点一下,多谢多谢~