简体   繁体   中英

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(). 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(){

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. Here is how to to pass custom compression factor - OpenCV cvSaveImage Jpeg Compression Factor .

There are different methods of compression and coding combined in JPEG. Most likely your original image used a different compression/coding than standard openCV parametrization for cvSaveImage.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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