-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmini_openpose_python.py
More file actions
111 lines (93 loc) · 3.58 KB
/
mini_openpose_python.py
File metadata and controls
111 lines (93 loc) · 3.58 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
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
import sys
import cv2
import os
from sys import platform
from djitellopy import Tello
import time
from OP import OP, Params, Movs
from datetime import date
#---------------------------------- Importando OpenPose -----------------------------------------#
dir_path = 'D:/Escritorio/Dron/openpose/build/examples/tutorial_api_python' # os.path.dirname(os.path.realpath(__file__))
try:
# Windows Import
if platform == "win32":
# Change these variables to point to the correct folder (Release/x64 etc.)
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:
# Change these variables to point to the correct folder (Release/x64 etc.)
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
#----------------------------------------------------------------------#
Drone = False
# ------------------------------ Main ----------------------------------#
def main():
if Drone:
dron = Tello()
dron.connect()
dron.for_back_velocity = 0
dron.left_right_velocity = 0
dron.up_down_velocity = 0
dron.yaw_velocity = 0
dron.speed = 0
print(dron.get_battery())
dron.streamoff()
dron.streamon()
#dron.takeoff()
else:
stream = cv2.VideoCapture(0)
dron = None
params = Params(dir_path).set_params()
print(type(params))
movs = Movs(stream, dron, Drone)
movements = movs.get_movs()
print(type(movements))
#Constructing OpenPose object allocates GPU memory
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()
font = cv2.FONT_HERSHEY_SIMPLEX
counter = -1
while True:
counter += 1
print('frame procesed: ',counter)
if Drone:
leer_frame = dron.get_frame_read()
img = leer_frame.frame
else:
ret,img = stream.read()
print('imagen obtenida')
img = cv2.resize(img, (320, 240))
print('imagen rescalada')
datum = op.Datum()
datum.cvInputData = img #imageToProcess
print('imagen preparada')
opWrapper.emplaceAndPop(op.VectorDatum([datum]))
print('imagen analizada')
object = OP(datumin=datum)
pose = object.check_pose()
print(pose)
if pose:
movements[pose]
else:
print('No pose idetified!')
# Display the stream
cv2.putText(datum.cvOutputData,'OpenPose using Python-OpenCV',(20,30), font, 1,(255,255,255),1,cv2.LINE_AA)
cv2.imshow('Human Pose Estimation',datum.cvOutputData)
print('imagen mostrada')
time.sleep(1)
print('tiempo de espera termiando')
key = cv2.waitKey(1)
if key==ord('q'):
break
if Drone:
dron.land()
else:
stream.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()