为什么openCV存储的文件比原始文件大(kB)?

编程入门 行业动态 更新时间:2024-10-23 09:36:24
本文介绍了为什么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)?

本文发布于:2023-11-22 06:51:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616391.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   原始   openCV   kB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!