Python OpenCV convert image to byte string?

前端 未结 6 1792
礼貌的吻别
礼貌的吻别 2020-12-02 11:12

I\'m working with PyOpenCV. How to convert cv2 image (numpy) to binary string for writing to MySQL db without a temporary file and imwrite?

I googled it

6条回答
  •  天命终不由人
    2020-12-02 11:56

    im = cv2.imread('/tmp/sourcepic.jpeg')
    res, im_png = cv2.imencode('.png', im)
    with open('/tmp/pic.png', 'wb') as f:
        f.write(im_png.tobytes())
    

提交回复
热议问题