(self)
| 149 | video_control_actions.reset_media_buttons(main_window) |
| 150 | |
| 151 | def load_media(self): |
| 152 | |
| 153 | main_window = self.main_window |
| 154 | # Deselect the currently selected video |
| 155 | if main_window.selected_video_button: |
| 156 | main_window.selected_video_button.toggle() # Deselect the previous video |
| 157 | main_window.selected_video_button = False |
| 158 | |
| 159 | # Stop the current video processing |
| 160 | main_window.video_processor.stop_processing() |
| 161 | |
| 162 | if main_window.selected_target_face_id: |
| 163 | main_window.current_widget_parameters = main_window.parameters[main_window.selected_target_face_id].copy() |
| 164 | |
| 165 | if main_window.control.get('AutoSwapToggle'): |
| 166 | prev_selected_input_faces = [face for _,face in main_window.input_faces.items() if face.isChecked()] |
| 167 | prev_selected_embeddings = [embed for _,embed in main_window.merged_embeddings.items() if embed.isChecked()] |
| 168 | # Reset the frame counter |
| 169 | main_window.video_processor.current_frame_number = 0 |
| 170 | main_window.video_processor.media_path = self.media_path |
| 171 | main_window.parameters = {} |
| 172 | main_window.selected_target_face_id = False |
| 173 | main_window.video_processor.current_frame = [] |
| 174 | |
| 175 | # Release the previous media_capture if it exists |
| 176 | if main_window.video_processor.media_capture: |
| 177 | main_window.video_processor.media_capture.release() |
| 178 | |
| 179 | frame = None |
| 180 | max_frames_number = 0 # Initialize max_frames_number for either video or image |
| 181 | |
| 182 | if self.file_type == 'video': |
| 183 | media_capture = cv2.VideoCapture(self.media_path) |
| 184 | if not media_capture.isOpened(): |
| 185 | print(f"Error opening video {self.media_path}") |
| 186 | return # If the video cannot be opened, exit the function |
| 187 | |
| 188 | media_capture.set(cv2.CAP_PROP_POS_FRAMES, 0) |
| 189 | max_frames_number = int(media_capture.get(cv2.CAP_PROP_FRAME_COUNT)) - 1 |
| 190 | _, frame = misc_helpers.read_frame(media_capture) |
| 191 | main_window.video_processor.media_capture = media_capture |
| 192 | self.media_capture = media_capture |
| 193 | main_window.video_processor.fps = media_capture.get(cv2.CAP_PROP_FPS) |
| 194 | main_window.video_processor.max_frame_number = max_frames_number |
| 195 | |
| 196 | elif self.file_type == 'image': |
| 197 | frame = misc_helpers.read_image_file(self.media_path) |
| 198 | max_frames_number = 0 # For an image, there is only one "frame" |
| 199 | main_window.video_processor.max_frame_number = max_frames_number |
| 200 | |
| 201 | elif self.file_type == 'webcam': |
| 202 | res_width, res_height = self.main_window.control['WebcamMaxResSelection'].split('x') |
| 203 | |
| 204 | media_capture = cv2.VideoCapture(self.webcam_index, self.webcam_backend) |
| 205 | media_capture.set(cv2.CAP_PROP_FRAME_WIDTH, int(res_width)) |
| 206 | media_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, int(res_height)) |
| 207 | max_frames_number = 999999 |
| 208 | _, frame = misc_helpers.read_frame(media_capture) |
nothing calls this directly
no test coverage detected