File size: 1,236 Bytes
c75ced2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import cv2
import json
import os
import sys
from .pose import PoseEstimator

def preprocess_video(video_path, output_json_path):
    cap = cv2.VideoCapture(video_path)
    if not cap.isOpened():
        print(f"Error: Could not open video {video_path}")
        return

    estimator = PoseEstimator(model_complexity=2) # Higher complexity for reference
    all_landmarks = []
    
    frame_count = 0
    while cap.isOpened():
        ret, frame = cap.read()
        if not ret:
            break
        
        results = estimator.process_frame(frame)
        landmarks = estimator.extract_landmarks(results)
        all_landmarks.append({
            "frame": frame_count,
            "landmarks": landmarks
        })
        
        frame_count += 1
        if frame_count % 30 == 0:
            print(f"Processed {frame_count} frames...")

    with open(output_json_path, 'w') as f:
        json.dump(all_landmarks, f)
    
    cap.release()
    estimator.close()
    print(f"Finished! Saved to {output_json_path}")

if __name__ == "__main__":
    if len(sys.argv) < 3:
        print("Usage: python -m src.core.preprocess_reference <video_path> <output_json_path>")
    else:
        preprocess_video(sys.argv[1], sys.argv[2])