title: Python OpenCV convert image to byte string?
body: <p>I'm working with PyOpenCV. How to convert cv2 image (numpy) to binary string for writing to MySQL db without a temporary file and <code>imwrite</code>?</p>
  
  <p>I googled it but found nothing...</p>
  
  <p>I'm trying <code>imencode</code>, but it doesn't work.</p>
  
  <pre><code>capture = cv2.VideoCapture(url.path)
  capture.set(cv2.cv.CV_CAP_PROP_POS_MSEC, float(url.query))
  self.wfile.write(cv2.imencode('png', capture.read()))
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>  File "server.py", line 16, in do_GET
    self.wfile.write(cv2.imencode('png', capture.read()))
    TypeError: img is not a numerical tuple
  </code></pre>
  
  <p>Help somebody!</p>