Artificial Intelligence 9 min read

Implementing a WeChat Jump Game Bot Using Python and OpenCV

This article explains how to use Python and OpenCV to automatically locate the player character and the next landing platform in the WeChat Jump game by applying template matching, Canny edge detection, image cropping, and pixel analysis to calculate the required press duration.

Architecture Digest
Architecture Digest
Architecture Digest
Implementing a WeChat Jump Game Bot Using Python and OpenCV

WeChat recently introduced the "Jump" mini‑game, which quickly became popular; many developers created bots that automatically play the game by capturing the screen, calculating the distance to the next platform, and simulating a press via ADB. This article describes the computer‑vision approach using Python and OpenCV to identify the player and the landing point.

Player detection is performed with template matching because the player character has a fixed purple shape. After saving a screenshot of the character as player.png and the game screen as 1.png , the following code finds the best match:

import cv2 as cv
img = cv.imread("1.png")
player_template = cv.imread('player.png')
player = cv.matchTemplate(img, player_template, cv.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(player)

The coordinates max_loc give the top‑left corner of the player. To visualize the result, the code draws a rectangle around the player and a circle at its centre:

corner_loc = (max_loc[0] + 50, max_loc[1] + 150)
player_spot = (max_loc[0] + 25, max_loc[1] + 150)
cv.circle(img, player_spot, 10, (0, 255, 255), -1)
cv.rectangle(img, max_loc, corner_loc, (0, 0, 255), 5)
cv.namedWindow('img', cv.WINDOW_KEEPRATIO)
cv.imshow("img", img)
cv.waitKey(0)

Landing‑point detection relies on edge detection because the platforms have various shapes. First the image is blurred to reduce noise and then the Canny operator extracts edges:

img_blur = cv.GaussianBlur(img, (5, 5), 0)  # Gaussian blur
canny_img = cv.Canny(img_blur, 1, 10)        # Canny edge detection
cv.namedWindow('img', cv.WINDOW_KEEPRATIO)
cv.imshow("img", canny_img)

Only the upper half of the screen contains useful information, so the image is cropped to remove the score board and the lower part:

height, width = canny_img.shape
crop_img = canny_img[300:int(height/2), 0:width]
cv.namedWindow('img', cv.WINDOW_KEEPRATIO)
cv.imshow("img", crop_img)

Because a small portion of the player’s head may still appear in the cropped area, those pixels are cleared to avoid interference:

for y in range(max_loc[1], max_loc[1]+150):
    for x in range(max_loc[0], max_loc[0]+50):
        canny_img[y][x] = 0

To find the landing platform’s centre, the algorithm scans the cropped edge image for the first white pixel (point A) and the pixel with the maximum x‑coordinate (point B). The centre is derived from these two points:

crop_h, crop_w = crop_img.shape
center_x, center_y = 0, 0
max_x = 0
for y in range(crop_h):
    for x in range(crop_w):
        if crop_img[y, x] == 255:
            if center_x == 0:
                center_x = x
            if x > max_x:
                center_y = y
                max_x = x
cv.circle(crop_img, (center_x, center_y), 10, 255, -1)
cv.namedWindow('img', cv.WINDOW_KEEPRATIO)
cv.imshow("img", crop_img)
cv.waitKey(0)

With the player position and the landing‑point centre known, the Euclidean distance between them can be computed, and the required press duration is derived from this distance. The article notes that the same result could also be achieved with findContours but the direct pixel‑scan method is simpler for this case.

All source code is available on the author’s GitHub repository: https://github.com/Yigang0622/OpenCV_Wechat_jump .

computer visionPythonopencvTemplate MatchingCanny Edge DetectionWeChat Jump
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.