title: Slow video stream with imdecode opencv using python
body: <p>I'm connecting to a IP-camera for object detection with OpenCV.The problem is that the videostream is superslow. When i comment this bit "rects = detect(gray, cascade)" the videostream is fluent.</p>
  
  <p>I read that it has to do with imdecode and converting the frames to gray per frame but I cant find a solution, how can I fix this problem?</p>
  
  <pre><code>bytes=""
  while True:
      '''authenticated connection to IP cam'''
      bytes+=stream.read(16384)
      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)
  
          '''Convert frames to gray to be able to detect objects'''
          gray = cv2.cvtColor(i, cv2.COLOR_BGR2GRAY)
          gray = cv2.equalizeHist(gray)
  
          '''Detect and draw whatever you specified in haarcascades'''
          rects = detect(gray, cascade)
          vis = i.copy()
          draw_rects(vis, rects, (0, 255, 0))
  
          '''Display the videostream'''
          cv2.imshow('authenticated cam',vis)
          if cv2.waitKey(1) ==27:
              exit(0)
  </code></pre>