title: BytesIO stream to Numpy arrays? (Picamera)
body: <p>I'm using Picamera with the Raspberry Pi to take pictures and then analyze the differences between them. I'm using the following code to capture to a BytesIO stream and then read that into a Numpy array (borrowed from <a href="http://picamera.readthedocs.org/en/release-1.6/recipes1.html#capturing-to-an-opencv-object" rel="nofollow">this guide</a>):</p>
  
  <pre><code>stream = io.BytesIO()
  with picamera.PiCamera() as camera:
      camera.resolution = (100, 60)
      camera.framerate = 30
      while not done:
          camera.capture(stream, format='jpeg', use_video_port=True)
          if previousData == None:
              previousData = cv2.imdecode(np.fromstring(stream.getvalue(), dtype=np.uint8), 1)
              previousData = previousData[:, :, ::-1]
          else:
              timeStartNumpy = time.time()
              currentData = cv2.imdecode(np.fromstring(stream.getvalue(), dtype=np.uint8), 1)
              currentData = previousData[:, :, ::-1]
              ....(omitted analysis code)....
              previousData = currentData
  </code></pre>
  
  <p>The analysis code works as it should, except it keeps using the same frame repeatedly. I'm assuming that must be a problem with the way I'm reading from the stream, but I'm not experienced enough in Python to know how to change it. Any tips or help would be appreciated.</p>