I am trying to make an object detector that will take input from the def(x1,y1,x2,y2)
but the error I get when I run the code is TypeError: iteration over a 0-d array
Error Line, it shows line 28 so the for (x,y,w,h) in inp
is this code even going to work?
Code I made:
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)
inp? Is there a boolean test for a zero-dimension array?File_Namefor cv2 show an outpiutinpand its datatype. To accommodate you should changeinp = np.array(inp)toinp1 = np.array(inp)and useinp1in subsequent statements - that will preserve the original for your troubleshooting.