Skip to content

A simple code that can play a Telegram mini game using image processing ๐ŸŽฎ๐Ÿ•น

Notifications You must be signed in to change notification settings

SMotlaq/simple-gamer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

15 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Simple gamer ๐ŸŽฎ๐Ÿ•น

A simple code that can play a Telegram mini game using image processing.

Watch the video on YouTube

Donation

Is it helpful?

Buy me a Coffee

Image processing steps

First of all, we have to grab the screen image in order to be able to work with it:

original_image = np.array(ImageGrab.grab(bbox=(380,140,445,520)))

The bbox parameter sets the coordination that you want to grab. The origin is the top-left corner of your screen.

Then by passing the original_image variable to process_img(...), we start processing.

The result of this step:

raw

The prosecc contains 4 steps:

1- Grayscale

Converts the colorfull image to a grayscale image:

processed_img = cv2.cvtColor(original_image, cv2.COLOR_BGR2GRAY)

grayscaled

2- Threshold

Applys a threshold to the image. If a pixel is more than 250 it will be replaced with 255. Otherwise will be replaced with 0.

ret, processed_img = cv2.threshold(processed_img, 250, 255, cv2.THRESH_BINARY)

first-threshold

3- Convolutional filter

We know if a signal will be convolved to itself, the output of this convlution has tha maximum possible value. So in this step I convolve the screen image to a simple white circle. After this I expect to see some white blured areas at the ball position.

path = os.getcwd()
kernel_path   = os.path.join(path, 'cir.png')
kernel = np.array(cv2.imread(kernel_path))
kernel = cv2.cvtColor(kernel, cv2.COLOR_BGR2GRAY)
kernel = kernel/(kernel.sum())  

processed_img = cv2.filter2D(processed_img, -1, kernel)

convolution

As you see, a halo exists at the ball position.

4- Another threshold

Still we aren't sure about the exact ball position because of the other stuffs in the screen like that big "GOAL" text and colored papers. So I applied another threshold to the image:

ret, processed_img = cv2.threshold(processed_img, 50, 255, cv2.THRESH_BINARY)

final

Deciding when to click

This game is so simple and easy. If the ball reach to a certain area you have to click on the screen. I used a summation of pixel colors. If the summation was greater than 10*255 it means the ball is at the right position. So click!


Contact

Telegram or E-mail: motlaq@aut.ac.ir

About

A simple code that can play a Telegram mini game using image processing ๐ŸŽฎ๐Ÿ•น

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

Languages