Skip to content

Commit

Permalink
feat: 改善站点点击,当前仅采用站点相对坐标方案
Browse files Browse the repository at this point in the history
  • Loading branch information
Night-stars-1 committed Feb 4, 2025
1 parent 3d604db commit 51545ad
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 164 deletions.
23 changes: 12 additions & 11 deletions core/adb/adb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Author: Night-stars-1 nujj1042633805@gmail.com
Date: 2024-03-20 22:24:35
LastEditTime: 2024-07-09 17:36:17
LastEditTime: 2025-02-04 23:24:50
LastEditors: Night-stars-1 nujj1042633805@gmail.com
"""

Expand Down Expand Up @@ -93,24 +93,25 @@ def input_swipe(pos1=(919, 617), pos2=(919, 908), time: int = 100):
global ADBOREDER, ADBPATH
pos_x1 = pos1[0] + random.randint(*EXCURSIONX)
if pos_x1 > 1280:
pos_x1 = 1280
pos_x1 = 1200
elif pos_x1 < 0:
pos_x1 = 0
pos_x1 = 20
pos_y1 = pos1[1] + random.randint(*EXCURSIONY)
if pos_y1 > 720:
pos_y1 = 720
if pos_y1 > 700:
pos_y1 = 700
elif pos_y1 < 0:
pos_y1 = 0
pos_y1 = 70
pos_x2 = pos2[0] + random.randint(*EXCURSIONX)
if pos_x2 > 1280:
pos_x2 = 1280
pos_x2 = 1200
elif pos_x2 < 0:
pos_x2 = 0
pos_x2 = 20
pos_y2 = pos2[1] + random.randint(*EXCURSIONY)
if pos_y2 > 720:
pos_y2 = 720
if pos_y2 > 700:
pos_y2 = 700
elif pos_y2 < 0:
pos_y2 = 0
pos_y2 = 70
logger.debug(f"滑动 ({pos_x1}, {pos_y1}) -> ({pos_x2}, {pos_y2})")
shell = [
ADBPATH,
"-s",
Expand Down
29 changes: 28 additions & 1 deletion core/image.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""
Author: Night-stars-1 nujj1042633805@gmail.com
Date: 2024-04-01 23:18:15
LastEditTime: 2024-04-29 19:43:59
LastEditTime: 2025-02-04 23:18:27
LastEditors: Night-stars-1 nujj1042633805@gmail.com
"""

import time
from typing import List, Tuple

import cv2 as cv
import numpy as np
from loguru import logger

from core.adb.adb import screenshot
from core.module.bgr import BGR
from core.module.hsv import HSV

Expand Down Expand Up @@ -243,3 +245,28 @@ def find_icons_coordinates(image, icon_path, threshold=0.8, min_distance=10):
if not too_close:
filtered.append(coord)
return filtered

def wait_static(threshold=6000000):
"""
等待画面静止
参数:
:param threshold: 参数阈值
"""
logger.info("等待图像静止")
while True:
# 截图并转换为灰度图像
gray1 = cv.cvtColor(screenshot(), cv.COLOR_BGR2GRAY)
# 等待画面变动,并再次截图
time.sleep(0.5)
gray2 = cv.cvtColor(screenshot(), cv.COLOR_BGR2GRAY)

# 计算两帧之间的绝对差异
diff = cv.absdiff(gray1, gray2)

# 计算差异图像的总像素差异值
diff_sum = np.sum(diff)
logger.debug(f"画面差异 {diff_sum}")
# 如果差异值小于阈值,则认为图像是静止的
if diff_sum < threshold:
break
time.sleep(1)
8 changes: 6 additions & 2 deletions core/ocr.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Author: Night-stars-1 nujj1042633805@gmail.com
Date: 2024-04-01 21:40:57
LastEditTime: 2024-04-21 22:59:43
LastEditTime: 2025-02-04 23:04:09
LastEditors: Night-stars-1 nujj1042633805@gmail.com
"""

Expand All @@ -13,6 +13,8 @@
from cnocr import CnOcr
from PIL import Image

from core.image import show_image

ocr = CnOcr(rec_root="resources/model/cnocr", det_root="resources/model/cnstd")
number_ocr = CnOcr(
"number-densenet_lite_136-fc",
Expand Down Expand Up @@ -59,12 +61,14 @@ def predict(
OCR识别图片上的文字
参数:
:param img_fp: 图片
:param cropped_pos: 切剪区域 (x1, x2, y1, y2)
:param cropped_pos1: 切剪区域 (x1, y1)
:param cropped_pos2: 切剪区域 (x2, y2)
"""
if cropped_pos1 != (0, 0) and cropped_pos2 != (0, 0):
img_fp = img_fp[
cropped_pos1[1] : cropped_pos2[1], cropped_pos1[0] : cropped_pos2[0]
]
# show_image(img_fp)
out = ocr.ocr(img_fp)
result = ocrout2result(out, cropped_pos1)
logger.debug(result)
Expand Down
Loading

0 comments on commit 51545ad

Please sign in to comment.