title: Python OpenCV: Returning cvBridge Image from ROS
body: <p>I recently just started OpenCv so apologies for any dumb questions.</p>
  
  <p>So my ultimate aim is to stream video from my ZED camera on to a VR headset &amp; I've not had any luck in Unity or UnReal as relevant plugins fail to work on my Linux machine. I need to be able to isolate the dual cameras from my ZED device but right now only ROS allows me to access the individual topics of either cam.</p>
  
  <p>So I used a ZED wrapper to publish image data on to a ROS node and found code to interact with ROS messages from <a href="http://wiki.ros.org/cv_bridge/Tutorials/ConvertingBetweenROSImagesAndOpenCVImagesPython" rel="nofollow noreferrer">here</a>.</p>
  
  <p>The code works perfectly and I am able to display a stream of images captured on my monitor.  But my issue is how do I basically save these images into a buffer/queue?</p>
  
  <p>I modified the example to code to try to return the images converted by cvBridge but I'm not having any luck getting the returned image to show on screen.  Think it may be because Image is initialised to <code>None</code> at first and so <code>cv2</code>.<code>imshow()</code> cannot display an empty picture.  But how do I check if the rest of the images are being returned correctly? Here is my code:</p>
  
  <pre><code>import cv2
  import rospy
  
  from sensor_msgs.msg import Image
  from cv_bridge import CvBridge, CvBridgeError
  from Queue import Queue
  
  
  class ImageConverter(object):
  
      def __init__(self, object):
  
          self.topic=object
          self.bridge= CvBridge()
          self.image_queue = Queue(maxsize=100)
          self.image_sub = rospy.Subscriber(self.topic, Image, self.callback, queue_size=100)
          self.image=None
  
      def callback(self, data):
  
          try:
              cv_image=self.bridge.imgmsg_to_cv2(data, "bgr8")
          except CvBridgeError as e:
              print(e)
          else:
                  self.image = cv_image
                  self.image_queue.put(cv_image)
  
  def get_image(self):
  
          try:
                  image = self.image_queue.get(block=False)
          except:
                  image = self.image
  
          cv2.imshow("Image window", image)
          cv2.waitKey(3)
  
  def subscribe(position):
  
      ic= ImageConverter(position)
      ic.get_image()
      rospy.init_node('image_converter', anonymous=True)
  
      try:
          rospy.spin()
      except KeyboardInterrupt:
          print ("goodbye")
      cv2.destroyAllWindows()
  </code></pre>
  
  <p>I have had such a difficult time trying to figure out how to do this all so any help would be very much appreciated.  Thanks!</p>