|
a |
|
b/internal/labeling_script.py |
|
|
1 |
import cv2 |
|
|
2 |
import pandas as pd |
|
|
3 |
import numpy as np |
|
|
4 |
dataset = pd.read_csv('assets/extracted_landmarks_test.csv') |
|
|
5 |
|
|
|
6 |
def is_float(num): |
|
|
7 |
try: |
|
|
8 |
float(num) |
|
|
9 |
return True |
|
|
10 |
except ValueError: |
|
|
11 |
return False |
|
|
12 |
|
|
|
13 |
dataset['landmarks'] = dataset['landmarks'].apply(lambda arr: np.array([float(n) for n in arr.split() if is_float(n)])) |
|
|
14 |
|
|
|
15 |
video_dir = 'assets/dataset_videos/batch_test' # Directory where your video files are stored |
|
|
16 |
|
|
|
17 |
dataset['Label'] = None |
|
|
18 |
for index, row in dataset.iterrows(): |
|
|
19 |
video = row['video'] |
|
|
20 |
frame = row['frame'] |
|
|
21 |
|
|
|
22 |
# Construct the path to the video file |
|
|
23 |
video_path = video_dir + video # Update the file extension if necessary |
|
|
24 |
|
|
|
25 |
# Open the video file |
|
|
26 |
cap = cv2.VideoCapture(video_path) |
|
|
27 |
|
|
|
28 |
# Get the frames per second (FPS) of the video |
|
|
29 |
fps = cap.get(cv2.CAP_PROP_FPS) |
|
|
30 |
|
|
|
31 |
print(f"{video} at group {row['group']}. Frame {frame}") |
|
|
32 |
# Read and discard frames until the desired frame index |
|
|
33 |
cap.set(cv2.CAP_PROP_POS_FRAMES, frame) |
|
|
34 |
|
|
|
35 |
# Display ~10 frames |
|
|
36 |
for _ in range(10): |
|
|
37 |
ret, frame = cap.read() |
|
|
38 |
if ret: |
|
|
39 |
cv2.imshow('Video', frame) |
|
|
40 |
|
|
|
41 |
# Ask for user input |
|
|
42 |
key = cv2.waitKey(0) & 0xFF |
|
|
43 |
if key == ord('g'): |
|
|
44 |
dataset.at[index, 'Label'] = 'good' # Update 'Label' to 'good' in the corresponding row |
|
|
45 |
print("Label set to 'good'") |
|
|
46 |
elif key == ord('b'): |
|
|
47 |
dataset.at[index, 'Label'] = 'bad' # Update 'Label' to 'bad' in the corresponding row |
|
|
48 |
print("Label set to 'bad'") |
|
|
49 |
|
|
|
50 |
# Release the video capture |
|
|
51 |
cap.release() |
|
|
52 |
|
|
|
53 |
# Close the video display window |
|
|
54 |
cv2.destroyAllWindows() |
|
|
55 |
|
|
|
56 |
dataset.to_csv('assets/labeled_dataset_test.csv', index=False) |
|
|
57 |
print(dataset.head()) |