"""标注图生成测试:RGBA 透明底 + 尺寸 + 有内容(不重叠由人工目视核验)。""" import cv2 import numpy as np from conftest import fixture from face_analysis.detector import detector from face_analysis.measure import measure_face from face_analysis.annotation import create_annotated_image def test_annotation_rgba_transparent(): img = cv2.imread(fixture("frontal.jpg")) h, w = img.shape[:2] lms = detector.detect(img) r = measure_face(lms, None, w, h) # 方案A,确定性 canvas = create_annotated_image(img, r) assert canvas.mode == "RGBA" assert canvas.size == (w, h) arr = np.asarray(canvas) assert (arr[:, :, 3] == 0).any() # 存在透明像素 assert (arr[:, :, 3] > 0).any() # 存在不透明像素(线/字) def test_annotation_runs_on_hard_sample(): img = cv2.imread(fixture("hard_longhair.jpg")) h, w = img.shape[:2] lms = detector.detect(img) r = measure_face(lms, None, w, h) canvas = create_annotated_image(img, r) assert canvas.size == (w, h)