Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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 .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top