Automating Onmyoji Game Tasks with Python, ADB, and OpenCV
This tutorial explains how to use Python, ADB commands, OpenCV image recognition, and Tencent OCR to automate weekly tasks in the Onmyoji mobile game, including boss battles, realm breakthroughs, and resource farming, while handling multi‑instance switching and random delays for stability.
This guide demonstrates how to automate repetitive tasks in the Onmyoji mobile game by leveraging Python 3.8, Android emulators (such as LDPlayer or NetEase MuMu), and ADB for backend control.
Personal workflow : each week the user runs secret‑story dungeons, daily regional boss battles, and realm‑breakthroughs, using the tool to repeatedly claim rewards, collect breakthrough tickets, and farm souls.
Core idea : capture screenshots via ADB, process them with OpenCV to locate images or colors, and simulate taps or swipes. Random delays of 2–3 seconds are added to avoid detection.
OCR integration : after completing nine breakthroughs, the tool captures the remaining count, uploads the image to Tencent Cloud OCR, and decides whether to continue based on the recognized number. The required secretId and secretKey are stored in a tencentcloudKeys.py file.
Emulator setup : recommended resolution 1024×576, OpenGL rendering mode, compatible with Windows and macOS. References to MuMu developer documentation and common ADB command lists are provided.
Running the game : use adb shell dumpsys window | findstr mCurrentFocus to identify the active app, then start Onmyoji with adb shell am start -n com.netease.onmyoji.netease_simulator/com.netease.onmyoji.Client .
Simulating input :
Tap example: adb shell input tap 500 266
Swipe example: adb shell input swipe 0 0 200 200 500
Screenshot: adb shell screencap /data/screen.png followed by adb pull /data/screen.png .
Image matching (find image) using OpenCV:
import cv2
def p():
capture_img = ""
temp_img = ""
img1 = cv2.imread(capture_img)
img2 = cv2.imread(temp_img)
result = cv2.matchTemplate(img1, img2, cv2.TM_CCOEFF_NORMED)
if result.max() > 0.9:
return TrueColor detection (find color) :
import cv2
def p(x, y):
capture_img = ""
_img = cv2.imread(capture_img)
img = cv2.cvtColor(_img, cv2.COLOR_BGR2RGB)
r, g, b = img[y, x] # note coordinate order
return r, g, bImage cropping (extract remaining breakthrough count) :
import cv2
capture_img = ""
img = cv2.imread(capture_img)
cv2.imwrite("new.png", img[12:30, 705:750]) # crop [y0:y1, x0:x1]Multi‑instance switching : after version 2.2.2, all instances share the same package name, so switching is done via UserId. Example commands:
# Switch to original app
adb shell am start-user 0
adb shell am start --user 0 com.netease.android.cloudgame/com.netease.android.cloudgame.MainActivity
# Switch to cloned app (UserId 10)
adb shell am start-user 10
adb shell am start --user 10 com.netease.android.cloudgame/com.netease.android.cloudgame.MainActivityBy following these steps, users can run the automation tool in the background while performing other work, achieving efficient farming of in‑game resources.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.