-
Notifications
You must be signed in to change notification settings - Fork 8
/
video_effect.py
55 lines (47 loc) · 1.54 KB
/
video_effect.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
import sys
import traceback
import tellopy
import av
import cv2 as cv2 # for avoidance of pylint error
import numpy
import time
def main():
drone = tellopy.Tello()
try:
drone.connect()
drone.wait_for_connection(60.0)
retry = 3
container = None
while container is None and 0 < retry:
retry -= 1
try:
container = av.open(drone.get_video_stream())
except av.AVError as ave:
print(ave)
print('retry...')
# skip first 300 frames
frame_skip = 300
while True:
for frame in container.decode(video=0):
if 0 < frame_skip:
frame_skip = frame_skip - 1
continue
start_time = time.time()
image = cv2.cvtColor(numpy.array(frame.to_image()), cv2.COLOR_RGB2BGR)
cv2.imshow('Original', image)
cv2.imshow('Canny', cv2.Canny(image, 100, 200))
cv2.waitKey(1)
if frame.time_base < 1.0/60:
time_base = 1.0/60
else:
time_base = frame.time_base
frame_skip = int((time.time() - start_time)/time_base)
except Exception as ex:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback)
print(ex)
finally:
drone.quit()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()