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 11. Linking and Deployment

After learning about debugging and testing applications using Qt Creator and the Qt Test framework in the previous chapters, we are down to one of the last phases in application development, which is the deployment of applications to the end users. This process itself has many variations and can take quite a lot of different forms depending on the target platform, but one thing they all have in common is the packaging of an application in a way that it can be simply executed in the target platform and without bothering with the dependencies of the application. Remember, not all target platforms (whether it is Windows, macOS, or Linux) have Qt and OpenCV libraries on them. So, if you go on and just provide the users of your application with only the executable of your application, it will most probably not even start executing, much less working correctly.

In this chapter, we are going to tackle exactly that, by learning about the correct way of creating...

The build process, behind the scenes


It all seems quite natural when we an application by editing some C++ header or source files, adding some modules in the project file, and finally pressing the run button. However, there are a few processes going on behind the scenes which, by working in the correct order, executed by the IDE (in our case Qt Creator), allow this smooth and natural sense of development. In general, there are three major processes that lead to the creation of an executable (such as *.exe) when we press the run or Build button in Qt Creator, or any other IDE for that matter. Here are those three processes:

  • Preprocessing
  • Compiling
  • Linking

Note

This is a very high-level categorization of the processes and phases going when an application is created from the source files. This categorization allows a much simpler overview of the processes and an easier way to understand their purpose in general. However, these processes include many subprocesses and phases that are out of the scope...

Building OpenCV static libraries


Let's start with OpenCV, which follows almost the same set of instructions for building libraries as we did for dynamic libraries. You can refer to Chapter 1, Introduction to OpenCV and Qt, for more information about this. Simply download the source codes, extract, and use CMake to configure your build, as it is mentioned in that chapter. This time though, in addition to checking the checkbox next to the BUILD_opencv_world option, also make sure that all of the following options are turned off by unchecking the checkbox next to each one of them:

  • BUILD_DOCS
  • BUILD_EXAMPLES
  • BUILD_PERF_TESTS
  • BUILD_TESTS
  • BUILD_SHARED_LIBS
  • BUILD_WITH_STATIC_CRT (only available on Windows)

Turning off the first four parameters is merely for speeding up the build process and is completely optional. Disabling BUILD_SHARED_LIBS simply enables the static (non-shared) build mode of OpenCV libraries, and the last parameter (on Windows) helps with avoiding incompatible library files. Now, if...

Building Qt static libraries


By default, only dynamic Qt libraries are with the official Qt installers. This was also the case in Chapter 1, Introduction to OpenCV and Qt, when we installed Qt in our development environment by using the installers provided by the following link:

https://download.qt.io/official_releases/qt/5.9/5.9.1/

So, to put it simply, if you want to use the static Qt libraries, you must build them on your own using their source codes. You can follow the steps provided here in order to configure, build, and use static Qt libraries:

  1. To be able to build a set of static Qt libraries, you need to start by downloading the source codes from the Qt downloads website. They are usually provided as a single compressed file (*.zip, *.tar.xz, and so on) that contains all of the required codes. In our case (Qt version 5.9.1), you can use the following link to download the Qt source codes:https://download.qt.io/official_releases/qt/5.9/5.9.1/single/

Download qt-everywhere-opensource-src...

Deploying Qt+OpenCV applications


It is extremely important to provide the users with an application package that contains everything it needs to be able to run on the target platform and demand very little or no effort at all from the users in terms of taking care of the required dependencies. Achieving this kind of works-out-of-the-box condition for an application relies mostly on the type of the linking (dynamic or static) that is used to create an application, and also the specifications of the target operating system.

Deploying using static linking

Deploying an application statically that your application will run on its own and it eliminates having to take care of almost all of the needed dependencies, since they are already inside the executable itself. It is enough to simply make sure you select the Release mode while building your application, as seen in the following screenshot:

When your application is built in the Release mode, you can simply pick up the produced executable file...

Summary


Whether your application can be easily installed and used on a target computer or not, it can mean winning or losing a significant number of users. Especially with the ones that are not professional users, you must make sure to create and deploy installers that contain all of the required dependencies and work out of the box on the target platform. In this chapter, we talked a fair amount about just that. We learned about the build process and how the linking method that we choose can completely alter the deployment experience. We learned about existing Qt tools to simplify the deployment process on Windows and macOS. Note that these tools contain many more parameters than we saw in this chapter, and they are worth taking a deeper look at by yourself, and trying out various parameters to see their effect for yourself. In the last section of this chapter, we learned about Qt Installer Framework and also created a simple installer by using it. We learned how to create packages that...

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}