feat: expose fudai region coordinates in gui
This commit is contained in:
1 parent
bcc4d1151f
commit
4797fa046e
17 files changed
+1044
-119
No files matched your search
@@ -35,13 +35,13 @@ def test_fudai_detail_debug_overview_saves_one_annotated_image(tmp_path, monkeyp
|
||||
{
|
||||
"key": "content",
|
||||
"name": "内容",
|
||||
"coords": (300, 1400, 1030, 1515),
|
||||
"coords": (360, 1460, 1035, 1545),
|
||||
"enabled": True,
|
||||
},
|
||||
{
|
||||
"key": "participants",
|
||||
"name": "人数",
|
||||
"coords": (520, 1325, 760, 1415),
|
||||
"coords": (516, 1396, 743, 1443),
|
||||
"enabled": False,
|
||||
},
|
||||
],
|
||||
@@ -91,13 +91,13 @@ def test_fudai_detail_debug_labels_are_inside_region_edges(tmp_path, monkeypatch
|
||||
{
|
||||
"key": "countdown",
|
||||
"name": "倒计时",
|
||||
"coords": (760, 1355, 1035, 1455),
|
||||
"coords": (730, 1338, 1038, 1418),
|
||||
"enabled": True,
|
||||
},
|
||||
{
|
||||
"key": "content",
|
||||
"name": "内容",
|
||||
"coords": (360, 1472, 1035, 1545),
|
||||
"coords": (360, 1460, 1035, 1545),
|
||||
"enabled": True,
|
||||
},
|
||||
],
|
||||
@@ -112,9 +112,61 @@ def test_fudai_detail_debug_labels_are_inside_region_edges(tmp_path, monkeypatch
|
||||
image, _kwargs = saved[0]
|
||||
# Labels are now drawn adjacent to their own boxes, not floating above
|
||||
# another OCR field.
|
||||
assert image.getpixel((763, 1358)) == (0, 0, 0)
|
||||
assert image.getpixel((363, 1475)) == (0, 0, 0)
|
||||
assert image.getpixel((363, 1444)) != (0, 0, 0)
|
||||
assert image.getpixel((767, 1348)) == (0, 0, 0)
|
||||
assert image.getpixel((363, 1463)) == (0, 0, 0)
|
||||
assert image.getpixel((363, 1438)) != (0, 0, 0)
|
||||
|
||||
|
||||
def test_fudai_detail_debug_overview_supports_two_task_positions(tmp_path, monkeypatch):
|
||||
from douyin.core import path_config
|
||||
from douyin.fudai.core import fudai_debug_utils
|
||||
|
||||
screenshot = tmp_path / "screenshot.png"
|
||||
Image.new("RGB", (1080, 2400), "white").save(screenshot)
|
||||
saved = []
|
||||
|
||||
def fake_save_debug_image(image, **kwargs):
|
||||
saved.append((image.copy(), kwargs))
|
||||
return str(tmp_path / "overview.png")
|
||||
|
||||
monkeypatch.setattr(path_config, "get_screenshot_path", lambda: str(screenshot))
|
||||
monkeypatch.setattr(
|
||||
"douyin.handlers.douyin_screenshot_manager.save_debug_image",
|
||||
fake_save_debug_image,
|
||||
)
|
||||
|
||||
analyser = SimpleNamespace(
|
||||
resolution_ratio_x=1080,
|
||||
resolution_ratio_y=2400,
|
||||
_log_kv=lambda *args, **kwargs: None,
|
||||
)
|
||||
|
||||
result = fudai_debug_utils.save_fudai_detail_debug_overview(
|
||||
analyser,
|
||||
[
|
||||
{
|
||||
"key": "countdown",
|
||||
"name": "倒计时",
|
||||
"coords": (760, 1328, 1038, 1398),
|
||||
"enabled": True,
|
||||
},
|
||||
{
|
||||
"key": "content",
|
||||
"name": "内容",
|
||||
"coords": (360, 1410, 1035, 1495),
|
||||
"enabled": True,
|
||||
},
|
||||
],
|
||||
ui_version="v2_0",
|
||||
ocr_enabled={"countdown", "content"},
|
||||
task_count=2,
|
||||
task_count_source="v2_pixels",
|
||||
)
|
||||
|
||||
assert result
|
||||
image, _kwargs = saved[0]
|
||||
assert image.getpixel((763, 1331)) == (0, 0, 0)
|
||||
assert image.getpixel((363, 1413)) == (0, 0, 0)
|
||||
|
||||
|
||||
def test_fudai_detail_debug_overview_cleans_old_detail_images(tmp_path, monkeypatch):
|
||||
@@ -165,3 +217,53 @@ def test_fudai_detail_debug_overview_cleans_old_detail_images(tmp_path, monkeypa
|
||||
assert not old_detail.exists()
|
||||
assert not old_overview.exists()
|
||||
assert unrelated.exists()
|
||||
|
||||
|
||||
def test_fudai_detail_debug_overview_uses_configured_profile_coords(tmp_path, monkeypatch):
|
||||
from douyin.core import path_config
|
||||
from douyin.fudai.core import coords as coords_mod
|
||||
from douyin.fudai.core import fudai_debug_utils
|
||||
|
||||
screenshot = tmp_path / "screenshot.png"
|
||||
Image.new("RGB", (1080, 2400), "white").save(screenshot)
|
||||
saved = []
|
||||
|
||||
def fake_save_debug_image(image, **kwargs):
|
||||
saved.append((image.copy(), kwargs))
|
||||
return str(tmp_path / "overview.png")
|
||||
|
||||
monkeypatch.setattr(path_config, "get_screenshot_path", lambda: str(screenshot))
|
||||
monkeypatch.setattr(
|
||||
"douyin.handlers.douyin_screenshot_manager.save_debug_image",
|
||||
fake_save_debug_image,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
coords_mod,
|
||||
"_read_runtime_region_config",
|
||||
lambda: {
|
||||
"fudai_detail_regions": {
|
||||
"v2_0_two_task": {
|
||||
"content": [111, 222, 333, 444],
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
analyser = SimpleNamespace(
|
||||
resolution_ratio_x=1080,
|
||||
resolution_ratio_y=2400,
|
||||
_log_kv=lambda *args, **kwargs: None,
|
||||
)
|
||||
profile = coords_mod.get_fudai_detail_profile("v2_0", task_count=2)
|
||||
|
||||
result = fudai_debug_utils.save_fudai_detail_debug_overview(
|
||||
analyser,
|
||||
[{"key": "content", "name": "内容", "coords": profile["content"], "enabled": True}],
|
||||
ui_version="v2_0",
|
||||
ocr_enabled={"content"},
|
||||
task_count=2,
|
||||
)
|
||||
|
||||
assert result
|
||||
image, _kwargs = saved[0]
|
||||
assert image.getpixel((114, 225)) == (0, 0, 0)
|
||||
Reference in new issue
Block a user