Python OpenCV load image from byte string

前端 未结 3 1236
小鲜肉
小鲜肉 2020-12-01 01:55

I\'m trying to load image from string like as PHP function imagecreatefromstring

How can I do that?

I have MySQL blob field image. I\'m using

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 02:29

    I've try to use this code to create an opencv from a string containing a raw buffer (plain pixel data) and it doesn't work in that peculiar case.

    So here's how to do that for this kind of data:

    image = np.fromstring(im_str, np.uint8).reshape( h, w, nb_planes )
    

    (but yes you need to know your image properties)

    if your B and G channel is permuted, here's how to fix it:

    image = cv2.cvtColor(image, cv2.cv.CV_BGR2RGB)
    

提交回复
热议问题