Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Computer Vision with OpenCV 3 and Qt5

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

Product type Book
Published in Jan 2018
Publisher Packt
ISBN-13 9781788472395
Pages 486 pages
Edition 1st Edition
Languages
Author (1):
Amin Ahmadi Tazehkandi Amin Ahmadi Tazehkandi
Profile icon Amin Ahmadi Tazehkandi

Table of Contents (19) Chapters

Title Page
Dedication
Packt Upsell
Foreword
Contributors
Preface
Introduction to OpenCV and Qt Creating Our First Qt and OpenCV Project Creating a Comprehensive Qt+OpenCV Project Mat and QImage The Graphics View Framework Image Processing in OpenCV Features and Descriptors Multithreading Video Analysis Debugging and Testing Linking and Deployment Qt Quick Applications Other Books You May Enjoy

Chapter 6. Image Processing in OpenCV

It always starts with an unprocessed and raw image, taken with a smartphone, webcam, DSLR camera, or, in short, any device that is capable of shooting and recording image data. However, it usually ends with sharp or blurred; bright, dark, or balanced; black and white or colored; and many other different representations of the same image data. This is probably the initial step (and one of the most important steps) in computer vision algorithms, and it's usually referred to as Image Processing (for now, let's forget about the fact that, sometimes, computer vision and Image Processing are used interchangeably; this is a discussion for experts). Of course, you can have image processing in between or in the final phases of any computer vision process, but, in general, any photo or video recorded with most of the existing devices undergoes some kind of image processing algorithm before anything else. Some of these algorithms are just meant to convert the...

Image filtering


In this starting section, you will learn about linear and non-linear image filtering methods available in OpenCV. It's important to note that all of the functions discussed in this section take a Mat image as an input and produce a Mat image of the same size and the same number of channels. In fact, the filters are applied to each channel independently. In general, filtering methods take a pixel and its pixels from the input image and calculate the value of the corresponding pixel in the resulting image based on a function response from those pixels.

This usually requires an assumption to be made about the pixels that do not exist, while calculating the filtered pixel result. OpenCV provides a number of methods to overcome this issue, and they can be specified in almost all of the OpenCV functions that need to deal with this phenomenon using the cv::BorderTypes enum. We will see how it is used in our first example in this chapter a bit later, but, before that, let's make...

Image transformation capabilities


In this section, you will learn about the transformation capabilities available in OpenCV. In general, there are two image transformation categories in OpenCV, called geometric and miscellaneous (which simply means everything else) transformations if you take a look at the OpenCV documentation. The reason for this is explained here.

Geometric transformations, as it can be guessed from their name, deal mostly with geometric properties of images, such as their size, orientation, shape, and so on. Note that a geometric transformation does not change the contents of the image, but it merely changes the form and shape of it by moving around the pixels of an depending on the geometric transformation type. Same as what we saw with filtering images in the beginning of the previous section, geometric transformation functions also need to deal with the extrapolation of pixels outside of an image, or, simply put, making an assumption about the non-existing pixels...

Drawing in OpenCV


It's impossible to ignore drawing text and shapes on an image when the subject is OpenCV and computer vision in general. For countless reasons, you will need to draw (output) some text or shapes on the output images. For example, you may want to write a program that prints the date of the image (or images) on it. Or you may want to draw a square around faces in the after performing a face detection. Even though Qt framework also provides quite powerful functions to deal with such tasks, it is also possible to use OpenCV itself to draw on images. In this section, you will learn about using OpenCV drawing functions one by one, which are surprisingly very easy to use, along with example codes and output results.

Drawing functions in OpenCV accept an input and output image, quite understandably, along with a few parameters which are common to most of them. Here are the mentioned common parameters of drawing functions in OpenCV along with their meaning and possible values:

  • color...

Template matching


The OpenCV framework offers different methods for object detection, tracking, and counting. Template matching is one of the most basic methods of object detection in OpenCV, yet, if it's used correctly and in conjunction with good threshold values, it can be used to effectively detect and count objects in an image. It is done by using a single function in OpenCV called the matchTemplate function.

The matchTemplate function takes an image as the input parameter. Consider it the image that will be searched for the object (or better yet, the scene that may contain the template) that we are interested in. It also takes a template as the second parameter. This template is also an image, but it's the one that will be searched for within the first image parameter. Another parameter required by this function, which is also the most important parameter and the one that decides the template matching method, is the method parameter, which can be one of the entries in the cv::TemplateMatchModes...

Summary


We are now familiar with some of the most widely used functions, enums, and classes in the OpenCV framework. Most of the skills you learned in this chapter are used almost in every computer vision application, one way or another. Starting from image filtering, which is one of the most initial steps in a computer vision process, up until image transformation methods and color space conversion, every computer vision application needs to have access to these methods, either to be able to perform a specific task or to optimize its performance in some way. In this chapter, you learned all about image filtering and geometric transformations. You learned how to use functions such as remap to perform countless image transformations. You also learned about color spaces and how to convert them to each other. Later on, we even used color mapping functions to map colors in an image to another set of colors. Then, you learned about image thresholding and how to extract parts of an image with...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Computer Vision with OpenCV 3 and Qt5
Published in: Jan 2018 Publisher: Packt ISBN-13: 9781788472395
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}