feat: Enhance yanghao detection with polygon support and template matching

- Updated config.json to include new parameters for yanghao template paths and match thresholds.
- Adjusted default icon match threshold in config to 0.70 for better detection.
- Implemented polygon detection logic in yanghao_idle function to allow for flexible ROI configurations.
- Added support for per-action ROI scaling and sizes in the configuration.
- Introduced new methods in fudai_analyse for capturing ROI screenshots and matching templates.
- Created a test script to validate polygon detection against provided templates.
- Improved error handling and logging for better debugging during detection processes.
This commit is contained in:
Your Name committed 2026-01-04 09:06:25 +08:00
1 parent 3678ff7e31
commit a61ba62864
8 files changed
+848 -26

No files matched your search

+119
View File
@@ -302,6 +302,19 @@ class ConfigManager:
if "yanghao_comment_prob" in config:
analyser.yanghao_comment_prob = float(config["yanghao_comment_prob"] or 0.0)
# 模板路径(点赞/收藏)
if "yanghao_like_template_path" in config:
try:
analyser.yanghao_like_template_path = str(config["yanghao_like_template_path"] or "")
except Exception:
pass
if "yanghao_fav_template_path" in config:
try:
analyser.yanghao_fav_template_path = str(config["yanghao_fav_template_path"] or "")
except Exception:
pass
# icon 坐标/偏移/模板路径
if "yanghao_like_icon_x" in config:
analyser.yanghao_like_icon_x = int(config["yanghao_like_icon_x"] or 0)
@@ -336,6 +349,112 @@ class ConfigManager:
config["yanghao_icon_match_threshold"] or 0.72
)
# per-action ROI scale multipliers (用于扩大检测范围)
if "yanghao_like_roi_scale" in config:
try:
analyser.yanghao_like_roi_scale = float(config["yanghao_like_roi_scale"] or 1.5)
except Exception:
analyser.yanghao_like_roi_scale = 1.5
else:
analyser.yanghao_like_roi_scale = getattr(analyser, "yanghao_like_roi_scale", 1.5)
if "yanghao_fav_roi_scale" in config:
try:
analyser.yanghao_fav_roi_scale = float(config["yanghao_fav_roi_scale"] or 1.5)
except Exception:
analyser.yanghao_fav_roi_scale = 1.5
else:
analyser.yanghao_fav_roi_scale = getattr(analyser, "yanghao_fav_roi_scale", 1.5)
# per-action match thresholds (可在 config 中单独设置)
if "yanghao_like_icon_match_threshold" in config:
try:
analyser.yanghao_like_icon_match_threshold = float(config["yanghao_like_icon_match_threshold"])
except Exception:
analyser.yanghao_like_icon_match_threshold = None
else:
analyser.yanghao_like_icon_match_threshold = getattr(analyser, "yanghao_like_icon_match_threshold", None)
if "yanghao_fav_icon_match_threshold" in config:
try:
analyser.yanghao_fav_icon_match_threshold = float(config["yanghao_fav_icon_match_threshold"])
except Exception:
analyser.yanghao_fav_icon_match_threshold = None
else:
analyser.yanghao_fav_icon_match_threshold = getattr(analyser, "yanghao_fav_icon_match_threshold", None)
# per-action ROI sizes
if "yanghao_like_icon_roi_size" in config:
try:
analyser.yanghao_like_icon_roi_size = int(
config["yanghao_like_icon_roi_size"] or analyser.yanghao_icon_roi_size
)
except Exception:
analyser.yanghao_like_icon_roi_size = analyser.yanghao_icon_roi_size
if "yanghao_fav_icon_roi_size" in config:
try:
analyser.yanghao_fav_icon_roi_size = int(
config["yanghao_fav_icon_roi_size"] or analyser.yanghao_icon_roi_size
)
except Exception:
analyser.yanghao_fav_icon_roi_size = analyser.yanghao_icon_roi_size
# 支持矩形(x1,y1,x2,y2)或多边形坐标(yanghao_*_poly)配置
if "yanghao_like_rect_x1" in config:
try:
analyser.yanghao_like_rect_x1 = int(config["yanghao_like_rect_x1"] or 0)
except Exception:
analyser.yanghao_like_rect_x1 = None
if "yanghao_like_rect_y1" in config:
try:
analyser.yanghao_like_rect_y1 = int(config["yanghao_like_rect_y1"] or 0)
except Exception:
analyser.yanghao_like_rect_y1 = None
if "yanghao_like_rect_x2" in config:
try:
analyser.yanghao_like_rect_x2 = int(config["yanghao_like_rect_x2"] or 0)
except Exception:
analyser.yanghao_like_rect_x2 = None
if "yanghao_like_rect_y2" in config:
try:
analyser.yanghao_like_rect_y2 = int(config["yanghao_like_rect_y2"] or 0)
except Exception:
analyser.yanghao_like_rect_y2 = None
if "yanghao_fav_rect_x1" in config:
try:
analyser.yanghao_fav_rect_x1 = int(config["yanghao_fav_rect_x1"] or 0)
except Exception:
analyser.yanghao_fav_rect_x1 = None
if "yanghao_fav_rect_y1" in config:
try:
analyser.yanghao_fav_rect_y1 = int(config["yanghao_fav_rect_y1"] or 0)
except Exception:
analyser.yanghao_fav_rect_y1 = None
if "yanghao_fav_rect_x2" in config:
try:
analyser.yanghao_fav_rect_x2 = int(config["yanghao_fav_rect_x2"] or 0)
except Exception:
analyser.yanghao_fav_rect_x2 = None
if "yanghao_fav_rect_y2" in config:
try:
analyser.yanghao_fav_rect_y2 = int(config["yanghao_fav_rect_y2"] or 0)
except Exception:
analyser.yanghao_fav_rect_y2 = None
if "yanghao_like_poly" in config:
try:
analyser.yanghao_like_poly = list(config["yanghao_like_poly"] or [])
except Exception:
analyser.yanghao_like_poly = None
if "yanghao_fav_poly" in config:
try:
analyser.yanghao_fav_poly = list(config["yanghao_fav_poly"] or [])
except Exception:
analyser.yanghao_fav_poly = None
# 评论相关坐标与文案
if "yanghao_comment_btn_x" in config:
analyser.yanghao_comment_btn_x = int(config["yanghao_comment_btn_x"] or 0)