gpt4 book ai didi

python - openCV模板匹配错误: (-215)

转载 作者:太空宇宙 更新时间:2023-11-03 21:10:43 24 4
gpt4 key购买 nike

我在实时摄像头捕获中使用 opencv 模板匹配,并收到错误消息:

error: (-215) _img.size().height <= _templ.size().height && _img.size().width <= _templ.size().width in function matchTemplate

环境:

OpenCV: 3.4.1
Python3

代码(来自Official website doc的例子,我只是替换图片)

import cv2 as cv
import numpy as np
img_rgb = cv.imread('mybook.png')
img_gray = cv.cvtColor(img_rgb, cv.COLOR_BGR2GRAY)
template = cv.imread('book.jpg',0)
w, h = template.shape[::-1]
res = cv.matchTemplate(img_gray,template,cv.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
cv.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)
cv.imwrite('res.png',img_rgb)

请问我是不是做错了什么?非常感谢!

最佳答案

问题是因为我要用于模板的图片比我的原始图片大。

所以我只是更改了模板,它就修复了!感谢@dorverbin 的评论!!

关于python - openCV模板匹配错误: (-215),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50110865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com