test_h264_sub.py
Go to the documentation of this file.
1 #!/usr/bin/env python2
2 
3 import rospy
4 from sensor_msgs.msg import CompressedImage
5 import av
6 import cv2
7 import numpy
8 import threading
9 import traceback
10 
11 
12 class StandaloneVideoStream(object):
13  def __init__(self):
14  self.cond = threading.Condition()
15  self.queue = []
16  self.closed = False
17 
18  def read(self, size):
19  self.cond.acquire()
20  try:
21  if len(self.queue) == 0 and not self.closed:
22  self.cond.wait(2.0)
23  data = bytes()
24  while 0 < len(self.queue) and len(data) + len(self.queue[0]) < size:
25  data = data + self.queue[0]
26  del self.queue[0]
27  finally:
28  self.cond.release()
29  return data
30 
31  def seek(self, offset, whence):
32  return -1
33 
34  def close(self):
35  self.cond.acquire()
36  self.queue = []
37  self.closed = True
38  self.cond.notifyAll()
39  self.cond.release()
40 
41  def add_frame(self, buf):
42  self.cond.acquire()
43  self.queue.append(buf)
44  self.cond.notifyAll()
45  self.cond.release()
46 
47 
49 
50 
51 def callback(msg):
52  #rospy.loginfo('frame: %d bytes' % len(msg.data))
53  stream.add_frame(msg.data)
54 
55 
56 def main():
57  rospy.init_node('h264_listener')
58  rospy.Subscriber("/tello/image_raw/h264", CompressedImage, callback)
59  container = av.open(stream)
60  rospy.loginfo('main: opened')
61  for frame in container.decode(video=0):
62  image = cv2.cvtColor(numpy.array(
63  frame.to_image()), cv2.COLOR_RGB2BGR)
64  cv2.imshow('Frame', image)
65  cv2.waitKey(1)
66 
67 
68 if __name__ == '__main__':
69  try:
70  main()
71  except BaseException:
72  traceback.print_exc()
73  finally:
74  stream.close()
75  cv2.destroyAllWindows()
def seek(self, offset, whence)
def callback(msg)


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