I am using OpenCV and saving as a jpeg using the cvSaveImage function, but I am unable to find the Jpeg compression factor used by this.
- What's cvSaveImage(...)'s Jpeg Compression factor
- How can I pass the compression factor when using cvSaveImage(...)
filename.jpeg
will be output File namesrc
be source image read containing variable(vector<int>)
typecasting{CV_IMWRITE_JPEG_QUALITY, 20}
an array of elements to be passed as Param_ID - and Param_value in imwrite functionCurrently cvSaveImage() is declared to take only two parameters:
However, the "latest tested snapshot" has:
I've been unable to find any documentation, but my impression from poking through this code is that you would build an array of int values to pass in the third parameter:
I don't know how the quality value is encoded, and I've never tried this, so caveat emptor.
Edit:
Being a bit curious about this, I downloaded and built the latest trunk version of OpenCV, and was able to confirm the above via this bit of throwaway code:
My "test.jpg" was 2,054 KB, the created "out1.jpg" was 182 KB and "out2.jpg" was 4,009 KB.
Looks like you should be in good shape assuming you can use the latest code available from the Subversion repository.
BTW, the range for the quality parameter is 0-100, default is 95.
OpenCV now has a parameter to set jpeg quality. I'm not sure exactly when this was introduced, but presumably sometime after 2.0.
If you are using C++0x, you can use this shorter notation: