title: How to send OpenCV video footage over ZeroMQ sockets?
body: <p>I've got a simple webcam which I read out using OpenCV and I'm now trying to send this video footage to a different (Python) program using <a href="http://zeromq.org/" rel="noreferrer">ZeroMQ</a>. So I've got the following simple script to read out the webcam and send it using a ZeroMQ socket:</p>
  
  <pre><code>import cv2
  import os
  import zmq
  import base64
  
  context = zmq.Context()
  footage_socket = context.socket(zmq.PUB)
  footage_socket.connect('tcp://localhost:5555')
  
  # init the camera
  camera = cv2.VideoCapture(0)
  
  while True:
      try:
          (grabbed, frame) = camera.read()            # grab the current frame
          frame = cv2.resize(frame, (640, 480))       # resize the frame
          footage_socket.send_string(base64.b64encode(frame))
  
          # Show the video in a window
          cv2.imshow("Frame", frame)                  # show the frame to our screen
          cv2.waitKey(1)                              # Display it at least one ms
          #                                           # before going to the next frame
  
      except KeyboardInterrupt:
          camera.release()
          cv2.destroyAllWindows()
          print "\n\nBye bye\n"
          break
  </code></pre>
  
  <p>This works well in that it shows the video and doesn't give any errors. </p>
  
  <p>I commented out the two lines which show the image (<code>cv2.imshow()</code> and <code>cv2.waitKey(1)</code>). I then started the script below in paralel. This second script should receive the video footage and show it.</p>
  
  <pre><code>import cv2
  import zmq
  import base64
  import numpy as np
  
  context = zmq.Context()
  footage_socket = context.socket(zmq.SUB)
  footage_socket.bind('tcp://*:5555')
  footage_socket.setsockopt_string(zmq.SUBSCRIBE, unicode(''))
  
  # camera = cv2.VideoCapture("output.avi")
  
  while True:
      try:
          frame = footage_socket.recv_string()
          frame = np.fromstring(base64.b64decode(frame), dtype=np.uint8)
          cv2.imshow("Frame", frame)                  # show the frame to our screen
          cv2.waitKey(1)                              # Display it at least one ms
          #                                           # before going to the next frame
      except KeyboardInterrupt:
          cv2.destroyAllWindows()
          break
  
  print "\n\nBye bye\n"
  </code></pre>
  
  <p>Unfortunately, this freezes on <code>cv2.waitKey(1)</code>. </p>
  
  <p>Does anybody know what I'm doing wrong here? Do I need to decode the footage differently? All tips are welcome!</p>