Add shopping red packet detection tests and sample image

- Implemented a test script for shopping red packet detection using pixel analysis and OCR.
- Created a sample image to simulate a shopping red packet for testing purposes.
- Added functions to test pixel detection, coordinate definitions, and OCR keyword matching.
- Included detailed print statements for test results and summaries.
This commit is contained in:
Your Name committed 2026-01-08 20:37:49 +08:00
1 parent b3011dd9ce
commit fb0c07c91a
30 files changed
+1269 -319

No files matched your search

+21 -11
View File
@@ -5,8 +5,10 @@
"""
import sys
import os
sys.path.insert(0, os.path.dirname(__file__))
def test_detect_icon_logic():
"""直接测试 _detect_icon 的核心逻辑"""
print("=== 测试 _detect_icon 核心逻辑 ===")
@@ -28,7 +30,9 @@ def test_detect_icon_logic():
def _scale_from_base(self, x, y):
return x, y
def _capture_roi_screenshot(self, roi_label, sx, sy, roi_px, shared_screenshot_path):
def _capture_roi_screenshot(
self, roi_label, sx, sy, roi_px, shared_screenshot_path
):
print(f"✅ 截图 ROI: {roi_label} at ({sx}, {sy}) size {roi_px}")
return f"/tmp/test_roi_{roi_label}.png"
@@ -46,7 +50,11 @@ def test_detect_icon_logic():
roi_size = analyser.yanghao_icon_roi_size
scale_x = analyser.resolution_ratio_x / 1080.0
scale_y = analyser.resolution_ratio_y / 2400.0
action_scale = analyser.yanghao_like_roi_scale if action == "爱心" else analyser.yanghao_fav_roi_scale
action_scale = (
analyser.yanghao_like_roi_scale
if action == "爱心"
else analyser.yanghao_fav_roi_scale
)
roi_px = max(1, int(roi_size * max(scale_x, scale_y) * float(action_scale)))
print(f" ROI 大小: {roi_px}px")
@@ -61,18 +69,18 @@ def test_detect_icon_logic():
return detected, score
# 测试爱心图标检测
like_ok, like_score = mock_detect_icon(
"爱心", 950, 1872, "", "action_like_roi"
)
like_ok, like_score = mock_detect_icon("爱心", 950, 1872, "", "action_like_roi")
# 测试收藏图标检测
fav_ok, fav_score = mock_detect_icon(
"收藏", 842, 1872, "", "action_fav_roi"
)
fav_ok, fav_score = mock_detect_icon("收藏", 842, 1872, "", "action_fav_roi")
print("\n🎯 测试结果:")
print(f" 爱心图标: {'✅ 检测成功' if like_ok else '❌ 检测失败'} (score={like_score})")
print(f" 收藏图标: {'✅ 检测成功' if fav_ok else '❌ 检测失败'} (score={fav_score})")
print(
f" 爱心图标: {'✅ 检测成功' if like_ok else '❌ 检测失败'} (score={like_score})"
)
print(
f" 收藏图标: {'✅ 检测成功' if fav_ok else '❌ 检测失败'} (score={fav_score})"
)
if like_ok and fav_ok:
print("✅ 核心逻辑测试通过:图标检测总是成功,符合修改要求")
@@ -81,6 +89,7 @@ def test_detect_icon_logic():
return like_ok and fav_ok
def test_click_logic():
"""测试点击逻辑"""
print("\n=== 测试点击逻辑 ===")
@@ -125,6 +134,7 @@ def test_click_logic():
print("❌ 点击逻辑测试失败")
return False
if __name__ == "__main__":
print("🚀 开始测试养号功能修改")
print("=" * 50)
@@ -146,4 +156,4 @@ if __name__ == "__main__":
print(" - 点击动作:在配置坐标上正确执行")
print(" - 概率控制:根据配置概率决定是否执行动作")
else:
print("\n❌ 部分测试失败,需要检查代码修改")
print("\n❌ 部分测试失败,需要检查代码修改")