-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbodytests.py
184 lines (148 loc) · 5.19 KB
/
bodytests.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import sys
import cv2
import os
from sys import platform
import argparse
import numpy as np
import pyautogui
from popup import PopUp
dir_path = os.path.dirname(os.path.realpath(__file__))
try:
if platform == "win32":
sys.path.append(dir_path + '/../../python/openpose/Release');
os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../bin;'
import pyopenpose as op
else:
sys.path.append('../../python');
from openpose import pyopenpose as op
except ImportError as e:
print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
raise e
# Flags
parser = argparse.ArgumentParser()
args = parser.parse_known_args()
# Custom Params
params = dict()
params["disable_multi_thread"] = False
# params["camera_resolution"] = "-1x-1"
params["model_folder"] = "./models/"
# params["output_resolution"] = "-1x-1"
params["net_resolution"] = "128x128"
params["number_people_max"] = 1
# Add others in path
for i in range(0, len(args[1])):
curr_item = args[1][i]
if i != len(args[1])-1: next_item = args[1][i+1]
else: next_item = "1"
if "--" in curr_item and "--" in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = "1"
elif "--" in curr_item and "--" not in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = next_item
# Starting OpenPose
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()
def dist(p1,p2):
return abs(datum.poseKeypoints[0][p1][0]-datum.poseKeypoints[0][p2][0])
# Process Image
datum = op.Datum()
cap = cv2.VideoCapture(0)
mode=1
flag=flag2=flag3=flag4=flag5=1
n=0
def changemode(m):
if(m==1):
return 2
elif(m==2):
return 3
elif(m==3):
return 1
while True:
blank,imageToProcess=cap.read()
imageToProcess = cv2.flip(imageToProcess,1)
height,width = imageToProcess.shape[:2]
datum.cvInputData = imageToProcess
opWrapper.emplaceAndPop([datum])
# Display Image Points
# print("Body keypoints: \n" + str(datum.poseKeypoints))
try:
if(mode==1):
# scroll content
if(datum.poseKeypoints[0][4][1]==0):
pass
else:
pyautogui.scroll(-(datum.poseKeypoints[0][4][1]-datum.poseKeypoints[0][2][1])/80)
# change tabs
if(datum.poseKeypoints[0][6][0]-datum.poseKeypoints[0][7][0]>100 and datum.poseKeypoints[0][7][0]!=0):
if(flag2==1):
flag2=0
pyautogui.hotkey('ctrl','pageup')
elif(datum.poseKeypoints[0][6][0]-datum.poseKeypoints[0][7][0]<-60 and datum.poseKeypoints[0][7][0]!=0):
if(flag2==1):
flag2=0
pyautogui.hotkey('ctrl','pagedown')
elif(datum.poseKeypoints[0][6][0]-datum.poseKeypoints[0][7][0]>-40 and datum.poseKeypoints[0][6][0]-datum.poseKeypoints[0][7][0]<40):
flag2=1
elif(mode==2):
# print("YT MODE")
# move 10 secs
if(datum.poseKeypoints[0][6][0]-datum.poseKeypoints[0][7][0]>100 and datum.poseKeypoints[0][7][0]!=0):
if(flag3==1):
flag3=0
pyautogui.press('j')
elif(datum.poseKeypoints[0][6][0]-datum.poseKeypoints[0][7][0]<-60 and datum.poseKeypoints[0][7][0]!=0):
if(flag3==1):
flag3=0
pyautogui.press('l')
elif(datum.poseKeypoints[0][6][0]-datum.poseKeypoints[0][7][0]>-40 and datum.poseKeypoints[0][6][0]-datum.poseKeypoints[0][7][0]<40):
flag3=1
# play and full screen
if(datum.poseKeypoints[0][4][1]-datum.poseKeypoints[0][4][1]>100 and datum.poseKeypoints[0][4][1]!=0):
if(flag4==1):
flag4=0
pyautogui.press('k')
elif(datum.poseKeypoints[0][2][1]-datum.poseKeypoints[0][4][1]<-60 and datum.poseKeypoints[0][4][1]!=0):
if(flag4==1):
flag4=0
pyautogui.press('f')
elif(datum.poseKeypoints[0][2][1]-datum.poseKeypoints[0][4][1]>-40 and datum.poseKeypoints[0][2][1]-datum.poseKeypoints[0][4][1]<40):
flag4=1
elif(mode==3):
# print("YT MODE 2")
# volume control
if(datum.poseKeypoints[0][6][1]-datum.poseKeypoints[0][7][1]>100 and datum.poseKeypoints[0][7][1]!=0):
if(flag5==1):
flag5=0
pyautogui.press('up')
elif(datum.poseKeypoints[0][6][1]-datum.poseKeypoints[0][7][1]<-60 and datum.poseKeypoints[0][7][1]!=0):
if(flag5==1):
flag5=0
pyautogui.press('down')
elif(datum.poseKeypoints[0][6][1]-datum.poseKeypoints[0][7][1]>-40 and datum.poseKeypoints[0][6][1]-datum.poseKeypoints[0][7][1]<40):
flag5=1
# video playlist control
if(datum.poseKeypoints[0][2][0]-datum.poseKeypoints[0][4][0]>100 and datum.poseKeypoints[0][4][0]!=0):
if(flag==1):
flag=0
pyautogui.hotkey('shift','p')
elif(datum.poseKeypoints[0][2][0]-datum.poseKeypoints[0][4][0]<-60 and datum.poseKeypoints[0][4][0]!=0):
if(flag==1):
flag=0
pyautogui.hotkey('shift','n')
elif(datum.poseKeypoints[0][2][0]-datum.poseKeypoints[0][4][0]>-40 and datum.poseKeypoints[0][2][0]-datum.poseKeypoints[0][4][0]<40):
flag=1
# elif(mode==4):
# print("mODE 4")
if(n>=1):
n-=1
# print (n)
elif((datum.poseKeypoints[0][4][1]!=0 and n==0) and ((abs(datum.poseKeypoints[0][4][0]-datum.poseKeypoints[0][7][0]) + abs(datum.poseKeypoints[0][4][0]-datum.poseKeypoints[0][7][0])) <180)):
n=20
mode=changemode(mode)
PopUp(mode-1);
except:
pass
cv2.imshow("window", datum.cvOutputData)
cv2.waitKey(1)