-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdata_collection.py
54 lines (36 loc) · 1.22 KB
/
data_collection.py
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
import mediapipe as mp
import numpy as np
import cv2
def inFrame(lst):
if lst[28].visibility > 0.6 and lst[27].visibility > 0.6 and lst[15].visibility>0.6 and lst[16].visibility>0.6:
return True
return False
cap = cv2.VideoCapture(0)
name = input("Enter the name of the Asana : ")
holistic = mp.solutions.pose
holis = holistic.Pose()
drawing = mp.solutions.drawing_utils
X = []
data_size = 0
while True:
lst = []
_, frm = cap.read()
frm = cv2.flip(frm, 1)
res = holis.process(cv2.cvtColor(frm, cv2.COLOR_BGR2RGB))
if res.pose_landmarks and inFrame(res.pose_landmarks.landmark):
for i in res.pose_landmarks.landmark:
lst.append(i.x - res.pose_landmarks.landmark[0].x)
lst.append(i.y - res.pose_landmarks.landmark[0].y)
X.append(lst)
data_size = data_size+1
else:
cv2.putText(frm, "Make Sure Full body visible", (50,50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,255),2)
drawing.draw_landmarks(frm, res.pose_landmarks, holistic.POSE_CONNECTIONS)
cv2.putText(frm, str(data_size), (50,50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,0),2)
cv2.imshow("window", frm)
if cv2.waitKey(1) == 27 or data_size>80:
cv2.destroyAllWindows()
cap.release()
break
np.save(f"{name}.npy", np.array(X))
print(np.array(X).shape)