Image compression on opencv (imwrite). How to explicitly set the compression ratio?

I was wondering if there is a way to easily determine the compression ratio when compressing images on opencv without declaring a dummy vector. If I declare a vector p (similar to this discussion ), but containing only 2 elements, which imwrite does, I can make a call:

vector<int> p; p[0] = CV_IMWRITE_JPEG_QUALITY; p[1] = 50; // compression factor imwrite("compressed.jpg", img, p); 

The above works fine. However, I want to compress the same image with multiple compression ratios in a loop. Is there a way to explicitly pass the imwrite parameter? Sort of:

 imwrite("compressed.jpg", img, {CV_IMWRITE_JPEG_QUALITY, factor}); // this doesn't work 

As a note, the function header:

 bool imwrite(const string& filename, const Mat& img, const vector<int>& params=vector<int>()); 

Thanks!

Update: After activating C ++ 0x, I can pass a vector explicitly defined in the function string.

+6
source share
1 answer

As suggested, activating C ++ 0x allows me to pass in a vector explicitly defined in a function string. This solved the problem.

+1
source

Source: https://habr.com/ru/post/896169/


All Articles