-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrunwalk.py
More file actions
72 lines (62 loc) · 2.15 KB
/
runwalk.py
File metadata and controls
72 lines (62 loc) · 2.15 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
62
63
64
65
66
67
68
69
70
71
72
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("still")
# Use a list to store landmark values
fileIndex = 0
subFolderIndex = 0
flag = 0
folder_path = "Trainingdata/Still"
folder_name = str(subFolderIndex) # Initialize folder_name
position = (50, 50) # (x, y) coordinates
# Define the font and other text properties
font = cv2.FONT_HERSHEY_SIMPLEX
font_scale = 1
font_color = (255, 0, 0) # BGR color (Blue, Green, Red)
font_thickness = 2
while True:
success, img = cap.read()
if not success:
break
landmark_list = []
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])
#improved
landmark_values.extend([lm.x, lm.y, lm.z, lm.visibility])
landmark_list.append(landmark_values)
#array = np.array(landmark_list).flatten()
if flag == 1:
# Save the list of landmark values as a numpy array
array = np.array(landmark_list).flatten()
file_name = f"{folder_path}/{folder_name}/{fileIndex}.npy"
array = array.flatten()
np.save(file_name, array)
fileIndex += 1
cv2.putText(img, str(subFolderIndex), position, font, font_scale, font_color, font_thickness)
cv2.imshow("LOL", img)
key = cv2.waitKey(1)
if key == ord("k"):
flag = 1
fileIndex = 0
folder_name = str(subFolderIndex) # Update folder_name
subFolderIndex += 1
folder_path = "Trainingdata/Still" # Update folder_path
if not os.path.exists(os.path.join(folder_path, folder_name)):
os.makedirs(os.path.join(folder_path, folder_name))
print(subFolderIndex)
if key == ord("m"):
flag = 0
if key == ord("q"):
break
cv2.destroyAllWindows()
cap.release()