【发布时间】:2020-12-09 01:47:51
【问题描述】:
我目前正在屏幕上制作一个对象查找器,但这是我的代码似乎无法正常工作的东西我收到错误AttributeError: 'numpy.ndarray' object has no attribute 'read'
我的对象查找器代码:
from PIL import ImageGrab
import cv2
import time
import numpy as np
def find(file):
while True:
Screen = np.array(ImageGrab.grab(bbox=(13, 32,805, 623)))
gray = cv2.cvtColor(Screen, cv2.COLOR_BGR2GRAY)
img_rgb = Screen.read()
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread(file,0)
w, h = 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)
k = cv2.waitKey(30) & 0xff
if k == 27:
cv2.destroyAllWindows()
break
cv2.imshow('Frame', gray)
find('13.png')
发生这种情况有什么原因吗?
【问题讨论】:
标签: python numpy python-imaging-library cv2