The code run perfectly fine, with no errors. However, the entirety of the code is in 1 function and is kind of hard to read. As well as that I'm not sure if and how the code could be more optimised/improved. Thank you for your suggestions and help!
def ScreenShot():
pydirectinput.click(x=483, y=559 )
time.sleep(1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
time.sleep(2)
x = True
while x == True:
if x == True:
if keyboard.is_pressed('q'): # if key 'q' is pressed
print('Stopped Fishing')
break # finishing the loop
screenie = py.screenshot()
screenie.save("is_fish_there.png")
print("taking a screenshot")
Fishisthere = cv2.imread("is_fish_there.png")
img = Fishisthere[590:614,400:690]
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
lowerrange = np.array([106, 147, 0])
upperrange = np.array([179, 255, 245])
mask = cv2.inRange(hsv, lowerrange, upperrange)
blue = np.sum(mask)
print (blue)
if blue > 15000:
print("fish has been found")
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
time.sleep(.5)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
time.sleep(1.5)
#check()
ScreenShot()
Here is an example of is_fish_there.png
: