Skip to content

Commit

Permalink
#238 统一遮挡uid方法,使用yolo填充色
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorReid committed Apr 19, 2024
1 parent bbdb611 commit b5b293d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 39 deletions.
6 changes: 2 additions & 4 deletions src/sr/app/screen_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pyautogui

from basic.img import cv2_utils
from basic.img.os import save_debug_image
from basic.log_utils import log
from sr.app.application_base import Application
from sr.context import Context, get_context
Expand All @@ -29,9 +28,8 @@ def _execute_one_round(self):
def screenshot(self):
log.info('截图完成')
img = self.ctrl.screenshot()
no_uid = fill_uid_black(img, self.ctrl.win)
cv2_utils.show_image(no_uid, win_name='no_uid')
save_debug_image(no_uid)
fill_uid_black(img)
cv2_utils.show_image(img, win_name='no_uid')

def mouse_position(self):
rect = self.ctrl.win.get_win_rect()
Expand Down
14 changes: 3 additions & 11 deletions src/sr/image/sceenshot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,16 @@

from basic import Point
from sr.const.map_const import Region
from sr.win import Window


def fill_uid_black(screen: MatLike, win: Window = None):
def fill_uid_black(screen: MatLike):
"""
将截图的UID部分变成黑色
将截图的UID部分变成灰色 (这个颜色是YOLO的填充默认颜色)
:param screen: 屏幕截图
:param win: 窗口
:return: 没有UID的新图
"""
img = screen.copy()
lt = (30, 1030)
rb = (200, 1080)
if win is None:
cv2.rectangle(img, lt, rb, (0, 0, 0), -1)
else:
cv2.rectangle(img, win.game_pos(lt), win.game_pos(rb), (0, 0, 0), -1)
return img
cv2.rectangle(screen, lt, rb, (114, 114, 114), -1)


class MiniMapInfo:
Expand Down
4 changes: 2 additions & 2 deletions src/sr/operation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ def execute(self) -> OperationResult:
except Exception as e:
round_result = self.round_retry('异常')
if self.last_screenshot is not None:
to_save = fill_uid_black(self.last_screenshot)
file_name = save_debug_image(to_save, prefix=self.__class__.__name__)
fill_uid_black(self.last_screenshot)
file_name = save_debug_image(self.last_screenshot, prefix=self.__class__.__name__)
log.error('%s 执行出错 相关截图保存至 %s', self.display_name, file_name, exc_info=True)
else:
log.error('%s 执行出错', self.display_name, exc_info=True)
Expand Down
6 changes: 4 additions & 2 deletions src/sr/operation/unit/enable_auto_fight.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def _execute_one_round(self) -> int:
if not battle.is_auto_battle_on(screen, self.ctx.im):
log.info('检测到未启动自动战斗')
if os_utils.is_debug():
save_debug_image(fill_uid_black(screen), prefix='no_auto')
fill_uid_black(screen)
save_debug_image(screen, prefix='no_auto')
r = battle.match_battle_ctrl(screen, self.ctx.im, 'battle_ctrl_02', is_on=False)
if r is not None:
log.info('启动自动战斗')
Expand All @@ -37,7 +38,8 @@ def _execute_one_round(self) -> int:
if not battle.is_fast_battle_on(screen, self.ctx.im):
log.info('检测到未启动二倍速战斗')
if os_utils.is_debug():
save_debug_image(fill_uid_black(screen), prefix='no_fast')
fill_uid_black(screen)
save_debug_image(screen, prefix='no_fast')
r = battle.match_battle_ctrl(screen, self.ctx.im, 'battle_ctrl_03', is_on=False)
if r is not None:
log.info('启动二倍速战斗')
Expand Down
8 changes: 3 additions & 5 deletions src/sr/operation/unit/move.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import os
import time
from typing import List, Optional, Tuple, Callable, ClassVar

import cv2
import os
from cv2.typing import MatLike

from basic import Point, cal_utils, debug_utils, os_utils
from basic.i18_utils import gt
from basic.img import cv2_utils
from basic.log_utils import log
from sr import cal_pos
from sr.cal_pos import VerifyPosInfo
from sr.const import game_config_const
from sr.const.map_const import Region
from sr.context import Context
from sr.control import GameController
from sr.image.sceenshot import mini_map, MiniMapInfo, LargeMapInfo, large_map, screen_state
from sr.image.sceenshot import mini_map, MiniMapInfo, LargeMapInfo, large_map, screen_state, fill_uid_black
from sr.operation import Operation, OperationOneRoundResult, OperationResult, StateOperation, StateOperationNode
from sr.operation.unit.enter_auto_fight import EnterAutoFight
from sr.operation.unit.record_coordinate import RecordCoordinate
Expand Down Expand Up @@ -247,8 +246,7 @@ def save_screenshot(self):
"""
base = os_utils.get_path_under_work_dir('.debug', 'yolo_world_patrol', self.region.prl_id)
now = os_utils.now_timestamp_str()
uid = ScreenNormalWorld.UID.value.rect
cv2_utils.mark_area_as_color(self.last_screenshot, (uid.x1, uid.y1, uid.width, uid.height), (0, 0, 0))
fill_uid_black(self.last_screenshot)
cv2.imwrite(os.path.join(base, '%s.png' % now), self.last_screenshot)

def move_in_stuck(self) -> Optional[OperationOneRoundResult]:
Expand Down
15 changes: 0 additions & 15 deletions test/src/test/sr/image/screenshot/init_test.py

This file was deleted.

0 comments on commit b5b293d

Please sign in to comment.