fix: recognize joined recommendation live tab ocr
This commit is contained in:
1 parent
debf016d23
commit
86bf5cefb1
4 files changed
+98
-16
No files matched your search
@@ -5,6 +5,7 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
from douyin.handlers.live_tab_ocr import (
|
||||
OcrTextBox,
|
||||
choose_live_tab_candidate,
|
||||
choose_live_tab_box,
|
||||
click_live_tab_on_recommend_page,
|
||||
parse_ocr_text_boxes,
|
||||
@@ -34,6 +35,23 @@ def test_choose_live_tab_ignores_long_text():
|
||||
assert selected.text == "直播"
|
||||
|
||||
|
||||
def test_choose_live_tab_from_joined_tab_row_estimates_substring_center():
|
||||
selected = choose_live_tab_candidate(
|
||||
[
|
||||
OcrTextBox(
|
||||
text="商城关注直播推荐",
|
||||
bbox=(0.0, 0.0, 1080.0, 80.0),
|
||||
confidence=0.92,
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
assert selected is not None
|
||||
assert selected.box.text == "商城关注直播推荐"
|
||||
assert 660 <= selected.center_x <= 700
|
||||
assert selected.center_y == 40.0
|
||||
|
||||
|
||||
def test_click_live_tab_uses_ocr_bbox(monkeypatch, tmp_path):
|
||||
pic = tmp_path / "live_tab.png"
|
||||
from PIL import Image
|
||||
@@ -53,7 +71,7 @@ def test_click_live_tab_uses_ocr_bbox(monkeypatch, tmp_path):
|
||||
analyser.operation.ocr = SimpleNamespace(
|
||||
readtext=MagicMock(
|
||||
return_value=[
|
||||
([[300, 10], [340, 10], [340, 35], [300, 35]], "直播", 0.96)
|
||||
([[700, 10], [740, 10], [740, 35], [700, 35]], "直播", 0.96)
|
||||
]
|
||||
)
|
||||
)
|
||||
@@ -87,6 +105,40 @@ def test_click_live_tab_falls_back_when_ocr_misses(tmp_path):
|
||||
analyser.operation.click.assert_called_once_with("D", 718, 169)
|
||||
|
||||
|
||||
def test_click_live_tab_uses_joined_row_substring(tmp_path):
|
||||
pic = tmp_path / "live_tab.png"
|
||||
from PIL import Image
|
||||
|
||||
Image.new("RGB", (1080, 80), (255, 255, 255)).save(pic)
|
||||
analyser = SimpleNamespace()
|
||||
analyser.device_id = "D"
|
||||
analyser.resolution_ratio_x = 1080
|
||||
analyser.resolution_ratio_y = 2400
|
||||
analyser.cut_pic = MagicMock()
|
||||
analyser._log_kv = MagicMock()
|
||||
analyser.operation = SimpleNamespace()
|
||||
analyser.operation.click = MagicMock()
|
||||
analyser.operation._find_pic_path = MagicMock(return_value=str(pic))
|
||||
analyser.operation.ocr_type = "easyocr"
|
||||
analyser.operation.ocr = SimpleNamespace(
|
||||
readtext=MagicMock(
|
||||
return_value=[
|
||||
(
|
||||
[[0, 0], [1080, 0], [1080, 80], [0, 80]],
|
||||
"商城关注直播推荐",
|
||||
0.96,
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
x, y, method = click_live_tab_on_recommend_page(analyser)
|
||||
|
||||
assert 660 <= x <= 700
|
||||
assert y == 180
|
||||
assert method == "ocr_live_tab"
|
||||
|
||||
|
||||
def test_recommend_page_keeps_second_step_entry_mode():
|
||||
from douyin.core.fudai_modules import run_once_basic_helpers as ronce
|
||||
|
||||
|
||||
Reference in new issue
Block a user