简体   繁体   English

openCV cvSaveImage()增加图像大小

[英]openCV cvSaveImage() increases the size of image

i am loading an image and just saving the same image but with a different name using cvSaveImage(). 我正在加载图像,并使用cvSaveImage()保存相同的图像但名称不同。 After saving the size of the newly saved image gets increased. 保存后,新保存的图像的大小会增加。 can anyone tell me why and how to avoid it?? 谁能告诉我为什么以及如何避免它? here is my code: 这是我的代码:

int main(){ int main(){

IplImage* src = cvLoadImage("test.jpg", 0);

cvSaveImage("reTest.jpg", src);

return 0;

} }

thanks. 谢谢。

It is because of low JPEG compression factor used by default in OpenCV. 这是因为OpenCV默认使用的JPEG压缩系数较低。 Here is how to to pass custom compression factor - OpenCV cvSaveImage Jpeg Compression Factor . 这是如何传递自定义压缩因子-OpenCV cvSaveImage Jpeg压缩因子

There are different methods of compression and coding combined in JPEG. 在JPEG中结合使用不同的压缩和编码方法。 Most likely your original image used a different compression/coding than standard openCV parametrization for cvSaveImage. 与cvSaveImage的标准openCV参数化相比,您的原始图像很可能使用了不同的压缩/编码。

Try this: 尝试这个:

IplImage* src = cvLoadImage("test.jpg", 0);
cvSaveImage("reTest.jpg", src);
IplImage* reSrc = cvLoadImage("reTest.jpg",0);
cvSaveImage("reTest2.jpg", reSrc);

if reTest.jpg and reTest2.jpg have the same size, openCV does not increase the filesize but just uses a different compression level or sth. 如果reTest.jpgreTest2.jpg具有相同的大小,则openCV不会增加文件大小,而只是使用不同的压缩级别或其他。 You would have to find out the compression level and coding of your original file and save it with these same parameters, maybe with a different library than openCV. 您必须找出原始文件的压缩级别和编码,然后使用这些相同的参数保存它,也许使用与openCV不同的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM