title: PIL to OpenCV MAT causes color shift
body: <p>When loading a png image with PIL and OpenCV, there is a color shift. Black and white remain the same, but brown gets changed to blue.</p>
  
  <p>I can't post the image because this site does not allow newbies to post images.</p>
  
  <p>The code is written as below rather than use cv.LoadImageM, because in the real case the raw image is received over tcp.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>#! /usr/bin/env python
  import sys
  import cv
  import cv2
  import numpy as np
  import Image
  from cStringIO import StringIO
  
  if __name__ == "__main__":
      # load raw image from file
      f = open('frame_in.png', "rb")
      rawImage = f.read()
      f.close()
  
      #convert to mat
      pilImage = Image.open(StringIO(rawImage));
      npImage = np.array(pilImage)
      cvImage = cv.fromarray(npImage)
  
      #show it
      cv.NamedWindow('display')
      cv.MoveWindow('display', 10, 10)
      cv.ShowImage('display', cvImage)
      cv. WaitKey(0)
  
      cv.SaveImage('frame_out.png', cvImage)
  </code></pre>
  
  <p>How can the color shift be fixed?</p>