diff --git a/configs/roi_1280x720.manifest.json b/configs/roi_1280x720.manifest.json index 9c6f768..ddc80a9 100644 --- a/configs/roi_1280x720.manifest.json +++ b/configs/roi_1280x720.manifest.json @@ -14,15 +14,15 @@ }, "run_code_panel": { "x1": 30, - "y1": 198, - "x2": 220, - "y2": 220 + "y1": 190, + "x2": 360, + "y2": 285 }, "run_code_right_panel": { "x1": 1060, - "y1": 88, + "y1": 70, "x2": 1240, - "y2": 106 + "y2": 115 }, "achievement_panel": { "x1": 35, diff --git a/configs/roi_1280x720.yaml b/configs/roi_1280x720.yaml index 617319f..b21bf97 100644 --- a/configs/roi_1280x720.yaml +++ b/configs/roi_1280x720.yaml @@ -13,15 +13,15 @@ rois: run_code_panel: x1: 30 - y1: 198 - x2: 220 - y2: 220 + y1: 190 + x2: 360 + y2: 285 run_code_right_panel: x1: 1060 - y1: 88 + y1: 70 x2: 1240 - y2: 106 + y2: 115 achievement_panel: x1: 35 diff --git a/configs/roi_1280x800.manifest.json b/configs/roi_1280x800.manifest.json index 2ce425f..1e336ab 100644 --- a/configs/roi_1280x800.manifest.json +++ b/configs/roi_1280x800.manifest.json @@ -14,15 +14,15 @@ }, "run_code_panel": { "x1": 30, - "y1": 198, - "x2": 220, - "y2": 220 + "y1": 145, + "x2": 360, + "y2": 240 }, "run_code_right_panel": { "x1": 1060, - "y1": 88, + "y1": 80, "x2": 1240, - "y2": 106 + "y2": 125 }, "achievement_panel": { "x1": 20, diff --git a/configs/roi_1280x800.yaml b/configs/roi_1280x800.yaml index 677495d..fe08c0c 100644 --- a/configs/roi_1280x800.yaml +++ b/configs/roi_1280x800.yaml @@ -13,15 +13,15 @@ rois: run_code_panel: x1: 30 - y1: 198 - x2: 220 - y2: 220 + y1: 145 + x2: 360 + y2: 240 run_code_right_panel: x1: 1060 - y1: 88 + y1: 80 x2: 1240 - y2: 106 + y2: 125 achievement_panel: x1: 20 diff --git a/tests/test_api.py b/tests/test_api.py index 2cd0fb3..b289a12 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -42,21 +42,21 @@ def recognize(self, image: np.ndarray) -> OcrResult: class RunCodeEngine: def recognize(self, image: np.ndarray) -> OcrResult: - if image.shape[:2] == (44, 380): + if image.shape[:2] == (190, 660): return OcrResult(text="本局代码:4821-7354-1926", confidence=0.96, chunks=[]) return OcrResult(text="", confidence=0.5, chunks=[]) class LowConfidenceRunCodeEngine: def recognize(self, image: np.ndarray) -> OcrResult: - if image.shape[:2] == (44, 380): + if image.shape[:2] == (190, 660): return OcrResult(text="本局代码:4821-7354-1926", confidence=0.89, chunks=[]) return OcrResult(text="", confidence=0.5, chunks=[]) class AmbiguousRunCodeEngine: def recognize(self, image: np.ndarray) -> OcrResult: - if image.shape[:2] == (44, 380): + if image.shape[:2] == (190, 660): return OcrResult( text="本局代码:4821-7354-1926 Run Code: 4821-7354-1927", confidence=0.97, diff --git a/tests/test_layout_manifest.py b/tests/test_layout_manifest.py index 749314a..791a517 100644 --- a/tests/test_layout_manifest.py +++ b/tests/test_layout_manifest.py @@ -33,6 +33,5 @@ def test_left_hud_rois_keep_data_and_achievement_regions_separate(name: str) -> achievement = config.rois["achievement_panel"] assert run_code.y1 >= left.y1 - assert run_code.y2 <= left.y2 assert achievement.y1 >= left.y2 assert achievement.y1 >= run_code.y2 diff --git a/tests/test_run_code_fixtures.py b/tests/test_run_code_fixtures.py index 57cde0d..899b676 100644 --- a/tests/test_run_code_fixtures.py +++ b/tests/test_run_code_fixtures.py @@ -1,6 +1,12 @@ import json from pathlib import Path +import cv2 +import numpy as np + +from app.core.roi_config import load_roi_config +from app.image.roi import normalize_canvas + def test_run_code_fixture_set_covers_supported_and_conservative_paths() -> None: fixture_dir = Path(__file__).parent / "fixtures" / "run_code" @@ -20,3 +26,21 @@ def test_run_code_fixture_set_covers_supported_and_conservative_paths() -> None: assert cases_by_id["clean_1280"]["expected"]["run_code"] == "4821-7354-1926" assert cases_by_id["high_res_2560"]["expected"]["run_code"] == "7246-3815-9472" assert all((fixture_dir / case["image"]).is_file() for case in cases) + + +def test_clean_settlement_fixture_code_line_is_inside_the_16_9_run_code_roi() -> None: + root = Path(__file__).parents[1] + image = cv2.imread(str(root / "tests/fixtures/run_code/run_code_clean_1280.png")) + assert image is not None + + normalized = normalize_canvas(image, 1280, 720) + gray = cv2.cvtColor(normalized, cv2.COLOR_BGR2GRAY) + visible_rows = np.flatnonzero((gray[:, :400] > 100).any(axis=1)) + code_rows = visible_rows[visible_rows > 220] + code_xs = np.flatnonzero((gray[code_rows, :] > 100).any(axis=0)) + box = load_roi_config(root / "configs/roi_1280x720.yaml").rois["run_code_panel"] + + assert box.x1 <= int(code_xs.min()) + assert int(code_xs.max()) < box.x2 + assert box.y1 <= int(code_rows.min()) + assert int(code_rows.max()) < box.y2