Processes a single video file by detecting and cropping the largest face in each frame and saving the results. Args: movie_path (str): Path to the video file to process. dataset_path (str): Path to the dataset directory. mask_path (str): Path to the mask directory.
(
movie_path: Path,
mask_path: Path,
dataset_path: Path,
mode: str,
num_frames: int,
stride: int,
)
| 213 | return None, None, None |
| 214 | |
| 215 | def video_manipulate( |
| 216 | movie_path: Path, |
| 217 | mask_path: Path, |
| 218 | dataset_path: Path, |
| 219 | mode: str, |
| 220 | num_frames: int, |
| 221 | stride: int, |
| 222 | ) -> None: |
| 223 | """ |
| 224 | Processes a single video file by detecting and cropping the largest face in each frame and saving the results. |
| 225 | |
| 226 | Args: |
| 227 | movie_path (str): Path to the video file to process. |
| 228 | dataset_path (str): Path to the dataset directory. |
| 229 | mask_path (str): Path to the mask directory. |
| 230 | mode (str): Either 'fixed_num_frames' or 'fixed_stride'. |
| 231 | num_frames (int): Number of frames to extract from the video. |
| 232 | stride (int): Number of frames to skip between each frame extracted. |
| 233 | margin (float): Amount to increase the size of the face bounding box by. |
| 234 | visualization (bool): Whether to save visualization images. |
| 235 | |
| 236 | Returns: |
| 237 | None |
| 238 | """ |
| 239 | |
| 240 | # Define face detector and predictor models |
| 241 | face_detector = dlib.get_frontal_face_detector() |
| 242 | predictor_path = './preprocessing/dlib_tools/shape_predictor_81_face_landmarks.dat' |
| 243 | ## Check if predictor path exists |
| 244 | if not os.path.exists(predictor_path): |
| 245 | logger.error(f"Predictor path does not exist: {predictor_path}") |
| 246 | sys.exit() |
| 247 | face_predictor = dlib.shape_predictor(predictor_path) |
| 248 | |
| 249 | def facecrop( |
| 250 | org_path: Path, |
| 251 | mask_path: Path, |
| 252 | save_path: Path, |
| 253 | mode: str, |
| 254 | num_frames: int, |
| 255 | stride: int, |
| 256 | face_predictor: dlib.shape_predictor, |
| 257 | face_detector: dlib.fhog_object_detector, |
| 258 | margin: float = 0.5, |
| 259 | visualization: bool = False |
| 260 | ) -> None: |
| 261 | """ |
| 262 | Helper function for cropping face and extracting landmarks. |
| 263 | """ |
| 264 | |
| 265 | # Open the video file |
| 266 | assert org_path.exists(), f"Video file {org_path} does not exist." |
| 267 | cap_org = cv2.VideoCapture(str(org_path)) |
| 268 | if not cap_org.isOpened(): |
| 269 | logger.error(f"Failed to open {org_path}") |
| 270 | return |
| 271 | |
| 272 | if mask_path is not None: |
nothing calls this directly
no test coverage detected