近距離において顔検出ROIが上部に行き過ぎてしまう問題を修正
This commit is contained in:
1 parent
c76036cd5c
commit
9a4631a9f3
1 file changed
+4
-1
@@ -3,6 +3,7 @@
|
|||||||
from .config_loader import FaceSettings
|
from .config_loader import FaceSettings
|
||||||
from .models import FaceROI, TrackedPerson
|
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:
|
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."""
|
"""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
|
return None
|
||||||
bbox = person.bbox
|
bbox = person.bbox
|
||||||
candidate_height = bbox.height * config.roi_height_ratio
|
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_x = bbox.width * config.roi_expand_ratio
|
||||||
expand_y = candidate_height * config.roi_expand_ratio
|
expand_y = candidate_height * config.roi_expand_ratio
|
||||||
y1 = max(0, round(bbox.y1 - expand_y))
|
y1 = max(0, round(bbox.y1 - expand_y))
|
||||||
y2 = min(frame_height, round(bbox.y1 + candidate_height + expand_y))
|
y2 = min(frame_height, round(bbox.y1 + candidate_height + expand_y))
|
||||||
if config.roi_square:
|
if config.roi_square:
|
||||||
half = (y2 - y1) / 2.0 # 縦幅と同じ幅の正方形
|
half = (y2 - y1) / 2.0
|
||||||
x1 = max(0, round(bbox.center_x - half))
|
x1 = max(0, round(bbox.center_x - half))
|
||||||
x2 = min(frame_width, round(bbox.center_x + half))
|
x2 = min(frame_width, round(bbox.center_x + half))
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in new issue
Block a user