mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-22 08:37:42 +00:00
Fix: Retry predict_door_by_name() to handle random OCR errors
This commit is contained in:
parent
c4f19cf41a
commit
8750704a4d
@ -273,7 +273,7 @@ class RouteBase(RouteBase_, RogueExit, RogueEvent):
|
||||
self.rotation_set(end_rotation, threshold=10)
|
||||
|
||||
logger.hr('Find domain exit', level=2)
|
||||
direction = self.predict_door_by_name(self.device.image)
|
||||
direction = self.predict_door(self.device.image)
|
||||
direction_limit = 55
|
||||
if direction is not None:
|
||||
if abs(direction) > direction_limit:
|
||||
|
@ -1,5 +1,4 @@
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
@ -170,7 +169,7 @@ class RogueExit(CombatInteract):
|
||||
logger.info(f'PlanarDoor: {planar_door}, direction: {direction}')
|
||||
return direction
|
||||
|
||||
def predict_door_by_name(self, image) -> Optional[float]:
|
||||
def predict_door_by_name(self, image) -> float | None:
|
||||
# Paint current name black
|
||||
x1, y1, x2, y2 = OCR_MAP_NAME.area
|
||||
image[y1:y2, x1:x2] = (0, 0, 0)
|
||||
@ -230,3 +229,19 @@ class RogueExit(CombatInteract):
|
||||
logger.error('No domain was selected, return the first instead')
|
||||
logger.info(f'Goto next domain: {results[0]}')
|
||||
return directions[0]
|
||||
|
||||
def predict_door(self, skip_first_screenshot=True) -> float | None:
|
||||
timeout = Timer(3, count=6).start()
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
else:
|
||||
self.device.screenshot()
|
||||
|
||||
if timeout.reached():
|
||||
logger.error('Predict door timeout')
|
||||
return None
|
||||
|
||||
direction = self.predict_door_by_name(self.device.image)
|
||||
if direction is not None:
|
||||
return direction
|
||||
|
Loading…
Reference in New Issue
Block a user