video_effect.py
Go to the documentation of this file.
1 import sys
2 import traceback
3 import tellopy
4 import av
5 import cv2.cv2 as cv2 # for avoidance of pylint error
6 import numpy
7 import time
8 
9 
10 def main():
11  drone = tellopy.Tello()
12 
13  try:
14  drone.connect()
15  drone.wait_for_connection(60.0)
16 
17  retry = 3
18  container = None
19  while container is None and 0 < retry:
20  retry -= 1
21  try:
22  container = av.open(drone.get_video_stream())
23  except av.AVError as ave:
24  print(ave)
25  print('retry...')
26 
27  # skip first 300 frames
28  frame_skip = 300
29  while True:
30  for frame in container.decode(video=0):
31  if 0 < frame_skip:
32  frame_skip = frame_skip - 1
33  continue
34  start_time = time.time()
35  image = cv2.cvtColor(numpy.array(frame.to_image()), cv2.COLOR_RGB2BGR)
36  cv2.imshow('Original', image)
37  cv2.imshow('Canny', cv2.Canny(image, 100, 200))
38  cv2.waitKey(1)
39  if frame.time_base < 1.0/60:
40  time_base = 1.0/60
41  else:
42  time_base = frame.time_base
43  frame_skip = int((time.time() - start_time)/time_base)
44 
45 
46  except Exception as ex:
47  exc_type, exc_value, exc_traceback = sys.exc_info()
48  traceback.print_exception(exc_type, exc_value, exc_traceback)
49  print(ex)
50  finally:
51  drone.quit()
52  cv2.destroyAllWindows()
53 
54 if __name__ == '__main__':
55  main()


tello_driver
Author(s): Jordy van Appeven
autogenerated on Wed May 13 2020 03:34:54