-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAi_Trainer.py
59 lines (47 loc) · 1.56 KB
/
Ai_Trainer.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
import cv2
import numpy as np
import time
import PoseModule as pm
cap = cv2.VideoCapture("ai-trainer/1_1.mp4")
detector = pm.poseDetector()
count = 0
dir = 0
pTime =0
while True:
success, img = cap.read()
img = cv2.resize(img, (1280,720))
img = detector.findPose(img,False)
lmlist = detector.findPosition(img,False)
if len(lmlist) != 0:
# right arm
# lef arm
angle = detector.findAngle(img,11,13,15)
per = np.interp(angle,(194,320),(0,100))
bar = np.interp(angle,(194,310),(650,100))
#check for the dumbell curls
color = (255,0,255)
if per == 100:
color = (0,255,0)
if dir == 0:
count +=0.5
dir = 1
if per ==0:
color = (0,255,0)
if dir ==1:
count +=0.5
dir = 0
print(count)
# Draw bar
cv2.rectangle(img,(1100,100),(1175,650),color,3)
cv2.rectangle(img,(1100,int(bar)),(1175,650),color,cv2.FILLED)
cv2.putText(img, f'{int(per)}%',(1100,75),cv2.FONT_HERSHEY_PLAIN,4,color,4)
# Draw curls
cv2.rectangle(img,(0,450),(250,728),(0,255,0),cv2.FILLED)
cv2.putText(img, str(int(count)),(45,670),cv2.FONT_HERSHEY_PLAIN,15,(255,0,0),25)
cTime = time.time()
fps = 1/(cTime-pTime)
pTime = cTime
cv2.putText(img, str(int(fps)),(50,100),cv2.FONT_HERSHEY_PLAIN,5,(255,0,0),5)
#show the output
cv2.imshow("Image", img)
cv2.waitKey(1)