-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrial_.py
More file actions
61 lines (49 loc) · 1.64 KB
/
Copy pathtrial_.py
File metadata and controls
61 lines (49 loc) · 1.64 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import cv2
import mediapipe as mp
import numpy as np
import os
# Initialize Mediapipe Pose
mpPose = mp.solutions.pose
pose = mpPose.Pose()
mpDraw = mp.solutions.drawing_utils
cap = cv2.VideoCapture(0)
landmark_list = [] # Use a list to store landmark values
fileIndex = 0
subFolderIndex = 0
flag = 0
folder_path = "Trainingdata/Running"
folder_name = str(subFolderIndex) # Initialize folder_name
while True:
success, img = cap.read()
if not success:
break
imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
results = pose.process(imgRGB)
if results.pose_landmarks:
mpDraw.draw_landmarks(img, results.pose_landmarks, mpPose.POSE_CONNECTIONS)
landmark_values = [] # Store landmark values for this frame
for lm in results.pose_landmarks.landmark:
landmark_values.extend([lm.x, lm.y, lm.z])
landmark_list.append(landmark_values)
if flag == 1:
# Save the list of landmark values as a numpy array
array = np.array(landmark_list)
file_name = f"{folder_path}/{folder_name}/{fileIndex}.npy"
np.save(file_name, array)
fileIndex += 1
cv2.imshow("LOL", img)
key = cv2.waitKey(1)
if key == ord("k"):
flag = 1
fileIndex = 0
subFolderIndex += 1
folder_name = str(subFolderIndex) # Update folder_name
folder_path = "Trainingdata/Walking" # Update folder_path
if not os.path.exists(os.path.join(folder_path, folder_name)):
os.makedirs(os.path.join(folder_path, folder_name))
if key == ord("l"):
flag = 0
if key == ord("q"):
break
cv2.destroyAllWindows()
cap.release()