How to compress png file with opencv in python?

此生再无相见时 提交于 2019-12-04 07:55:46
Miki

The name in OpenCV 3.0 is IMWRITE_PNG_COMPRESSION (without the CV_ prefix).

So try:

cv2.imwrite('compress_img1.png', img,  [cv2.IMWRITE_PNG_COMPRESSION, 9])

This post mentions also to cast to int. I'm not sure if this is still needed:

cv2.imwrite('compress_img1.png', img,  [int(cv2.IMWRITE_PNG_COMPRESSION), 9])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!