qingfeng__
qingfeng__
采纳率0%
2017-08-07 13:43 阅读 3.3k

使用模板匹配函数 cv2.matchTemplate() 时出现如下错误

2

错误提示:
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()


有大神遇到过这样的错误吗?还望指点一下,多谢多谢~

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

相关推荐