小天才《速算王者》自動腳本








方法寫在了圖片里,下面是文字:
文件下載鏈接(新):avolip-hyp.ysepan.com
ADB命令:
adb start-server
adb shell am start com.xtc.selftest/.ui.ControllerActivity
python配置(先安裝pip)
pip3 install pillow -i https://pypi.mirrors.ustc.edu.cn/simple?
pip3 install pytesseract -i https://pypi.mirrors.ustc.edu.cn/simple?
pip3 install uiautomator2 -i https://pypi.mirrors.ustc.edu.cn/simple
pip3 install pyautogui –i https://pypi.mirrors.ustc.edu.cn/simple?
uiautomator2 init
代碼:
from PIL import Image
import pytesseract
import uiautomator2 as u2
import PIL.ImageOps
import pyautogui
import os,sys
import time
pytesseract.pytesseract.tesseract_cmd = "D:\\Program Files\\Tesseract-OCR\\tesseract.exe"
#os.system("/usr/local/bin/adb shell LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -P 320x360@320x360/0 -s >" + name)
#os.system('adb shell screencap -p /data/local/tmp/tmp.png')
#os.system('adb pull /data/local/tmp/tmp.png')
d=u2.connect('10d03286')
f=0
ansp=int(input("目標(biāo)分?jǐn)?shù):"))
input("等待第一題,確認(rèn)請回車")
while True:
? ? img = pyautogui.screenshot(region=[0,38,320,360]) # x,y,w,h
? ? #img.save('screenshot.png')
? ? #img = CV2.cvtColor(np.asarray(img),CV2.COLOR_RGB2BGR)
? ? #img = Image.open("screen.png")
? ? Img=img.convert('L')
? ? Img=PIL.ImageOps.invert(Img)
? ? threshold=20
? ? filter_func = lambda x: 0 if x < threshold else 1?
? ? photo = Img.point(filter_func,'1')
? ? box = (0,70,320,250)
? ? #photo.show()
? ? photo = photo.crop(box)
? ? jieguo = pytesseract.image_to_string( photo ,config="--psm 6 stdout -c tessedit_char_whitelist=0123456789-*+=",lang="num").split("=")
? ? if(eval(jieguo[0]) == int(jieguo[1])):
? ? ? ? d(resourceId="com.xtc.arithmeticmaster:id/btn_answer_right").click()
? ? else:
? ? ? ? d(resourceId="com.xtc.arithmeticmaster:id/btn_answer_error").click()
? ? if(f+1 == ansp):
? ? ? ? print("系統(tǒng)提示:分?jǐn)?shù)已達成,自動結(jié)束")
? ? ? ? break
? ? f+=1
? ? time.sleep(0.35)

提示:如果手表比較卡,適當(dāng)增加time.sleep的時間,否則可能因為響應(yīng)遲鈍而失敗。