Skip to content

Commit

Permalink
fix: 修复购买物品界面颜色检查偏移为0,导致无法正常判断是否购买
Browse files Browse the repository at this point in the history
  • Loading branch information
Night-stars-1 committed Jul 22, 2024
1 parent fca99e7 commit 8c692f1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion auto/run_business/buy.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def click_buy_button():
input_tap((1056, 647))
time.sleep(1)
image = screenshot()
bgr = get_bgr(image, (1177, 459))
bgr = get_bgr(image, (1177, 459), 5)
logger.debug(f"购买物品界面颜色检查: {bgr}")
if bgr != [2, 133, 253] and bgr != [251, 253, 253]:
return True
Expand Down
2 changes: 1 addition & 1 deletion auto/run_business/sell.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def click_sell_button():
input_tap((1056, 647))
time.sleep(1)
image = screenshot()
bgr = get_bgr(image, (1175, 470))
bgr = get_bgr(image, (1175, 470), 5)
logger.debug(f"出售物品界面颜色检查: {bgr}")
if bgr == [227, 131, 82]:
logger.info("检测到包含本地商品")
Expand Down
3 changes: 2 additions & 1 deletion core/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def get_bgr(
pos=(0, 0),
cropped_pos1: Tuple[int, int] = (0, 0),
cropped_pos2: Tuple[int, int] = (0, 0),
offset=0,
):
"""
说明:
Expand All @@ -94,7 +95,7 @@ def get_bgr(
]
pos = (pos[0] - cropped_pos1[0], pos[1] - cropped_pos1[1])
color = image[pos[1], pos[0]]
return BGR(*color, offset=0)
return BGR(*color, offset=offset)


def get_hsv(
Expand Down
9 changes: 7 additions & 2 deletions core/ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path
from typing import Tuple, Union

from loguru import logger
import numpy as np
from cnocr import CnOcr
from PIL import Image
Expand Down Expand Up @@ -65,7 +66,9 @@ def predict(
cropped_pos1[1] : cropped_pos2[1], cropped_pos1[0] : cropped_pos2[0]
]
out = ocr.ocr(img_fp)
return ocrout2result(out, cropped_pos1)
result = ocrout2result(out, cropped_pos1)
logger.debug(result)
return result


def number_predict(
Expand All @@ -85,4 +88,6 @@ def number_predict(
cropped_pos1[1] : cropped_pos2[1], cropped_pos1[0] : cropped_pos2[0]
]
out = number_ocr.ocr(img_fp)
return ocrout2result(out, cropped_pos1)
result = ocrout2result(out, cropped_pos1)
logger.debug(result)
return result
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 11 additions & 4 deletions tests/tools/get_pos.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
Author: Night-stars-1 nujj1042633805@gmail.com
Date: 2024-04-25 23:03:03
LastEditors: Night-stars-1 nujj1042633805@gmail.com
LastEditTime: 2024-07-22 18:33:47
"""

"""
Author: Night-stars-1 nujj1042633805@gmail.com
Date: 2024-04-01 23:06:19
Expand All @@ -14,9 +21,9 @@

import cv2

from core.adb.adb import connect, screenshot
# from core.adb.adb import connect, screenshot

connect("127.0.0.1:16384")
# connect("127.0.0.1:16384")


# 澄明数据中心 (1049, 345) 7号自由港 (665, 577) 阿妮塔战备工厂 (832, 664) 阿妮塔发射中心 (164, 420+577) 阿妮塔能源研究所 (614, 454+577)
Expand All @@ -33,8 +40,8 @@ def click_event(event, x, y, flags, param):
print("Color (HSV): ", color_hsv.tolist())


image = screenshot()
# image = cv2.imread("resources/test/MuMu12-20240422-002758.png")
# image = screenshot()
image = cv2.imread("resources/test/ae930c5ab35cd1fcda946fe4e74f8896.png")
"""
Clicked at: (626, 273)
Color (BGR): [181, 199, 14]
Expand Down

0 comments on commit 8c692f1

Please sign in to comment.