Answer the question
In order to leave comments, you need to log in
How do I fix the osu! bot?
I have already written the bot completely, but there is a problem. When he starts clicking on the circles, the bot does it sooner or later than expected. Although I picked the best screenshot (it's at the end). How to fix it so that it clicks when the game requires it?
Here is the code with computer vision
import numpy as np
import cv2
import pyautogui
import time
from PIL import ImageGrab
def click(x, y):
pyautogui.moveTo(x, y)
pyautogui.mouseDown(button='left')
time.sleep(0.01)
pyautogui.mouseUp(button='left')
def finding(filename):
img = ImageGrab.grab(bbox=(280, 22, 1637, 1079))
img_bgr = np.array(img)
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread(filename, 0)
w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshold = 0.5
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
for p in img_rgb:
x = pt[0] + w * 1.7
y = pt[1] + h / 1.7
pyautogui.moveTo(x, y)
click(x, y)
finding('note.png')
time.sleep(10)
click(963, 535)
while True:
finding('note.png')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question