-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmission_pad.py
More file actions
62 lines (50 loc) · 1.83 KB
/
mission_pad.py
File metadata and controls
62 lines (50 loc) · 1.83 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
from djitellopy import Tello
import cv2
import pygame
from pygame.locals import *
import numpy as np
import time
class missions(object):
def __init__(self):
pygame.init()
pygame.display.set_caption("Tello Feed")
self.screen = pygame.display.set_mode([960, 720])
self.tello = Tello()
def run(self):
if not self.tello.connect():
print("Tello not connected")
return
if not self.tello.streamon():
print("Could not start video stream")
return
frame_read = self.tello.get_frame_read()
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
face_cascade = cv2.CascadeClassifier(
'haarcascade_frontalface_default.xml')
while True:
self.screen.fill([0, 0, 0])
frame = cv2.cvtColor(frame_read.frame, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(frame_read.frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y),
(x+w, y+h), (255, 0, 0), 2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = frame[y:y + h, x:x + w]
eyes = eye_cascade.detectMultiScale(roi_gray)
for (ex, ey, ew, eh) in eyes:
cv2.rectangle(roi_color, (ex, ey),
(ex+ew, ey+eh), (0, 255, 0), 2)
frame = np.rot90(frame)
frame = np.flipud(frame)
frame = pygame.surfarray.make_surface(frame)
self.screen.blit(frame, (0, 0))
pygame.display.update()
time.sleep(1 / 60)
self.tello.end()
def main():
frontend = missions()
frontend.run()
if __name__ == "__main__":
main()
pass