forked from Johnny-Q/htn_2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
47 lines (41 loc) · 1.45 KB
/
controller.py
File metadata and controls
47 lines (41 loc) · 1.45 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
import mediapipe as mp
import cv2
class Controller:
def __init__(self):
self.mp_drawing = mp.solutions.drawing_utils
self.mp_pose = mp.solutions.pose
self.mp_holistic = mp.solutions.holistic
self.cap = cv2.VideoCapture(0)
self.pose = self.mp_pose.Pose(min_detection_confidence=0.5,
min_tracking_confidence=0.5)
def formatImage(self, image):
image = cv2.flip(image, 1)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image.flags.writeable = False
return image
def classifyPose(self, results):
def getJoint(joint_name):
return results.pose_landmarks.landmark[self.mp_pose.PoseLandmark[joint_name]]
if(getJoint("NOSE").y < 0.1):
print("jump")
return -1
elif(getJoint("NOSE").y > 0.7):
print("duck")
return -2
if(getJoint("LEFT_HIP").x < 0.4):
print("left")
return 0
elif(getJoint("LEFT_HIP").x < 0.7):
print("middle")
return 1
else:
print("right")
return 2
return 1
def renderFeedback(self, image, results):
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
self.mp_drawing.draw_landmarks(
image, results.pose_landmarks, self.mp_pose.POSE_CONNECTIONS)
cv2.imshow('camera', image)
cv2.waitKey(3)