48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
|
import os
|
||
|
import sys
|
||
|
import time
|
||
|
import easyocr
|
||
|
import pyautogui
|
||
|
|
||
|
from cv2_test import calc_boll_count
|
||
|
|
||
|
|
||
|
reader = easyocr.Reader(['ch_sim','en'], gpu = True) # need to run only once to load model into memory
|
||
|
tmp_path=os.getenv("TEMP")
|
||
|
|
||
|
if not os.path.exists("scr_path"):
|
||
|
os.mkdir("scr_path")
|
||
|
|
||
|
def get_text(left:int,top:int,wid:int,hit:int)->list[str]:
|
||
|
img = pyautogui.screenshot(region=[left, top, wid, hit])
|
||
|
img.save(f"{tmp_path}\\screenshot.png")
|
||
|
result = reader.readtext(f"{tmp_path}\\screenshot.png")
|
||
|
ret=[]
|
||
|
for item in result:
|
||
|
ret.append(item[1])
|
||
|
return ret
|
||
|
|
||
|
def get_scr(left:int,top:int,wid:int,hit:int,text:str):
|
||
|
img = pyautogui.screenshot(region=[left, top, wid, hit])
|
||
|
img.save(f"scr_path\\{time.strftime('%Y%m%d_%H%M%S')}_{text}.png")
|
||
|
|
||
|
def get_boll_count(left:int,top:int,wid:int,hit:int):
|
||
|
path=f"{tmp_path}\\boll_scr.png"
|
||
|
img = pyautogui.screenshot(region=[left, top, wid, hit])
|
||
|
img.save(path)
|
||
|
return calc_boll_count(path)
|
||
|
|
||
|
|
||
|
def mouse_touch(left:int,top:int,wid:int,hit:int):
|
||
|
x,y=pyautogui.position()
|
||
|
if(x>left and x<left+wid and y>top and y<top+hit):
|
||
|
print("点击手机屏幕")
|
||
|
pyautogui.click()
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
print("start")
|
||
|
# get_text(1560,198,363,331)
|
||
|
result = reader.readtext(f"test.png")
|
||
|
print(result)
|
||
|
|