"""Face-anonymization sizing (PIPA). _head_boxes must scale the blur region with the person's size — a fixed ~40x40px patch leaves a close worker's face fully identifiable, defeating the anonymization the spec requires. No hardware: synthetic Person/BBox.""" from edge.app import _head_boxes from edge.models import Person, BBox, Keypoint def _person(bbox, nose_conf=0.9): nose = Keypoint(bbox.cx, bbox.y1 + 0.1 * bbox.height, nose_conf) return Person(bbox, [nose] + [Keypoint(bbox.cx, bbox.cy, nose_conf) for _ in range(16)]) def test_head_box_scales_with_person_size(): small = _head_boxes([_person(BBox(0, 0, 40, 120))])[0] big = _head_boxes([_person(BBox(0, 0, 400, 1200))])[0] # 10x bigger person assert big.width > small.width * 5, "head box must scale with the person, not be fixed" assert big.width > 40, "a close face must be covered by more than the old ~40px box" def test_head_box_falls_back_to_bbox_top_when_nose_low_confidence(): p = _person(BBox(0, 0, 100, 300), nose_conf=0.1) # nose keypoint unreliable box = _head_boxes([p])[0] assert box.width > 0 and box.height > 0 # anchored to the head region (top of the bbox), not wherever the low-conf nose landed assert box.y1 < p.bbox.cy