Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions configs/roi_1280x720.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions configs/roi_1280x720.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions configs/roi_1280x800.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions configs/roi_1280x800.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion tests/test_layout_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions tests/test_run_code_fixtures.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Loading