title: Trying to stream in video into opencv from http address
body: <p>I'm relatively new to this, but here's what I'm trying to do. I have a raspberry zero connected to a raspberry pi camera, and I'm streaming this video from from the raspberry pi wirelessly via uv4l. I use this command:</p>
  
  <p>sudo uv4l -f -k --sched-fifo --mem-lock  --driver raspicam --auto-video_nr --encoding h264 --width 1080 --height 720 --enable-server on</p>
  
  <p>I'm able to access this stream on a web browser by looking at the pi's ip address. Now what I'd like to do is to be able to view the video stream in opencv. This is what I've read works, however I am running into the following error:</p>
  
  <pre><code>Streaming http://192.168.1.84:8080/stream
  Traceback (most recent call last):
    File "videoStream.py", line 17, in &lt;module&gt;
      bytes+=stream.read('1024')
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 448, in read
      b = bytearray(amt)
  TypeError: string argument without an encoding
  </code></pre>
  
  <p>Here is my code. Note I'm running python 3.5 and opencv 3:</p>
  
  <pre><code>import cv2
  import urllib.request
  import numpy as np
  import sys
  
  host = "192.168.1.84:8080"
  if len(sys.argv)&gt;1:
      host = sys.argv[1]
  
  hoststr = 'http://' + host + '/stream'
  print('Streaming ' + hoststr)
  
  stream=urllib.request.urlopen(hoststr)
  
  bytes=''
  while True:
      bytes+=stream.read('1024')
      a = bytes.find('\xff\xd8')
      b = bytes.find('\xff\xd9')
      if a!=-1 and b!=-1:
          jpg = bytes[a:b+2]
          bytes= bytes[b+2:]
          i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.CV_LOAD_IMAGE_COLOR)
          cv2.imshow(hoststr,i)
          if cv2.waitKey(1) ==27:
              exit(0)
  </code></pre>
  
  <p>I'm not sure how to resolve this issue, or if there's perhaps a better approach to viewing this video stream in opencv.</p>