python - TypeError:迭代 0 维数组 Python(图像检测)
问题描述
我正在尝试制作一个对象检测器,该检测器将从def(x1,y1,x2,y2)
但是我在运行代码时得到的错误是 TypeError: iteration over a 0-d array
错误行,它显示第 28 行,所以for (x,y,w,h) in inp
这段代码甚至可以工作吗?
我制作的代码:
import cv2
import numpy as np
import time
from PIL import ImageGrab
import pyautogui
def object_detection(File_Name, x1 ,y1 ,x2 ,y2):
F1 = File_Name
while (True):
screen = np.array(ImageGrab.grab(bbox=(x1,y1,x2,y2)))
last_time = time.time()
cv2.imshow('window',cv2.cvtColor(screen, cv2.COLOR_BGR2RGB))
inp = pyautogui.locateOnScreen(File_Name)
inp = np.array(inp)
if inp is None:
print("No " + F1 + ' Found On Screen')
if inp is not None:
print(F1 + 'Found On' + File_Name)
for (x,y,w,h) in inp:
rect = cv2.rectangle(screen,(x,y),(x+w,y+h),(0,255,0),2)
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
object_detection('Capture.PNG', 6, 138,767, 827)
解决方案
推荐阅读
- wordpress - woocommerce_update_product 操作 – 每次产品更新仅触发一次
- reactjs - 如何使用带有突变和图像上传的异步功能反应js
- r - R为数据框列表创建一个循环
- django - Django查询没有输出正确的结果
- javascript - 如何在Javascript中动态使用子对象值查找父JSON对象值?
- lucene - 使用休眠搜索以单词开头或以单词结尾
- ios - Xcode 使用 Drawercontroller 未声明的类型错误
- javascript - 带有 setInterval 的幻灯片
- linux-kernel - 向我的 Linux 添加新的设备驱动程序及其对 initrd 的影响
- php - php登录到仪表板,在chrome中显示数据泄露警报