【发布时间】:2020-06-16 15:52:13
【问题描述】:
我有 this image and 我想选择其中的所有地图,包括使用 python 的名称。
我已经用 OpenCv 试过了
from cv2 import cv2
import numpy as np
import os
for image in os.listdir('assets'):
print(image)
img_rgb = cv2.imread(image)
template = cv2.imread('assets/template/template.png')
w, h = template.shape[:-1]
res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
threshold = .8
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]): # Switch columns and rows
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
cv2.imwrite('result.png', img_rgb)
break
但我总是得到这个错误:
OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\templmatch.cpp:1104: 错误: (-215:Assertion failed) (depth == CV_8U || depth = = CV_32F) && type == _templ.type() && _img.dims()
我该怎么做?请帮忙
【问题讨论】:
-
你能显示完整的回溯吗?我不确定 for 循环中的哪个
cv2调用会引发此错误 -
你让它工作了吗?什么是错误