 CodexandClaude Sonnet 4.5
|
bb90e2983f
|
fix(pil): 补充修复剩余 PIL Image 资源泄漏
覆盖 14 个文件中的 Image.open() 未正确关闭问题:
- fansclub_handler: 5 处(pic/pic_rgb/img 未 close)
- image_ops: 2 处(crop 后 pic 未 close)
- douyin_popups: 2 处(pic.convert 重赋值泄漏原始句柄)
- douyin_fudai: 1 处(open().convert() 链式调用泄漏)
- douyin_robot: 2 处(同上)
- save_files/direct_attend/finder/stage/find_open/detail/_common/ocr_preprocess: 各 1-2 处
统一修复模式:分离 open 与 convert,try/finally 确保原始句柄关闭。
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
2026-05-23 22:49:50 +08:00 |
|
 CodexandClaude Opus 4.7
|
b200002a00
|
refactor(finder): 抽 OpenCV 模板匹配兜底到 finder_template_match (635 → 417)
check_have_fudai_with_ready_screenshot L288-513 是像素检测都失败时的最后
兜底(226 行):cv2.matchTemplate(TM_CCOEFF_NORMED) + minMaxLoc 在
156..269 × 351..451 搜索区域里找 fudai.png 模板。
抽到 douyin/detection/detection_pkg/finder_template_match.py:
- match_template(analyser, pic_new, rx, ry, y_pianyi_val, loop) → (det, x)
- _resolve_template_path 从 path_config / 项目根 assets 解析模板路径
(兜底走 .. 回退,避免推到 detection_pkg/assets)
- _save_search_roi 提取 last_match.png 的保存逻辑
主 finder.py 替换为 7 行委托,从 635 → 417 行。
新增 9 个单元测试覆盖:
- _resolve_template_path:用 path_config / 兜底
- 早出条件:模板路径不存在 / cv2.imread 返回 None / 搜索区域无效
- 命中:max_val>=threshold 时 detected_x 是 1080 基准
- 不命中:max_val<threshold 时返回 False
- 模板太大:cv2.resize 被调用
- cv2 不可用时安全返回 False
1345 passed (+9)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-23 02:26:49 +08:00 |
|
 CodexandClaude Opus 4.7
|
ab846dae0f
|
refactor(finder): 抽逐像素兜底扫描到 finder_pixel_scan (817 → 635)
check_have_fudai_with_ready_screenshot L279-461 是 numpy 失败时的逐像素
兜底(183 行):optimal_x 从历史 / 默认热区中心选起 → 检查 5 个 y 偏移
(0/±1/±2)→ 每行从 optimal 向两侧交替搜索 → 最后从左到右兜底。
抽到 douyin/detection/detection_pkg/finder_pixel_scan.py:
- scan_pixel_by_pixel(analyser, pic_new, rx, ry, y_pianyi_val) → (detected, x)
- _is_target_pixel / _safe_check_pixel / _pick_optimal_x / _search_along_y
4 个独立纯函数,每个职责单一
颜色范围常量与 finder_numpy_scan 对齐(_R_MIN/_MAX 等)。
主 finder.py 替换为 8 行委托。
新增 15 个单元测试覆盖:
- _is_target_pixel 边界 / _safe_check_pixel 异常兜底
- _pick_optimal_x 历史命中/越界/无历史 3 种路径
- scan_pixel_by_pixel 主路径成功 / y 偏移 / 越界失败 / pic 异常兜底
1336 passed (+15)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-23 02:20:25 +08:00 |
|
 CodexandClaude Opus 4.7
|
07cdd662c2
|
refactor(finder): 抽 numpy 加速扫描段到 finder_numpy_scan (937 → 811)
check_have_fudai_with_ready_screenshot L271-397 是"numpy 加速水平带扫描"
逻辑(126 行):ROI 裁剪 → RGB 颜色掩码 → 列聚合 → 从最优起始列向两侧
交替搜索第一个匹配列 → 写回 last_fudai_x。
抽到 douyin/detection/detection_pkg/finder_numpy_scan.py:
- scan_with_numpy(analyser, pic_new, rx, ry, y_pianyi_val, optimal_x_scaled)
→ (detected, detected_x)
- numpy ImportError / 异常时返回 (False, None),让 caller 走逐像素兜底
主 finder.py 替换为 7 行委托。
新增 8 个单元测试(用真实 PIL.Image + numpy 构造小图):
- 空图返回 False
- 整图目标色命中 + last_fudai_x 写回
- 仅在某段列有目标色,命中位置在该段
- y_pianyi_val 偏移正确传递到扫描带
- ROI 越界返回 False
- optimal_x_scaled 在命中区时优先返回该位置
1321 passed (+8)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-23 02:15:43 +08:00 |
|
 CodexandClaude Opus 4.7
|
1514122981
|
chore(finder): 删 check_have_fudai_with_ready_screenshot 末尾 501 行死代码 (1438 → 937)
L938-1438 全部位于 L936 `return False` 之后,永远不会执行:
- 旧版重复参数初始化(retry_delay_s / max_wait_s 等)
- 已被弃用的模板匹配兜底代码块
- 末尾的"以下为旧的像素检测代码"注释块
文件大小直接砍 35%,无任何行为变化。
1313 passed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-05-23 02:09:36 +08:00 |
|
 CodexandClaude Opus 4.7
|
787c4e8eec
|
拆分 douyin_detection (1756 → 3 个子模块 + 22 行 shim)
把 douyin/detection/douyin_detection.py 按职责拆成
douyin/detection/detection_pkg/ 子包:
- _common (14) _ensure_detection_cache 共享缓存初始化
- detail (323) check_detail_height + check_in_fudai_detail(详情页相关)
- finder (1438) check_have_fudai_with_ready_screenshot(找福袋图标主入口,最大头)
原文件改为 22 行 re-export shim,4 个公共符号全部保留。
- check_in_fudai_detail 5 处外部引用
- check_have_fudai_with_ready_screenshot 3 处外部引用
- check_detail_height 2 处外部引用
全部不需修改。
子包名 detection_pkg 是为了避免与同目录下的 shim 文件 douyin_detection.py
潜在的命名混淆。
回归:
- 4 个新文件 + shim compileall 通过
- pytest 353 passed / 1 skipped
- 旧 import 路径与新子包路径返回同一函数对象
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
2026-05-21 16:55:24 +08:00 |
|