R
R
Ru5D1mG4me2021-03-24 10:40:02
Python
Ru5D1mG4me, 2021-03-24 10:40:02

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')

And here is note.png:605aeb379e0b7724490369.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2021-03-24
@Ru5D1mG4me

check the size of the circle, when it is about halfway, and calibrate the delay,
do not compare with the full circle, but when it starts to shrink, then insert sleep before clicking and select the value

from time import sleep
sleep(0.05)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question