Read all frames from a video
(self, video_path)
| 254 | self.info_label.config(text=f"Loaded {len(self.mask_frames)} frames", foreground="green") |
| 255 | |
| 256 | def read_video_frames(self, video_path): |
| 257 | """Read all frames from a video""" |
| 258 | cap = cv2.VideoCapture(str(video_path)) |
| 259 | frames = [] |
| 260 | while True: |
| 261 | ret, frame = cap.read() |
| 262 | if not ret: |
| 263 | break |
| 264 | # Convert to grayscale if needed |
| 265 | if len(frame.shape) == 3: |
| 266 | frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) |
| 267 | frames.append(frame) |
| 268 | cap.release() |
| 269 | return frames |
| 270 | |
| 271 | def write_video_frames(self, frames, output_path, fps=12): |
| 272 | """Write frames to a video file using lossless H.264""" |