Update vision_analyzer.py
Browse files- vision_analyzer.py +5 -31
vision_analyzer.py
CHANGED
|
@@ -43,7 +43,7 @@ MIN_FREE_SPACE_GB = 2 # Minimum free space in GB before processing
|
|
| 43 |
DEFAULT_FPS = 3 # Default frames per second for extraction
|
| 44 |
|
| 45 |
# Cursor Tracking Parameters
|
| 46 |
-
|
| 47 |
|
| 48 |
# Initialize HF API
|
| 49 |
hf_api = HfApi(token=HF_TOKEN)
|
|
@@ -57,8 +57,7 @@ processing_status = {
|
|
| 57 |
"failed_files": 0,
|
| 58 |
"extracted_courses": 0,
|
| 59 |
"extracted_videos": 0,
|
| 60 |
-
|
| 61 |
-
"tracked_cursors_count": 0,
|
| 62 |
"last_update": None,
|
| 63 |
"logs": []
|
| 64 |
}
|
|
@@ -263,21 +262,7 @@ def extract_frames(video_path, output_dir, fps=DEFAULT_FPS):
|
|
| 263 |
log_message(f"Extracted {saved_idx-1} frames from {video_path} to {output_dir}")
|
| 264 |
return saved_idx - 1
|
| 265 |
|
| 266 |
-
# --- Cursor Tracking Utilities ---
|
| 267 |
-
def to_rgb(img):
|
| 268 |
-
if img is None:
|
| 269 |
-
return None
|
| 270 |
-
if len(img.shape) == 2:
|
| 271 |
-
return cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
|
| 272 |
-
if img.shape[2] == 4:
|
| 273 |
-
return cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
|
| 274 |
-
return img
|
| 275 |
|
| 276 |
-
def get_mask_from_alpha(template_img):
|
| 277 |
-
if template_img is not None and len(template_img.shape) == 3 and template_img.shape[2] == 4:
|
| 278 |
-
# Use alpha channel as mask (nonzero alpha = 255)
|
| 279 |
-
return (template_img[:, :, 3] > 0).astype(np.uint8) * 255
|
| 280 |
-
return None
|
| 281 |
|
| 282 |
|
| 283 |
|
|
@@ -331,11 +316,7 @@ def process_rar_file(rar_path: str) -> bool:
|
|
| 331 |
processing_status["extracted_videos"] += 1
|
| 332 |
log_message(f"[INFO] Extracted {extracted_frames_count} frames from {video_filename}")
|
| 333 |
|
| 334 |
-
|
| 335 |
-
cursor_output_json = os.path.join(CURSOR_TRACKING_OUTPUT_FOLDER, f"{course_name}_{video_filename.replace('.', '_')}_cursor_data.json")
|
| 336 |
-
tracked_cursors = track_cursor(frames_output_dir, CURSOR_TEMPLATES_DIR, cursor_output_json, threshold=CURSOR_THRESHOLD)
|
| 337 |
-
processing_status["tracked_cursors_count"] += tracked_cursors
|
| 338 |
-
log_message(f"[INFO] Tracked {tracked_cursors} cursors in frames from {video_filename}")
|
| 339 |
else:
|
| 340 |
log_message(f"[WARN] No frames extracted from {video_filename}")
|
| 341 |
|
|
@@ -425,12 +406,7 @@ def main_processing_loop(start_index: int = 0):
|
|
| 425 |
next_index += 1
|
| 426 |
save_json_state(DOWNLOAD_STATE_FILE, {"next_download_index": next_index})
|
| 427 |
|
| 428 |
-
# Status update
|
| 429 |
-
log_message(f"π Progress: {next_index}/{len(rar_files)} files processed")
|
| 430 |
-
log_message(f'π Extracted: {processing_status["extracted_courses"]} courses')
|
| 431 |
-
log_message(f'π Videos Processed: {processing_status["extracted_videos"]}')
|
| 432 |
-
log_message(f'π Frames Extracted: {processing_status["extracted_frames_count"]}')
|
| 433 |
-
|
| 434 |
if next_index < len(rar_files):
|
| 435 |
log_message(f"π Run the script again to process the next file: {os.path.basename(rar_files[next_index])}")
|
| 436 |
else:
|
|
@@ -439,7 +415,7 @@ def main_processing_loop(start_index: int = 0):
|
|
| 439 |
log_message("β
All files have been processed!")
|
| 440 |
|
| 441 |
log_message("π Processing complete!")
|
| 442 |
-
log_message(f'π Final stats: {processing_status["extracted_courses"]} courses extracted, {processing_status["extracted_videos"]} videos processed, {processing_status["extracted_frames_count"]} frames extracted
|
| 443 |
|
| 444 |
except KeyboardInterrupt:
|
| 445 |
log_message("βΉοΈ Processing interrupted by user")
|
|
@@ -460,5 +436,3 @@ __all__ = [
|
|
| 460 |
]
|
| 461 |
|
| 462 |
|
| 463 |
-
|
| 464 |
-
|
|
|
|
| 43 |
DEFAULT_FPS = 3 # Default frames per second for extraction
|
| 44 |
|
| 45 |
# Cursor Tracking Parameters
|
| 46 |
+
|
| 47 |
|
| 48 |
# Initialize HF API
|
| 49 |
hf_api = HfApi(token=HF_TOKEN)
|
|
|
|
| 57 |
"failed_files": 0,
|
| 58 |
"extracted_courses": 0,
|
| 59 |
"extracted_videos": 0,
|
| 60 |
+
: 0,
|
|
|
|
| 61 |
"last_update": None,
|
| 62 |
"logs": []
|
| 63 |
}
|
|
|
|
| 262 |
log_message(f"Extracted {saved_idx-1} frames from {video_path} to {output_dir}")
|
| 263 |
return saved_idx - 1
|
| 264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
|
| 268 |
|
|
|
|
| 316 |
processing_status["extracted_videos"] += 1
|
| 317 |
log_message(f"[INFO] Extracted {extracted_frames_count} frames from {video_filename}")
|
| 318 |
|
| 319 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
else:
|
| 321 |
log_message(f"[WARN] No frames extracted from {video_filename}")
|
| 322 |
|
|
|
|
| 406 |
next_index += 1
|
| 407 |
save_json_state(DOWNLOAD_STATE_FILE, {"next_download_index": next_index})
|
| 408 |
|
| 409 |
+
# Status update log_message(f"π Frames Extracted: {processing_status["extracted_frames_count"]}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
if next_index < len(rar_files):
|
| 411 |
log_message(f"π Run the script again to process the next file: {os.path.basename(rar_files[next_index])}")
|
| 412 |
else:
|
|
|
|
| 415 |
log_message("β
All files have been processed!")
|
| 416 |
|
| 417 |
log_message("π Processing complete!")
|
| 418 |
+
log_message(f'π Final stats: {processing_status["extracted_courses"]} courses extracted, {processing_status["extracted_videos"]} videos processed, {processing_status["extracted_frames_count"]} frames extracted')
|
| 419 |
|
| 420 |
except KeyboardInterrupt:
|
| 421 |
log_message("βΉοΈ Processing interrupted by user")
|
|
|
|
| 436 |
]
|
| 437 |
|
| 438 |
|
|
|
|
|
|