diff --git a/src/face_geometry.py b/src/face_geometry.py index 377518b..c838053 100644 --- a/src/face_geometry.py +++ b/src/face_geometry.py @@ -3,6 +3,7 @@ from .config_loader import FaceSettings from .models import FaceROI, TrackedPerson +TRUNCATED_WIDTH_RATIO = 0.8 def create_face_roi(person: TrackedPerson, frame_width: int, frame_height: int, config: FaceSettings) -> FaceROI | None: """Create a clipped upper-body ROI or return None when the track is ineligible.""" @@ -12,12 +13,14 @@ def create_face_roi(person: TrackedPerson, frame_width: int, frame_height: int, return None bbox = person.bbox candidate_height = bbox.height * config.roi_height_ratio + if bbox.y2 >= frame_height - 2: + candidate_height = max(candidate_height, bbox.width * TRUNCATED_WIDTH_RATIO) expand_x = bbox.width * config.roi_expand_ratio expand_y = candidate_height * config.roi_expand_ratio y1 = max(0, round(bbox.y1 - expand_y)) y2 = min(frame_height, round(bbox.y1 + candidate_height + expand_y)) if config.roi_square: - half = (y2 - y1) / 2.0 # 縦幅と同じ幅の正方形 + half = (y2 - y1) / 2.0 x1 = max(0, round(bbox.center_x - half)) x2 = min(frame_width, round(bbox.center_x + half)) else: