'cv2 magesearch pyautogui need better way to loop thu functions
im looking for a better way to write this code each function searches for the image using cv2 and pyautogui through python-image search. the code works well but I'm sure there is a better way of writing it.
I'm using https://github.com/drov0/python-imagesearch which is a wrapper around pyautogui and opencv2, to allow you to easily add cross-platform image searching capabilities to your project.
from python_imagesearch.imagesearch import *
import sys
sys.setrecursionlimit(1500)
def function_one():
pos = imagesearch("images/function_one.png")
if pos[0] != -1:
print("function_one good")
print("going to function_two")
function_two()
else:
print("function_one image not found checking again")
function_one()
def function_two():
pos = imagesearch("images/function_two.png")
if pos[0] != -1:
print("function_two")
print("looking for function_three")
function_three()
else:
print("function_two image not found checking again")
function_two()
def function_three():
pos = imagesearch("images/function_three.png")
if pos[0] != -1:
print("found function_three")
print("checking if function_four")
function_four()
else:
print("function_three image not found checking again")
function_three()
if __name__ == "__main__":
function_one()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
