"""接口3 马克笔检测测试:辅助函数(纯numpy) + 真实样本检测/拒识。""" import cv2 import numpy as np from conftest import fixture from hairline.marker_detect import ( detect_marker_hairline, path_to_curve_mask, _snap_anchor, ) from hairline.service import get_landmarker, get_parser def test_path_to_curve_mask(): path = np.array([[10, 5], [10, 50], [10, 90]]) # 水平线 row=10 m = path_to_curve_mask(path, 100, 100, thickness=3) assert m[10, 50] == 255 assert m[90, 50] == 0 def test_snap_anchor_moves_to_peak(): bh = np.zeros((100, 100), np.float32) bh[40, 30] = 99.0 # 峰值在 (40,30) r, c = _snap_anchor(bh, x=33, y=42, w=1000) # 起点附近 → 应吸到峰值 assert (r, c) == (40, 30) def _ctx(path_img): img = cv2.imread(path_img) rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) lm = get_landmarker().detect(rgb) pm = get_parser().parse(rgb) return img, lm, pm def test_detect_real_marked(): img, lm, pm = _ctx(fixture("marked_hairline.jpg")) path = detect_marker_hairline(img, lm, pm) assert path is not None and len(path) > 50 # 检测到画线 def test_reject_clean_photo(): img, lm, pm = _ctx(fixture("frontal.jpg")) assert detect_marker_hairline(img, lm, pm) is None # 无画线 → 拒识