ROIを頭部だけに絞ってアップスケールする
This commit is contained in:
1 parent
1aa107106d
commit
c76036cd5c
4 files changed
+19
-3
No files matched your search
+3
-1
@@ -72,8 +72,10 @@ face:
|
||||
max_persons_per_frame: 3
|
||||
require_confirmed_track: true
|
||||
process_only_inside_region: false
|
||||
roi_height_ratio: 0.60
|
||||
roi_height_ratio: 0.25
|
||||
roi_expand_ratio: 0.20
|
||||
roi_square: true
|
||||
roi_upscale_target: 384
|
||||
min_roi_width: 40
|
||||
min_roi_height: 40
|
||||
static_image_mode: false
|
||||
|
||||
@@ -181,6 +181,8 @@ class FaceSettings:
|
||||
process_only_inside_region: bool
|
||||
roi_height_ratio: float
|
||||
roi_expand_ratio: float
|
||||
roi_square: bool
|
||||
roi_upscale_target: int
|
||||
min_roi_width: int
|
||||
min_roi_height: int
|
||||
static_image_mode: bool
|
||||
@@ -574,6 +576,8 @@ def _validate(config: AppConfig) -> None:
|
||||
raise ConfigurationError("face ROI ratios are outside their valid range")
|
||||
if face.min_roi_width <= 0 or face.min_roi_height <= 0:
|
||||
raise ConfigurationError("face minimum ROI dimensions must be positive")
|
||||
if face.roi_upscale_target < 0 or not isinstance(face.roi_square, bool):
|
||||
raise ConfigurationError("face roi_square/roi_upscale_target is invalid")
|
||||
if not 0.0 <= face.min_detection_confidence <= 1.0 or not 0.0 <= face.min_tracking_confidence <= 1.0:
|
||||
raise ConfigurationError("face confidence thresholds must be in [0, 1]")
|
||||
pose = config.head_pose
|
||||
|
||||
@@ -14,10 +14,15 @@ def create_face_roi(person: TrackedPerson, frame_width: int, frame_height: int,
|
||||
candidate_height = bbox.height * config.roi_height_ratio
|
||||
expand_x = bbox.width * config.roi_expand_ratio
|
||||
expand_y = candidate_height * config.roi_expand_ratio
|
||||
x1 = max(0, round(bbox.x1 - expand_x))
|
||||
y1 = max(0, round(bbox.y1 - expand_y))
|
||||
x2 = min(frame_width, round(bbox.x2 + expand_x))
|
||||
y2 = min(frame_height, round(bbox.y1 + candidate_height + expand_y))
|
||||
if config.roi_square:
|
||||
half = (y2 - y1) / 2.0 # 縦幅と同じ幅の正方形
|
||||
x1 = max(0, round(bbox.center_x - half))
|
||||
x2 = min(frame_width, round(bbox.center_x + half))
|
||||
else:
|
||||
x1 = max(0, round(bbox.x1 - expand_x))
|
||||
x2 = min(frame_width, round(bbox.x2 + expand_x))
|
||||
if x2 - x1 < config.min_roi_width or y2 - y1 < config.min_roi_height:
|
||||
return None
|
||||
return FaceROI(person.track_id, x1, y1, x2, y2, bbox, person.confidence)
|
||||
@@ -71,6 +71,11 @@ class FaceProcessor:
|
||||
image = frame[roi.y1:roi.y2, roi.x1:roi.x2]
|
||||
import cv2
|
||||
|
||||
target = self.config.roi_upscale_target
|
||||
longest = max(image.shape[:2])
|
||||
if target > 0 and longest < target:
|
||||
scale = target / longest
|
||||
image = cv2.resize(image, None, fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC)
|
||||
output = self._mesh.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
|
||||
faces = getattr(output, "multi_face_landmarks", None) or []
|
||||
if not faces:
|
||||
|
||||
Reference in new issue
Block a user