-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
65 lines (52 loc) · 1.58 KB
/
main.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
"""
Smart drone
"""
import cv2
from common.controller import TelloEngine
from common.drone import Drone
from common.fps import FPS
from common.info import InfoDisplayer
from webserver.manager import WebControlManager
frame_skip = 300
def skip_frame():
global frame_skip
total_frames = 0
skip_frames = 10
if 0 < frame_skip:
frame_skip = frame_skip - 1
return True
if total_frames % skip_frames != 0:
return True
return False
def main(mock_drone=True, enable_web=False, enable_socket=False, log_level=None):
"""
Main function
mock_drone = False will use your computer camera
enable_web = start a web server with streaming video and remote control
enable_socket = start a socket server to send the current drone position
"""
drone = Drone(mock_drone)
drone.start()
engine = TelloEngine(drone, log_level=log_level)
fps = FPS()
info = InfoDisplayer()
web_control = WebControlManager(enable_web, enable_socket, engine.pygame_screen)
web_control.start_http()
web_control.start_socket()
while True:
if skip_frame():
continue
engine.pygame_screen.watch_events()
frame = drone.get_frame()
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
frame = cv2.resize(frame, (640, 480))
frame = engine.process(frame)
engine.sound_player.play()
frame = info.display_info(engine, frame, fps)
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
web_control.send_frame(frame)
web_control.send_msg(str(engine.drone.drone_locator.x) + "-" + str(engine.drone.drone_locator.y))
cv2.imshow('My image', frame)
cv2.waitKey(1)
if __name__ == '__main__':
main(True, True, True, None)