Reader small image

You're reading from  Computer Vision with OpenCV 3 and Qt5

Product typeBook
Published inJan 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788472395
Edition1st Edition
Languages
Right arrow
Author (1)
Amin Ahmadi Tazehkandi
Amin Ahmadi Tazehkandi
author image
Amin Ahmadi Tazehkandi

Amin Ahmadi Tazehkandi is an Iranian author, developer, and a computer vision expert.Amin Ahmadi Tazehkandi is an Iranian author, developer, and a computer vision expert. He completed his computer software engineering studies in Iran and has worked for numerous software and industrial companies around the world.
Read more about Amin Ahmadi Tazehkandi

Right arrow

Writing images using OpenCV


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

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Computer Vision with OpenCV 3 and Qt5
Published in: Jan 2018Publisher: PacktISBN-13: 9781788472395

Author (1)

author image
Amin Ahmadi Tazehkandi

Amin Ahmadi Tazehkandi is an Iranian author, developer, and a computer vision expert.Amin Ahmadi Tazehkandi is an Iranian author, developer, and a computer vision expert. He completed his computer software engineering studies in Iran and has worked for numerous software and industrial companies around the world.
Read more about Amin Ahmadi Tazehkandi