My script is having a hard time identifying the image when it pops up, i ran the script and watched it in game but it failed to idenfity the picture correctly once even after running for more than 1 minute, i tried putting the confidence down to .3 but then it just thinks everything is the image
import pyautogui as pt
from time import sleep, time
# Sleep to have time to get out of pycharm
sleep(3)
# Function to tap a key with a slight delay
def tap_key(key, duration=.1):
pt.keyDown(key)
sleep(duration)
pt.keyUp(key)
# Function to continuously scan for the target picture while moving
def scan_and_move(target_images, region=None):
last_seen = time()
direction = 'd' # Initial direction (right)
while True:
for target_image in target_images:
try:
position = pt.locateCenterOnScreen(target_image, confidence=0.4)
if position:
print(f"Target image found at {position}. Pressing 'F'.")
pt.press('f')
last_seen = time()
break # Break out of loop once a target image is found
except pt.ImageNotFoundException:
# Image not found, continue to the next target image
continue
if time() - last_seen > 7:
# No picture seen for more than 3 seconds, change direction
if direction == 'd':
print("No target image found. Changing direction to 'A'.")
tap_key('d') # Tap 'D' key
direction = 'a'
else:
print("No target image found. Changing direction to 'D'.")
tap_key('a') # Tap 'A' key
direction = 'd'
sleep(.1) # Adjust scanning frequency
# Main function
def main():
# List of target images to search for
target_images = ['path/to/image1.png', 'path/to/image2.png', 'path/to/image3.png']
if __name__ == "__main__":
main()
I tried to add more picture for it to work trough but it still didnt see the picture