Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Qt 5 and OpenCV 4 Computer Vision Projects
Qt 5 and OpenCV 4 Computer Vision Projects

Qt 5 and OpenCV 4 Computer Vision Projects: Get up to speed with cross-platform computer vision app development by building seven practical projects

eBook
₹799.99 ₹2621.99
Paperback
₹3276.99
Subscription
Free Trial
Renews at ₹800p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Table of content icon View table of contents Preview book icon Preview Book

Qt 5 and OpenCV 4 Computer Vision Projects

Editing Images Like a Pro

In Chapter 1, Building an Image Viewer, we built a simple application for image viewing with Qt from scratch. With that application, we can view an image from the local disk, zoom the view in or out, and navigate in the opening directory. In this chapter, we will continue with that application and add some features to allow users to edit the opening image. To achieve this goal, we will get the OpenCV library we mentioned at the beginning of this book involved. To make the application extensible, we will develop most of these editing features as plugins using the plugin mechanism of Qt.

The following topics will be covered in this chapter:

  • Converting images between Qt and OpenCV
  • Extending an application through Qt's plugin mechanism
  • Modifying images using image processing algorithms provided by OpenCV
...

Technical requirements

Users are required to have the ImageViewer application, which we built in the previous chapter, running correctly. Our development in this chapter will be based on that application.

Also, some basic knowledge of OpenCV is required as a prerequisite. We will be using the latest version of OpenCV, that is, version 4.0, which was released in December 2018, when this book was being written. Since the new version is not yet included in the software repositories of many operator systems, such as Debian, Ubuntu, or Fedora, we will build it from the source. Please don't worry about this—we will cover the installation instructions briefly, later in this chapter.

All of the code for this chapter can be found in this book's GitHub repository at https://github.com/PacktPublishing/Qt-5-and-OpenCV-4-Computer-Vision-Projects/tree/master/Chapter-02.

Check...

The ImageEditor application

In this chapter, we will build an application that can be used to edit images, so we will name it ImageEditor. To edit an image with a GUI application, the first step is opening and viewing the image with that application, which is what we did in the previous chapter. Therefore, I decided to make a copy of the ImageViewer application and rename it ImageEditor, before adding the image editing features to it.

Let's start by copying the sources:

    $ mkdir Chapter-02
$ cp -r Chapter-01/ImageViewer/ Chapter-02/ImageEditor
$ ls Chapter-02
ImageEditor
$ cd Chapter-02/ImageEditor
$ make clean
$ rm -f ImageViewer

With these commands, we copy the ImageViewer directory under the Chapter-01 directory to Chapter-02/ImageEditor. Then, we can enter that directory, run make clean to clean all intermediate files that were generated in the compiling...

Blurring images using OpenCV

In the preceding section, we set up our editor application. In this section, we will add a simple feature of image editing—an action (both on the menu and the toolbar) to blur the image.

We will do this in two steps:

  1. First, we will set up the UI and add the action, and then connect the action to a dummy slot.
  2. Then, we will rewrite the dummy slot to blur the image, which will get the OpenCV library involved.

Adding the blur action

Most of the actions we will add in this chapter will be used to edit an image, so we should categorize them in a new menu and toolbar. First, we will declare three members, that is, the edit menu, the edit toolbar, and the blur action, in the private section of...

Adding features using Qt's plugin mechanism

In the previous section, we added a new menu and toolbar named Edit to our application and added an action to both of them to blur the opening image. Let's recall the progress of adding this feature.

First, we added the menu and toolbar, and then the action. After the action was added, we connected a new slot to the action. In the slot, we got the opening image as an instance of QPixmap and converted it into a QImage object, and then a Mat object. The crucial editing work began here—we used OpenCV to modify the Mat instance to get the editing work done. Then, we converted Mat back into QImage and QPixmap accordingly to show the edited image.

Now, if we want to add another editing feature to our app, what should we do? Of course, just repeating the preceding process of adding the blurring action is fine, but it's...

Editing images like a pro

In the preceding section, we looked at how we can add image editing features as plugins for our application. By doing this, we don't need to take care of the user interface, opening and closing the images, and the hotkeys. Instead, we have to add a new editing feature, which we do by writing a subclass of the EditorPluginInterface interface and implementing its pure virtual functions, and then compile it into a plugin file (a shared library file) and copy it into the plugin directory of our application. In this section, we will talk about image editing using OpenCV.

First, let's start with sharpening images.

Sharpening images

Image sharpening is a common feature that is implemented by many...

Summary

In this chapter, we remade the desktop application for image viewing that we built in Chapter 1, Building an Image Viewer, to make an image editor application. Then, we added a simple editing feature to blur images. At the same time, we learned about how to install and set up OpenCV for Qt applications, the data structures related to image processing both in Qt and OpenCV, and how to process images using OpenCV.

Afterward, we learned about the plugin mechanism of the Qt library and abstracted out a way to add editing features to our applications in a more flexible and convenient way as plugins. As an example of this, we wrote our first plugin to erode images.

Then, we moved our attention to the OpenCV library to discuss how to edit images like a prowe made numerous plugins to edit images, to sharpen images, to make cartoon effects, to rotate, to execute affine...

Questions

Try out these questions to test your knowledge of this chapter:

  1. How do we know if an OpenCV function supports in-place operation or not?
  2. How can we add a hotkey for each action we added as a plugin?
  3. How can we add a new action to discard all the changes to the current image in our application?
  4. How can we resize images using OpenCV?
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Gain practical insights into code for all projects covered in this book
  • Understand modern computer vision concepts such as character recognition, image processing and modification
  • Learn to use a graphics processing unit (GPU) and its parallel processing power for filtering images quickly

Description

OpenCV and Qt have proven to be a winning combination for developing cross-platform computer vision applications. By leveraging their power, you can create robust applications with both an intuitive graphical user interface (GUI) and high-performance capabilities. This book will help you learn through a variety of real-world projects on image processing, face and text recognition, object detection, and high-performance computing. You’ll be able to progressively build on your skills by working on projects of increasing complexity. You’ll begin by creating an image viewer application, building a user interface from scratch by adding menus, performing actions based on key-presses, and applying other functions. As you progress, the book will guide you through using OpenCV image processing and modification functions to edit an image with filters and transformation features. In addition to this, you’ll explore the complex motion analysis and facial landmark detection algorithms, which you can use to build security and face detection applications. Finally, you’ll learn to use pretrained deep learning models in OpenCV and GPUs to filter images quickly. By the end of this book, you will have learned how to effectively develop full-fledged computer vision applications with OpenCV and Qt.

Who is this book for?

This book is for engineers and developers who are familiar with both Qt and OpenCV frameworks and are capable of creating simple projects using them, but want to build their skills to create professional-level projects using them. Familiarity with the C++ language is a must to follow the example source codes in this book.

What you will learn

  • Create an image viewer with all the basic requirements
  • Construct an image editor to filter or transform images
  • Develop a security app to detect movement and secure homes
  • Build an app to detect facial landmarks and apply masks to faces
  • Create an app to extract text from scanned documents and photos
  • Train and use cascade classifiers and DL models for object detection
  • Build an app to measure the distance between detected objects
  • Implement high-speed image filters on GPU with Open Graphics Library (OpenGL)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 21, 2019
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781789531831
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning

Product Details

Publication date : Jun 21, 2019
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781789531831
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
₹800 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
₹4500 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts
₹5000 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 10,203.97
Machine Learning for OpenCV 4
₹3649.99
OpenCV 4 Computer Vision Application Programming Cookbook
₹3276.99
Qt 5 and OpenCV 4 Computer Vision Projects
₹3276.99
Total 10,203.97 Stars icon

Table of Contents

10 Chapters
Building an Image Viewer Chevron down icon Chevron up icon
Editing Images Like a Pro Chevron down icon Chevron up icon
Home Security Applications Chevron down icon Chevron up icon
Fun with Faces Chevron down icon Chevron up icon
Optical Character Recognition Chevron down icon Chevron up icon
Object Detection in Real Time Chevron down icon Chevron up icon
Real-Time Car Detection and Distance Measurement Chevron down icon Chevron up icon
Using OpenGL for the High-Speed Filtering of Images Chevron down icon Chevron up icon
Assessments Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(2 Ratings)
5 star 50%
4 star 50%
3 star 0%
2 star 0%
1 star 0%
Anthony Love Oct 20, 2023
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Feefo Verified review Feefo
Robert Feb 26, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The chapters build on each other, the books author does anexcellent job of laying out the material. Each chapter tells youwhere you can get the needed code in order to follow the examples in the book.I am learning a lot from this book.Good Job !!!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.