The imwrite
function in OpenCV can be used to write images into files on disk. It uses the extension of the filename to decide the format of the image. To customize the compression rate and similar settings in an imwrite
function, you need to use ImwriteFlags
, ImwritePNGFlags
, and so on. Here's a simple example demonstrating to write an image into a JPG file with a progressive set on and a relatively low quality (higher compression rate):
std::vector<int> params; params.push_back(IMWRITE_JPEG_QUALITY); params.push_back(20); params.push_back(IMWRITE_JPEG_PROGRESSIVE); params.push_back(1); // 1 = true, 0 = false imwrite("c:/dev/output.jpg", image, params);
You can omit the params
altogether if you want to use the default settings and simply write:
imwrite("c:/dev/output.jpg", image, params);
See the imread
function in the previous section for the same list of supported file types in the imwrite
function.
Apart from imwrite
,...