Getting list of pixel values from PIL

前端 未结 9 1184
感动是毒
感动是毒 2020-11-27 15:07

Guys, I\'m looking for a bit of assistance. I\'m a newbie programmer and one of the problems I\'m having at the minute is trying to convert a black & white .jpg

9条回答
  •  时光说笑
    2020-11-27 15:56

    data = numpy.asarray(im)
    

    Notice:In PIL, img is RGBA. In cv2, img is BGRA.

    My robust solution:

    def cv_from_pil_img(pil_img):
        assert pil_img.mode=="RGBA"
        return cv2.cvtColor(np.array(pil_img), cv2.COLOR_RGBA2BGRA)
    

提交回复
热议问题