1

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)
7
  • 1
    When the error occurs what is inp? Is there a boolean test for a zero-dimension array? Commented Aug 29, 2020 at 1:55
  • 1
    Searching with the error message is often productive. stackoverflow.com/q/48643256/2823755 - There are others. Commented Aug 29, 2020 at 1:57
  • 1
    inp is an input source from File_Name for cv2 show an outpiut Commented Aug 29, 2020 at 15:27
  • 1
    You haven't provided enough information. Please read minimal reproducible example. Searching with the error message, it sounds like ``pyautogui.locateOnScreen(...` might be returning an iterator. You can verify that by Catching the error and inspect/print inp and its datatype. To accommodate you should change inp = np.array(inp) to inp1 = np.array(inp) and use inp1 in subsequent statements - that will preserve the original for your troubleshooting. Commented Aug 29, 2020 at 15:38
  • 1
    the data type of inp is a string not an int Commented Aug 29, 2020 at 15:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.