Files
RSClicker/#Image Recognition Testing.py
2023-04-14 11:31:20 -04:00

35 lines
1011 B
Python

import cv2
import numpy as np
import pyautogui as pag
##Inventory Count
# Take a screenshot and store it in a numpy array
screenshot = np.array(pag.screenshot(region = (0, 1079, 1920, 1080)))
screenshot = cv2.cvtColor(screenshot, cv2.COLOR_BGR2GRAY)
# Load the image to be searched for in grayscale
image_to_search = cv2.imread('Images/shrimp.png', 0)
# Get the dimensions of the image to be searched for
h, w = image_to_search.shape[::-1]
# Use cv2.matchTemplate() to find the template image within the screenshot
result = cv2.matchTemplate(screenshot, image_to_search, cv2.TM_CCOEFF_NORMED)
# Set a threshold value to count only those template images that have a high enough correlation
threshold = 0.9
counter = 0
loc = np.where(result >= threshold)
for pt in zip(*loc[::-1]):
cv2.rectangle(screenshot, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
counter += 1
print(counter)
if counter == 27:
print('Inventory full, time to drop')
else:
print('Inventory not full, keep fishing')