-
Notifications
You must be signed in to change notification settings - Fork 3
/
3. Tello_hand_gesture_control.py
65 lines (56 loc) · 2.29 KB
/
3. Tello_hand_gesture_control.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
import cv2
import mediapipe as mp
from djitellopy import Tello
from utils.HandTrackingModule import HandDetector
from utils.FaceDetectionModule import FaceDetector
detectorH = HandDetector(maxHands=2, detectionCon=0.8)
detectorF = FaceDetector(minDetectionCon=0.5, modelSelection=1)
# cap = cv2.VideoCapture(0)
gesture = ''
tello = Tello()
tello.connect()
print(tello.get_battery())
tello.streamon()
# tello.takeoff()
# tello.move_up(80)
while True:
# _, img = cap.read()
img = tello.get_frame_read().frame
img = detectorH.findHands(img)
lmList, bbox = detectorH.findPosition(img)
img, bboxsFace = detectorF.findFaces(img)
if bboxsFace:
x, y, w, h = bboxsFace[0]['bbox']
detectRegion = x - 175 - 25, y - 75, 175, h + 75
cv2.rectangle(img, detectRegion, (0, 0, 255), 2)
if bbox and detectorH.handType() == 'Right':
cx, cy = bbox['center']
if detectRegion[0] < cx < detectRegion[0] + detectRegion[2] and \
detectRegion[1] < cy < detectRegion[1] + detectRegion[3]:
cv2.rectangle(img, detectRegion, (0, 255, 0), 2)
fingers = detectorH .fingersUp()
if fingers == [1, 1, 1, 1, 1]:
gesture = 'Open hand'
elif fingers == [0, 1, 0, 0, 0]:
gesture = 'Up'
tello.move_up(40)
elif fingers == [0, 1, 1, 0, 0]:
gesture = 'Victory'
tello.move_down(40)
elif fingers == [0, 1, 0, 0, 1]:
gesture = 'Spider Man'
tello.flip_left()
elif fingers == [0, 0, 0, 0, 0]:
gesture = 'Stop'
elif fingers == [0, 0, 0, 0, 1]:
gesture = 'Left'
tello.move_left(20)
elif fingers == [1, 0, 0, 0, 0]:
gesture = 'Right'
tello.move_right(20)
cv2.putText(img, f'{gesture}'.upper(), (detectRegion[0] + 15, detectRegion[1] + detectRegion[3] + 50), cv2.FONT_HERSHEY_PLAIN, 2, (0,255,0), 2)
cv2.imshow('window', img)
if cv2.waitKey(1) & 0xFF == ord('q'):
tello.land()
break
cv2.destroyAllWindows()