本文介绍了为什么openCV存储的文件比原始文件大(kB)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以两种不同方式加载和保存图像的代码-第一种使用openCV,第二种使用PIL.
I have code that loads and saves the image in two different ways - first using openCV, the second using PIL.
import cv2 from PIL import Image img = cv2.imread("/home/myname/png/image.png") cv2.imwrite("/home/myname/png/image_save.png", img) img = Image.open("/home/myname/png/image.png") img.save("/home/myname/png/image_save_pil.png")原始图像的大小为204.6 kB.openCV的结果为245.0 kB,PIL的结果为204.6 kB.
The original image is 204.6 kB in size. The result obtained with openCV is 245.0 kB, the result of PIL is 204.6 kB.
为什么用openCV保存的图像尺寸更大?
Why does the image saved with openCV have a larger size?
推荐答案大小差异与ZLIB压缩设置有关.
The size difference has to do with the ZLIB compression settings.
- 默认情况下,PIL最多使用9(请参见这里)
- 默认情况下,OpenCV仅使用3(请参见这里)
使用OpenCV,您可以使用以下代码将压缩率设置为9(来自此 answer )
Using OpenCV you can set compression to 9 using this code (from this answer)
cv2.imwrite('image.png', img, [int(cv2.IMWRITE_PNG_COMPRESSION), 9])更多推荐
为什么openCV存储的文件比原始文件大(kB)?
发布评论