python-3.x - OpenCV 错误 -215:断言失败,无法弄清楚如何诊断此错误
问题描述
我一直在关注为 Flash 游戏 Burrito Bison 开发模板匹配机器人的教程,github 的代码链接在这里,但即使使用原始源代码似乎也无法让机器人运行。错误似乎与res = cv2.matchTemplate(img_grayscale, template, cv2.TM_CCOEFF_NORMED)
文件中的行有关vision.py
完整的错误是cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\imgproc\src\templmatch.cpp:589: error: (-215:Assertion failed) corrsize.height <= img.rows + templ.rows - 1 && corrsize.width <= img.cols + templ.cols - 1 in function 'cv::crossCorr'
没有尝试太多,我以前从未使用过 OpenCV,这对我来说很新。
def match_template(self, img_grayscale, template, threshold=0.9):
""" Matches template image in a target grayscaled image """
res = cv2.matchTemplate(img_grayscale, template, cv2.TM_CCOEFF_NORMED)
matches = np.where(res >= threshold)
预期的结果是它正常工作并玩游戏。
解决方案
推荐阅读
- jquery - symfony 集合类型将 javascript 函数添加到集合字段
- xamarin - 如何在 Xamarin Android 项目中正确使用 referenceJar?
- django - Django,sendmail密码不是来自设置
- javascript - React 中自定义钩子的异步调用
- r - 插入符号:glmboost 中的系列规范不起作用
- javascript - *ngIf 指令在 ionic 4 中不起作用
- xml - FANUC KAREL XML 解析器
- python-3.x - 通过另一列的结果累积减少列中的值
- ag-grid - 使用 AG-Grid 视口模型进行行分组
- swift - 取消对 OperationQueue 的所有操作