-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
88 lines (65 loc) · 2.31 KB
/
app.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Preparing Dataset for Pose Estimation
import mediapipe as mp
import cv2
import time
import numpy as np
import pandas as pd
import os
mpPose = mp.solutions.pose
pose = mpPose.Pose()
mpDraw = mp.solutions.drawing_utils # For drawing keypoints
points = mpPose.PoseLandmark # Landmarks
path = "DATASET/TRAIN/plank" # enter dataset path
data = []
for p in points:
x = str(p)[13:]
data.append(x + "_x")
data.append(x + "_y")
data.append(x + "_z")
data.append(x + "_vis")
data = pd.DataFrame(columns = data) # Empty dataset
count = 0
for img in os.listdir(path):
temp = []
img = cv2.imread(path + "/" + img)
imageWidth, imageHeight = img.shape[:2]
imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
blackie = np.zeros(img.shape) # Blank image
results = pose.process(imgRGB)
if results.pose_landmarks:
# mpDraw.draw_landmarks(img, results.pose_landmarks, mpPose.POSE_CONNECTIONS) #draw landmarks on image
mpDraw.draw_landmarks(blackie, results.pose_landmarks, mpPose.POSE_CONNECTIONS) # draw landmarks on blackie
landmarks = results.pose_landmarks.landmark
for i,j in zip(points,landmarks):
temp = temp + [j.x, j.y, j.z, j.visibility]
data.loc[count] = temp
count +=1
cv2.imshow("Image", img)
cv2.imshow("blackie",blackie)
cv2.waitKey(100)
data.to_csv("dataset3.csv") # save the data as a csv file
# Creating the Pose Estimation model
from sklearn.svm import SVC
data = pd.read_csv("dataset3.csv")
X,Y = data.iloc[:,:132],data['target']
model = SVC(kernel = 'poly')
model.fit(X,Y)
mpPose = mp.solutions.pose
pose = mpPose.Pose()
mpDraw = mp.solutions.drawing_utils
path = "enter image path"
img = cv2.imread(path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
results = pose.process(imgRGB)
if results.pose_landmarks:
landmarks = results.pose_landmarks.landmark
for j in landmarks:
temp = temp + [j.x, j.y, j.z, j.visibility]
y = model.predict([temp])
if y == 0:
asan = "plank"
else:
asan = "goddess"
print(asan)
cv2.putText(img, asan, (50,50), cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,0),3)
cv2.imshow("image",img)