In its most basic form and shape, Computer Vision is the term that is used to identify all methods and algorithms that are used to empower digital devices with a sense of vision. What does that mean? Well, it means exactly what it sounds like. Ideally, computers should be able to see the world through the lens of a standard camera (or any other type of camera for that matter), and by applying various Computer Vision algorithms, they should be able to detect faces, even recognize them, count objects in an image, detect motion in video feeds, and do many more, which, at first guess, would only be expected of a human being. So, to understand what Computer Vision really is, it's better to know that Computer Vision aims to develop methods to achieve the ideal that was mentioned, empowering digital devices with the power of seeing and understanding the surrounding environment. It is worth noting that most of the time Computer Vision and Image Processing are used interchangeably (although, a historical study of the subject may prove that it should be otherwise). But nevertheless, throughout this book we'll stick to the term Computer Vision since that is the more popular and widely used term nowadays in computer science communities and also because, as we'll see later in this chapter, Image Processing is a module of OpenCV library that we'll also be introduced to in the upcoming pages of this chapter, and it will also be covered in a complete chapter of its own.
Computer Vision is one of the today's most popular subjects in computer science and it's used in a variety of applications ranging from medical tools that detect cancerous tissues to video editing software that helps make all those shiny music videos and movies, and from military grade target detectors that help locate a specific location on the map to traffic sign detectors that help driverless cars find their way around. Well, it's obvious that we can't finish naming all possibilities for Computer Vision, but we can be sure it's an interesting subject that will be around for a long time. It's also worth mentioning that there is a fast-expanding market for jobs and careers in the field of Computer Vision and it's growing day by day.
Among the most popular tools used by Computer Vision developers and experts, come two of the most prominent frameworks of open source community, which are also in the title of the book you have in hand, OpenCV and Qt. Every day, literally thousands of developers around the world, ranging from established corporations to innovative startup companies, work with these two frameworks to build applications for various sets of industries, such as the ones we mentioned, and that is exactly what you will learn in this book.
In this chapter, we will cover the following topics:
- Introducing Qt, an open source, and cross-platform application development framework
- Introducing OpenCV, an open source, and cross-platform computer vision framework
- How to install Qt on Windows, macOS, and Linux operating systems
- How to build OpenCV from sources on Windows, macOS, and Linux operating systems
- Configuring your development environment to build applications using a combination of both Qt and OpenCV frameworks
- Build your very first application using Qt and OpenCV
This is the most obvious question after what was said in the introduction of this chapter, but the answer for it is also the first step in our journey to learn Computer Vision. This book is intended for developers who are familiar with C++ programming language and want to develop powerful and good-looking computer vision applications that perform well on different operating systems without much effort. This book aims to take you on an exciting journey through different topics of Computer Vision with a focus on hands-on exercises and developing whatever you learn, one step at a time.
Anyone with enough C++ experience knows that it's not an easy task to write visually rich applications using raw C++ code and depending on OS-specific APIs. So, almost every C++ developer (or at least serious developers with an active career in C++), use one or another framework to ease the process. Among the most widely known frameworks for C++ comes Qt. It is, in fact, one of the top choices, if not the top choice for that matter. On the other hand, if your aim is to develop an application dealing with images or visualized datasets, the OpenCV Framework is perhaps the first (and perhaps the most popular) address to visit. So, that's why this book focuses on the combination of Qt and OpenCV. Developing Computer Vision applications for different desktop and mobile platforms that perform with the highest possible performance would not be possible without using a combination of powerful frameworks such as Qt and OpenCV.
To summarize what was said, make sure you have at least an intermediate level of knowledge in C++ programming language. If terms such as class, abstract class, inheritance, templates, or pointers sound unfamiliar to you, then consider reading a book on C++ first. For all the rest of the topics, especially all of the hands-on topics that are covered, this book promises you crystal clear explanations (or reference to specific documentation pages) for all of the examples and tutorials included. Of course, to get a very detailed and deep understanding of how modules and classes are implemented in Qt and OpenCV, you need to be familiar with many more resources, studies, sometimes even hard-core mathematical calculations or low-level understanding of how a computer or operating system performs in the real world, which is totally out of the scope of this book. However, for all the algorithms and methods covered in this book, you will get a brief description of what they are, how and when and where they are used, and enough guidelines to let you continue digging deeper if you feel like it.
You have heard about it or maybe even used it knowing it. It's the foundation of many world famous commercial and open source applications, such as VLC Player, Calibre, and so many more. The Qt Framework is used by a majority of the so-called Fortune 500 companies, and we can't even begin to define how widely used and popular it is among the many application development teams and companies in the world. So, we'll start with an introduction and take it from there.
Let's first go through a brief introduction to the Qt Framework to get us on our feet. Nothing can make you feel more comfortable with a framework than having a clear picture of the whole thing in your mind. So, here we go, currently built and managed by The Qt Company, Qt Framework is an open source application development framework that is widely used to create visually rich and cross-platform applications that can be run on different operating systems or devices with very little or no effort at all. To break it down further, open source is the most obvious part of it. It means you can access all of the source code for Qt. By visually rich, we mean enough resources and capabilities are present in Qt Framework to write very beautiful applications. As for the last part, cross-platform, this basically means that, if you develop an application using Qt Framework modules and classes for Microsoft Windows operating system, for instance, then it can be compiled and built for macOS or Linux exactly as it is, without changing a single line of code (almost), provided that you don't use any non-Qt or platform-specific libraries in your application.
At the time of writing this book, Qt framework (or simply Qt from here on) is at version 5.9.X and it contains many modules for almost any purpose in developing applications. Qt divides those modules into these four main categories:
- Qt Essentials
- Qt Add-Ons
- Value-Add Modules
- Technology Preview Modules
Let's see what they are and what they include since we'll be dealing with them a lot throughout this book.
These are the modules promised by Qt to be available on all supported platforms. They are basically the foundation of Qt and they contain the majority of the classes that are used by almost all Qt applications. Qt Essential modules include all of the general-purpose modules and classes. Pay real attention to the words general-purpose, since it's exactly what these modules are used for. The following is a brief list for a quick study of the modules and for later reference purposes:
Module | Description |
These are core non-graphical classes used by other modules. | |
These are base classes for graphical user interface (GUI) components. These include OpenGL. | |
These are classes for audio, video, radio, and camera functionality. | |
These are widget-based classes to implement multimedia functionality. | |
These are classes to make network programming easier and more portable. | |
These are classes for QML and JavaScript languages. | |
This is a declarative framework to build highly dynamic applications with custom user interfaces. | |
These are reusable Qt Quick based UI controls to create classic desktop-style user interfaces. | |
These are types to create and interact with system dialogs from a Qt Quick application. | |
These layouts are items that are used to arrange Qt Quick 2 based items in the user interface. | |
These are classes for database integration using SQL. | |
These are classes for unit testing Qt applications and libraries. | |
These are classes to extend Qt GUI with C++ widgets. |
For information, refer to http://doc.qt.io/qt-5/qtmodules.html.
Note that it's not possible and perhaps not a good idea to cover all modules and all classes in this book, and, for the most part we will stick to whatever module and class we require; however, by the end of the book you'll feel comfortable enough exploring all the numerous and powerful modules and classes within Qt by yourself. You'll learn how to include a module and class in your projects in the upcoming chapters, so for now, let's not bother with too much detail and just focus on having a picture of what Qt really is and what it contains in our minds.
These modules may or may not be available on all platforms. This means they are used for developing specific capabilities as opposed to the general-purpose nature of Qt Essentials. A few examples of these type of modules are Qt 3D, Qt Print Support, Qt WebEngine, Qt Bluetooth, and many more. You can always refer to the Qt documentation for a complete list of these modules, and in fact, they are too many to be just listed here. For the most part, you can get a brief idea of what a module is used for by just looking.
For information on this you can refer to http://doc.qt.io/qt-5/qtmodules.html.
These modules offer additional capabilities and are offered with a commercial license from Qt. Yes, you guessed it right, these are the modules that are only available in a paid version of Qt and are not offered in the open source and free version of the Qt, but they're mostly aimed to help with very specific tasks that we don't need at all for the purpose of this book. You can get a list using the Qt documentation pages.
For information on this you can refer to http://doc.qt.io/qt-5/qtmodules.html.
Exactly as their name implies, these modules are the ones that are offered in a state that is not guaranteed to work for all cases; they may or may not contain bugs or other issues, and they are simply still in development and are offered as a preview for test and feedback purposes. As soon as a module is developed and becomes mature enough, it becomes available in other categories mentioned before, and it's taken out of the technology preview category. An example of these types of modules, at the moment of writing this book, is Qt Speech, which is a module that is aimed to add support for text-to-speech in Qt applications. It's always a good idea to keep an eye on these modules if you are looking forward to becoming a fully-fledged Qt developer.
For more information on this, you can refer to http://doc.qt.io/qt-5/qtmodules.html.
When we are talking about developing applications, the platform can have many different meanings, including the OS type, OS version, Compiler type, Compiler version, and Architecture of the processor (32-bit, 64-bit, Arm, and more). Qt supports many (if not all) of the well-known platforms and is quick enough to catch up with new platforms when they are released. The following is the list of platforms supported by Qt at the moment of writing this book (Qt 5.9). Note that you will probably not use all of the platforms mentioned here, but it gives you a sense of how powerful and cross-platform Qt really is:
Platform | Compiler | Notes |
Windows | ||
Windows 10 (64-bit) | MSVC 2017, MSVC 2015, MSVC 2013, MinGW 5.3 | |
Windows 10 (32-bit) | MSVC 2017, MSVC 2015, MSVC 2013, MinGW 5.3 | |
Windows 8.1 (64-bit) | MSVC 2017, MSVC 2015, MSVC 2013, MinGW 5.3 | |
Windows 8.1 (32-bit) | MSVC 2017, MSVC 2015, MSVC 2013, MinGW 5.3 | |
Windows 7 (64-bit) | MSVC 2017, MSVC 2015, MSVC 2013, MinGW 5.3 | |
Windows 7 (32-bit) | MSVC 2017, MSVC 2015, MSVC 2013, MinGW 5.3 | MinGW-builds gcc 5.3.0 (32-bit) |
Linux/X11 | ||
openSUSE 42.1 (64-bit) | GCC 4.8.5 | |
Red Hat Enterprise Linux 6.6 (64-bit) | GCC 4.9.1 | devtoolset-3 |
Red Hat Enterprise Linux 7.2 (64-bit) | GCC 5.3.1 | devtoolset-4 |
Ubuntu 16.04 (64-bit) | GCC as provided by Canonical | |
(Linux 32/64-bit) | GCC 4.8, GCC 4.9, GCC 5.3 | |
macOS | ||
macOS 10.10, 10.11, 10.12 | Clang as provided by Apple | |
Embedded Platforms: Embedded Linux, QNX, INTEGRITY | ||
Embedded Linux | GCC | ARM Cortex-A, Intel boards with GCC-based toolchains |
QNX 6.6.0, 7.0 (armv7le and x86) | GCC as provided by QNX | Hosts: RHEL 6.6 (64-bit), RHEL 7.2 (64-bit), Windows 10 (64-bit), Windows 7 (32-bit) |
INTEGRITY 11.4.x | As provided by Green Hills INTEGRITY | Hosts: 64-bit Linux |
Mobile Platforms: Android, iOS, Universal Windows Platform (UWP) | ||
Universal Windows Platform (UWP) (x86, x86_64, armv7) | MSVC 2017, MSVC 2015 | Hosts: Windows 10 |
iOS 8, 9, 10 (armv7, arm64) | Clang as provided by Apple | macOS 10.10 host |
Android (API Level: 16) | GCC as provided by Google, MinGW 5.3 | Hosts: RHEL 7.2 (64-bit), macOS 10.12, Windows 7 (64-bit) |
Reference: http://doc.qt.io/qt-5/supported-platforms.html
As you'll see in the next sections, we'll use the Microsoft Visual C++ 2015 (or from here on, simply MSVC 2015) compiler on Windows since both Qt and OpenCV (which you'll learn about later) highly support it. We'll also use GCC on Linux and Clang on macOS operating systems. All of which are tools that are either free and open source, or they are provided by the operating system provider. Although our main development system will be Windows, we'll cover Linux and macOS operating systems whenever there is a difference between Windows and other versions. So, the default screenshots throughout the book will be that of Windows, with Linux and macOS screenshots provided wherever there's any serious difference between them and not just simply a slight difference between paths, coloring of buttons, and so on.
Creator
is the name of the IDE (Integrated Development Environment) used to develop applications. It's also the IDE that we will use throughout this book to create and build our projects. It is worth noting that Qt applications can be created using any other IDE (such as Visual Studio or Xcode), and Qt Creator is not a requirement to build Qt applications, but it's a lightweight and powerful IDE that comes with the Qt Framework installer by default. So, the biggest advantage it has is easy integration with the Qt framework.
The following is a screenshot of the Qt Creator, which shows the IDE in code editing mode. Details on how to use the Qt Creator will be covered in the next chapter, although we'll give it a try for a couple of tests later on in this chapter too, without going into too much detail about it:
