python OpenCV jpeg compression in memory

前端 未结 1 540
抹茶落季
抹茶落季 2020-12-30 04:24

In OpenCV it is possible to save an image to disk with a certain jpeg compression. Is there also a way to do this in memory? Or should I write a function using cv2.ims

相关标签:
1条回答
  • 2020-12-30 05:26

    You can use imencode:

    encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90]
    result, encimg = cv2.imencode('.jpg', img, encode_param)
    

    (The default value for IMWRITE_JPEG_QUALITY is 95.)

    You can decode it back with:

    decimg = cv2.imdecode(encimg, 1)
    

    Snippet from here

    0 讨论(0)
提交回复
热议问题