Book Image

Computer Vision with OpenCV 3 and Qt5

By : Amin Ahmadi Tazehkandi
4 (1)
Book Image

Computer Vision with OpenCV 3 and Qt5

4 (1)
By: Amin Ahmadi Tazehkandi

Overview of this book

Developers have been using OpenCV library to develop computer vision applications for a long time. However, they now need a more effective tool to get the job done and in a much better and modern way. Qt is one of the major frameworks available for this task at the moment. This book will teach you to develop applications with the combination of OpenCV 3 and Qt5, and how to create cross-platform computer vision applications. We’ll begin by introducing Qt, its IDE, and its SDK. Next you’ll learn how to use the OpenCV API to integrate both tools, and see how to configure Qt to use OpenCV. You’ll go on to build a full-fledged computer vision application throughout the book. Later, you’ll create a stunning UI application using the Qt widgets technology, where you’ll display the images after they are processed in an efficient way. At the end of the book, you’ll learn how to convert OpenCV Mat to Qt QImage. You’ll also see how to efficiently process images to filter them, transform them, detect or track objects as well as analyze video. You’ll become better at developing OpenCV applications.
Table of Contents (19 chapters)
Title Page
Dedication
Packt Upsell
Foreword
Contributors
Preface

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