Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Learn OpenCV 4 by Building Projects
Learn OpenCV 4 by Building Projects

Learn OpenCV 4 by Building Projects: Build real-world computer vision and image processing applications with OpenCV and C++ , Second Edition

Arrow left icon
Profile Icon Millán Escrivá Profile Icon Joshi Profile Icon Vinícius G. Mendonça
Arrow right icon
€36.99
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.5 (2 Ratings)
Paperback Nov 2018 310 pages 2nd Edition
eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Millán Escrivá Profile Icon Joshi Profile Icon Vinícius G. Mendonça
Arrow right icon
€36.99
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.5 (2 Ratings)
Paperback Nov 2018 310 pages 2nd Edition
eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Learn OpenCV 4 by Building Projects

Getting Started with OpenCV

Computer vision applications are interesting and useful, but the underlying algorithms are computationally intensive. With the advent of cloud computing, we are getting more processing power to work with.

The OpenCV library enables us to run computer vision algorithms efficiently in real time. It has been around for many years, and has become the standard library in this field. One of the main advantages of OpenCV is that it is highly optimized, and available on almost all platforms.

This book will cover the various algorithms we will be using, why we are using them, and how to implement them in OpenCV.

In this chapter, we are going to learn how to install OpenCV on various operating systems. We will discuss what OpenCV offers out of the box, and the various things that we can do using the inbuilt functions.

By the end of this chapter, you will be able to answer the following questions:

  • How do humans process visual data, and how do they understand image content?
  • What can we do with OpenCV, and what are the various modules available in OpenCV that can be used to achieve those things?
  • How do we install OpenCV on Windows, Linux, and Mac OS X?

Understanding the human visual system

Before we jump into OpenCV functionalities, we need to understand why those functions were built in the first place. It's important to understand how the human visual system works, so that you can develop the right algorithms.

The goal of computer vision algorithms is to understand the content of images and videos. Humans seem to do it effortlessly! So, how do we get machines to do it with the same accuracy?

Let's consider the following diagram:

The human eye captures all the information that comes along the way, such as color, shape, brightness, and so on. In the preceding image, the human eye captures all the information about the two main objects and stores it in a certain way. Once we understand how our system works, we can take advantage of it to achieve what we want.

For example, here are a few things we need to know:

  • Our visual system is more sensitive to low-frequency content than high-frequency content. Low-frequency content refers to planar regions where pixel values don't change rapidly, and high-frequency content refers to regions with corners and edges where pixel values fluctuate a lot. We can easily see if there are blotches on a planar surface, but it's difficult to spot something like that on a highly-textured surface.
  • The human eye is more sensitive to changes in brightness than to changes in color.

  • Our visual system is sensitive to motion. We can quickly recognize if something is moving in our field of vision, even though we are not directly looking at it.

  • We tend to make a mental note of salient points in our field of vision. Let's say you look at a white table with four black legs, and a red dot at one of the corners of the table surface. When you look at this table, you'll immediately make a mental note that the surface and legs have opposing colors, and that there is a red dot on one of the corners. Our brain is really smart that way! We do this automatically so that we can immediately recognize an object if we encounter it again.

To get an idea of our field of view, let's look at the top view of a human, and the angles at which we see various things:

Our visual system is actually capable of a lot more, but this should be good enough to get us started. You can explore further by reading up on Human Visual System (HVS) models on the web.

How do humans understand image content?

If you look around, you will see a lot of objects. You encounter many different objects every day, and you recognize them almost instantaneously without any effort. When you see a chair, you don't wait for a few minutes before realizing that it is in fact a chair. You just know that it's a chair right away.

Computers, on the other hand, find it very difficult to do this task. Researchers have been working for many years to find out why computers are not as good as we are at this.

To get an answer to that question, we need to understand how humans do it. The visual data processing happens in the ventral visual stream. This ventral visual stream refers to the pathway in our visual system that is associated with object recognition. It is basically a hierarchy of areas in our brain that helps us recognize objects.

Humans can recognize different objects effortlessly, and can cluster similar objects together. We can do this because we have developed some sort of invariance toward objects of the same class. When we look at an object, our brain extracts the salient points in such a way that factors such as orientation, size, perspective, and illumination don't matter.

A chair that is double the normal size and rotated by 45 degrees is still a chair. We can recognize it easily because of the way we process it. Machines cannot do that so easily. Humans tend to remember an object based on its shape and important features. Regardless of how the object is placed, we can still recognize it.

In our visual system, we build up these hierarchical invariances with respect to position, scale, and viewpoint that help us to be very robust. If you look deeper into our system, you will see that humans have cells in their visual cortex that can respond to shapes such as curves and lines.

As we move further along our ventral stream, we will see more complex cells that are trained to respond to more complex objects such as trees, gates, and so on. The neurons along our ventral stream tend to show an increase in the size of the receptive field. This is coupled with the fact that the complexity of their preferred stimuli increases as well.

Why is it difficult for machines to understand image content?

We now understand how visual data enters the human visual system, and how our system processes it. The issue is that we still don't fully understand how our brain recognizes and organizes this visual data. In machine learning, we just extract some features from images, and ask the computers to learn them using algorithms. We still have these variations, such as shape, size, perspective, angle, illumination, occlusion, and so on.

For example, the same chair looks very different to a machine when you look at it from the profile view. Humans can easily recognize that it's a chair, regardless of how it's presented to us. So, how do we explain this to our machines?

One way to do this would be to store all the different variations of an object, including sizes, angles, perspectives, and so on. But this process is cumbersome and time-consuming. Also, it's actually not possible to gather data that can encompass every single variation. The machines would consume a huge amount of memory and a lot of time to build a model that can recognize these objects.

Even with all this, if an object is partially occluded, computers still won't recognize it. This is because they think this is a new object. So when we build a computer vision library, we need to build the underlying functional blocks that can be combined in many different ways to formulate complex algorithms.

OpenCV provides a lot of these functions, and they are highly optimized. So once we understand what OpenCV is capable of, we can use it effectively to build interesting applications.

Let's go ahead and explore that in the next section.

What can you do with OpenCV?

Using OpenCV, you can pretty much do every computer vision task you can think of. Real-life problems require you to use many computer vision algorithms and modules together to achieve the desired result. So, you just need to understand which OpenCV modules and functions to use, in order to get what you want.

Let's look at what OpenCV can do out of the box.

Inbuilt data structures and input/output

One of the best things about OpenCV is that it provides a lot of in-built primitives to handle operations related to image processing and computer vision. If you have to write something from scratch, you will have to define Image, Point, Rectangle, and so on. These are fundamental to almost any computer vision algorithm.

OpenCV comes with all these basic structures out of the box, contained in the core module. Another advantage is that these structures have already been optimized for speed and memory, and so you don't have to worry about the implementation details.

The imgcodecs module handles reading and writing of image files. When you operate on an input image and create an output image, you can save it as a .jpg or a .png file with a simple command.

You will be dealing with a lot of video files when you work with cameras. The videoio module handles everything related to the input and output of video files. You can easily capture a video from the webcam or read a video file in many different formats. You can even save a bunch of frames as a video file by setting properties such as frames per second, frame size, and so on.

Image processing operations

When you write a computer vision algorithm, there are a lot of basic image processing operations that you will use over and over again. Most of these functions are present in the imgproc module. You can do things such as image filtering, morphological operations, geometric transformations, color conversions, drawing on images, histograms, shape analysis, motion analysis, feature detection, and more.

Let's consider the following photo:

The right image is a rotated version of the one on the left. We can carry out this transformation with a single line in OpenCV.

There is another module, called ximgproc, which contains advanced image processing algorithms such as structured forests for edge detection, domain transform filter, adaptive manifold filter, and so on.

GUI

OpenCV provides a module called highgui that handles all the high-level user interface operations. Let's say you are working on a problem, and you want to check what the image looks like before you proceed to the next step. This module has functions that can be used to create windows to display images and/or videos.

There is a waiting function that will wait until you hit a key on your keyboard before it goes on to the next step. There is also a function that can detect mouse events. This is very useful in developing interactive applications.

Using this functionality, you can draw rectangles on those input windows, and then proceed based on the selected region. Consider the following screenshot:

As you can see, we drew a green rectangle on top of the window. Once we have the coordinates of that rectangle, we can operate only on that region.

Video analysis

Video analysis includes tasks such as analyzing the motion between successive frames in a video, tracking different objects in a video, creating models for video surveillance, and so on. OpenCV provides a module called video that can handle all of this.

There is also a module called videostab that deals with video stabilization. Video stabilization is important, as when you are capturing videos by holding the camera in your hands, there's usually a lot of shake that needs correcting. All modern devices use video stabilization to process the video before it's presented to the end user.

3D reconstruction

3D reconstruction is an important topic in computer vision. Given a set of 2D images, we can reconstruct the 3D scene using relevant algorithms. OpenCV provides algorithms that can find the relationship between various objects in those 2D images to compute their 3D positions in its calib3d module.

This module can also handle camera calibration, which is essential for estimating the parameters of the camera. These parameters define how the camera sees the scene in front of it. We need to know these parameters to design algorithms, or else we might get unexpected results.

Let's consider the following diagram:

As we can see here, the same object is captured from multiple positions. Our job is to reconstruct the original object using these 2D images.

Feature extraction

As we discussed earlier, the human visual system tends to extract the salient features from a given scene to remember it for retrieval later. To mimic this, people started designing various feature extractors that can extract these salient points from a given image. Popular algorithms include Scale Invariant Feature Transform (SIFT), Speeded Up Robust Features (SURF), and Features From Accelerated Segment Test (FAST).

An OpenCV module called features2d provides functions to detect and extract all these features. Another module called xfeatures2d provides a few more feature extractors, some of which are still in the experimental phase. You can play around with these if you get the chance.

There is also a module called bioinspired that provides algorithms for biologically-inspired computer vision models.

Object detection

Object detection refers to detecting the location of an object in a given image. This process is not concerned with the type of object. If you design a chair detector, it will not tell you whether the chair in a given image is red with a high back, or blue with a low back—it will just tell you the location of the chair.

Detecting the location of objects is a critical step in many computer vision systems. Consider the following photo:

If you run a chair detector on this image, it will put a green box around all the chairs—but it won't tell you what kind of chair it is.

Object detection used to be a computationally-intensive task because of the number of calculations required to perform the detection at various scales. To solve this, Paul Viola and Michael Jones came up with a great algorithm in their seminal 2001 paper, which you can read at the following link: https://www.cs.cmu.edu/~efros/courses/LBMV07/Papers/viola-cvpr-01.pdf. They provided a fast way to design an object detector for any object.

OpenCV has modules called objdetect and xobjdetect that provide the framework to design an object detector. You can use it to develop detectors for random items such as sunglasses, boots, and so on.

Machine learning

Machine learning algorithms are used extensively to build computer vision systems for object recognition, image classification, face detection, visual search, and so on.

OpenCV provides a module called ml, which has many machine learning algorithms bundled into it, including a Bayes classifier, k-nearest neighbors (KNN), support vector machines (SVM), decision trees, neural networks, and more.

It also has a module called Fast Approximate Nearest Neighbor Search Library (FLANN), which contains algorithms for fast nearest neighbor searches in large datasets.

Computational photography

Computational photography refers to using advanced image processing techniques to improve the images captured by cameras. Instead of focusing on optical processes and image capture methods, computational photography uses software to manipulate visual data. Applications include high dynamic range imaging, panoramic images, image relighting, and light field cameras.

Let's look at the following image:

Look at those vivid colors! This is an example of a high dynamic range image, and it wouldn't be possible to get this using conventional image capture techniques. To do this, we have to capture the same scene at multiple exposures, register those images with each other, and then blend them nicely to create this image.

The photo and xphoto modules contain various algorithms that provide algorithms pertaining to computational photography. There is also a module called stitching that provides algorithms to create panoramic images.

Shape analysis

The notion of shape is crucial in computer vision. We analyze visual data by recognizing various different shapes in the image. This is actually an important step in many algorithms.

Let's say you are trying to identify a particular logo in an image. You know that it can appear in various shapes, orientations, and sizes. One good way to get started is to quantify the characteristics of the shape of the object.

The shape module provides all the algorithms required to extract different shapes, measure similarity between them, transform the shapes of objects, and more.

Optical flow algorithms

Optical flow algorithms are used in videos to track features across successive frames. Let's say you want to track a particular object in a video. Running a feature extractor on each frame would be computationally expensive; hence, the process would be slow. So, you just extract the features from the current frame, and then track those features in successive frames.

Optical flow algorithms are heavily used in video-based applications in computer vision. The optflow module contains all the algorithms required to perform optical flow. There is also a module called tracking that contains more algorithms that can be used to track features.

Face and object recognition

Face recognition refers to identifying the person in a given image. This is not the same as face detection, where you simply identify the location of a face in the given image.

If you want to build a practical biometric system that can recognize the person in front of the camera, you first need to run a face detector to identify the location of the face, and then run a separate face recognizer to identify who the person is. There is an OpenCV module called face that deals with face recognition.

As we discussed earlier, computer vision tries to model algorithms based on how humans perceive visual data. So, it would be helpful to find salient regions and objects in the images that can help with different applications such as object recognition, object detection and tracking, and so on. There is a module called saliency that's designed for this purpose. It provides algorithms that can detect salient regions in static images and videos.

Surface matching

We are increasingly interacting with devices that can capture the 3D structure of the objects around us. These devices essentially capture depth information, along with the regular 2D color images. So, it's important for us to build algorithms that can understand and process 3D objects.

Kinect is a good example of a device that captures depth information along with the visual data. The task at hand is to recognize the input 3D object, by matching it to one of the models in our database. If we have a system that can recognize and locate objects, then it can be used for many different applications.

There is a module called surface_matching that contains algorithms for 3D object recognition and a pose estimation algorithm using 3D features.

Text detection and recognition

Identifying text in a given scene and recognizing the content is becoming increasingly important. Applications include number plate recognition, recognizing road signs for self-driving cars, book scanning to digitize content, and more.

There is a module called text that contains various algorithms to handle text detection and recognition.

Deep learning

Deep learning has a big impact on computer vision and image recognition, and achieves a higher level of accuracy than other machine learning and artificially intelligent algorithms. Deep learning is not a new concept; it was introduced to the community around 1986, but it started a revolution around 2012 when new GPU hardware was optimized for parallel computing and Convolutional Neural Network (CNN) implementations and other techniques allowed the training of complex neural network architectures in reasonable times.

Deep learning can be applied to multiple use cases such as image recognition, object detection, voice recognition, and natural language processing. Since version 3.4, OpenCV has been implementing deep learning algorithmsin the latest version, multiple importers for important frameworks such as TensorFlow and Caffe have been added.

Installing OpenCV

Let's see how to get OpenCV up and running on various operating systems.

Windows

To keep things easy, let's install OpenCV using pre-built libraries. Go to opencv.org and download the latest version for Windows. The current version is 4.0.0, and you can get the download link from the OpenCV homepage. You should make sure you have admin rights before you proceed.

The downloaded file will be an executable file, so just double-click on it to start the installation. The installer expands the content into a folder. You will be able to choose the installation path, and check the installation by inspecting the files.

Once you are done with the previous step, we need to set the OpenCV environment variables and add them to the system path to complete the installation. We will set up an environment variable that will hold the build directory of the OpenCV library. We will be using this in our projects.

Open up the Terminal and type the following:

C:> setx -m OPENCV_DIR D:OpenCVBuildx64vc14
We are assuming that you have a 64-bit machine with Visual Studio 2015 installed. If you have Visual Studio 2012, replace vc14 with vc11 in the command. The path specified is where we would have our OpenCV binaries, and you should see two folders inside that path called lib and bin. If you are using Visual Studio 2018, you should compile OpenCV from scratch.

Let's go ahead and add a path to the bin folder to our system path. The reason we need to do this is because we will be using the OpenCV library in the form of dynamic link libraries (DLLs). Essentially, all the OpenCV algorithms are stored here, and our operating system will only load them during runtime.

In order to do that, our operating system needs to know where they are located. The PATH system variable contains a list of all the folders where it can find DLLs. So, naturally, we need to add the path of the OpenCV library to this list.

Why do we need to do all this? Well, the other option is to copy the required DLLs in the same folder as the application's executable file (.exe file). This is an unnecessary overhead, especially when we are working with many different projects.

We need to edit the PATH variable to add this folder. You can use software such as Path Editor to do this, which you can download from here: https://patheditor2.codeplex.com. Once you install it, start it up and add the following new entry (you can right-click on the path to insert a new item):

%OPENCV_DIR%bin

Go ahead and save it to the registry. We are done!

Mac OS X

In this section, we will see how to install OpenCV on Mac OS X. Precompiled binaries are not available for Mac OS X, so we need to compile OpenCV from scratch.

Before we proceed, we need to install CMake. If you don't already have CMake installed, you can download it from here: https://cmake.org/files/v3.12/cmake-3.12.0-rc1-Darwin-x86_64.dmg. It's a .dmg file, so once you download it, just run the installer.

Download the latest version of OpenCV from opencv.org. The current version is 4.0.0, and you can download it from here: https://github.com/opencv/opencv/archive/4.0.0.zip. Unzip the contents into a folder of your choice.

OpenCV 4.0.0 also has a new package called opencv_contrib, containing user contributions that are not yet considered stable, and some algorithms that are not freely available for commercial use in all the latest computer vision algorithms, which is worth keeping in mind. Installing this package is optionalOpenCV will work just fine if you don't install opencv_contrib.

Since we are installing OpenCV anyway, it's good to install this package so that you can experiment with it later on (as opposed to going through the whole installation process again). It is a great way to learn and play around with new algorithms. You can download it from the following link: https://github.com/opencv/opencv_contrib/archive/4.0.0.zip.

Unzip the contents of the zip file into a folder of your choice. For convenience, unzip it into the same folder as before, so that the opencv-4.0.0 and opencv_contrib-4.0.0 folders are in the same main folder.

We are now ready to build OpenCV. Open up your Terminal and navigate to the folder where you unzipped the contents of OpenCV 4.0.0. Run the following commands after substituting the right paths in the commands:

$ cd /full/path/to/opencv-4.0.0/ 
$ mkdir build 
$ cd build 
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/full/path/to/opencv-4.0.0/build -D INSTALL_C_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/full/path/to/opencv_contrib-4.0.0/modules ../ 

It's time to install OpenCV 4.0.0. Go to the /full/path/to/opencv-4.0.0/build directory, and run the following commands on your Terminal:

$ make -j4 
$ make install 

In the preceding command, the -j4 flag indicates that it should be using four cores to install it. It's faster this way! Now, let's set the library path. Open up your ~/.profile file in your Terminal using the vi ~/.profile command, and add the following line:

export DYLD_LIBRARY_PATH=/full/path/to/opencv-4.0.0/build/lib:$DYLD_LIBRARY_PATH

We need to copy the pkgconfig file in opencv.pc to /usr/local/lib/pkgconfig and name it opencv4.pc. This way, if you already have an existing OpenCV 3.x.x installation, there will be no conflict. Let's go ahead and do that:

$ cp /full/path/to/opencv-4.0.0/build/lib/pkgconfig/opencv.pc /usr/local/lib/pkgconfig/opencv4.pc 

We need to update our PKG_CONFIG_PATH variable as well. Open up your ~/.profile file and add the following line:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH 

Reload your ~/.profile file using the following command:

$ source ~/.profile 

We're finished! Let's see if it's working:

$ cd /full/path/to/opencv-4.0.0/samples/cpp 
$ g++ -ggdb `pkg-config --cflags --libs opencv4` opencv_version.cpp -o /tmp/opencv_version && /tmp/opencv_version

If you see Welcome to OpenCV 4.0.0 printed on your Terminal, you are good to go. We will be using CMake to build our OpenCV projects throughout this book. We will cover it in more detail in Chapter 2, An Introduction to the Basics of OpenCV.

Linux

Let's see how to install OpenCV on Ubuntu. We need to install some dependencies before we begin. Let's install them using the package manager by running the following command in your Terminal:

$ sudo apt-get -y install libopencv-dev build-essential cmake libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils 

Now that you have installed the dependencies, let's download, build, and install OpenCV:

$ wget "https://github.com/opencv/opencv/archive/4.0.0.tar.gz" -O opencv.tar.gz 
$ wget "https://github.com/opencv/opencv_contrib/archive/4.0.0.tar.gz" -O opencv_contrib.tar.gz 
$ tar -zxvf opencv.tar.gz 
$ tar -zxvf opencv_contrib.tar.gz 
$ cd opencv-4.0.0 
$ mkdir build 
$ cd build 
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/full/path/to/opencv-4.0.0/build -D INSTALL_C_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/full/path/to/opencv_contrib-4.0.0/modules ../ 
$ make -j4 
$ sudo make install 

Let's copy the pkgconfig file in opencv.pc to /usr/local/lib/pkgconfig, and name it opencv4.pc:

$ cp /full/path/to/opencv-4.0.0/build/lib/pkgconfig/opencv.pc /usr/local/lib/pkgconfig/opencv4.pc 

We're finished! We will now be able to use it to compile our OpenCV programs from the command line. Also, if you already have an existing OpenCV 3.x.x installation, there will be no conflict.

Let's check the installation is working properly:

$ cd /full/path/to/opencv-4.0.0/samples/cpp 
$ g++ -ggdb `pkg-config --cflags --libs opencv4` opencv_version.cpp -o /tmp/opencv_version && /tmp/opencv_version 

If you see Welcome to OpenCV 4.0.0 printed on your Terminal, you should be good to go. In the following chapters, we will learn how to use CMake to build our OpenCV projects.

Summary

In this chapter, we discussed the human visual system, and how humans process visual data. We explained why it's difficult for machines to do the same, and what we need to consider when designing a computer vision library.

We learned what could be done using OpenCV, and the various modules that can be used to complete those tasks. Finally, we learned how to install OpenCV in various operating systems.

In the next chapter, we will discuss how to operate on images and how we can manipulate them using various functions. We will also learn about building a project structure for our OpenCV applications.

Left arrow icon Right arrow icon

Key benefits

  • Understand basic OpenCV 4 concepts and algorithms
  • Grasp advanced OpenCV techniques such as 3D reconstruction, machine learning, and artificial neural networks
  • Work with Tesseract OCR, an open-source library to recognize text in images

Description

OpenCV is one of the best open source libraries available, and can help you focus on constructing complete projects on image processing, motion detection, and image segmentation. Whether you’re completely new to computer vision, or have a basic understanding of its concepts, Learn OpenCV 4 by Building Projects – Second edition will be your guide to understanding OpenCV concepts and algorithms through real-world examples and projects. You’ll begin with the installation of OpenCV and the basics of image processing. Then, you’ll cover user interfaces and get deeper into image processing. As you progress through the book, you'll learn complex computer vision algorithms and explore machine learning and face detection. The book then guides you in creating optical flow video analysis and background subtraction in complex scenes. In the concluding chapters, you'll also learn about text segmentation and recognition and understand the basics of the new and improved deep learning module. By the end of this book, you'll be familiar with the basics of Open CV, such as matrix operations, filters, and histograms, and you'll have mastered commonly used computer vision techniques to build OpenCV projects from scratch.

Who is this book for?

If you are a software developer with a basic understanding of computer vision and image processing and want to develop interesting computer vision applications with OpenCV, Learn OpenCV 4 by Building Projects for you. Prior knowledge of C++ will help you understand the concepts covered in this book.

What you will learn

  • Install OpenCV 4 on your operating system
  • Create CMake scripts to compile your C++ application
  • Understand basic image matrix formats and filters
  • Explore segmentation and feature extraction techniques
  • Remove backgrounds from static scenes to identify moving objects for surveillance
  • Employ various techniques to track objects in a live video
  • Work with new OpenCV functions for text detection and recognition with Tesseract
  • Get acquainted with important deep learning tools for image classification
Estimated delivery fee Deliver to Greece

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 30, 2018
Length: 310 pages
Edition : 2nd
Language : English
ISBN-13 : 9781789341225
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Greece

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

Product Details

Publication date : Nov 30, 2018
Length: 310 pages
Edition : 2nd
Language : English
ISBN-13 : 9781789341225
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 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
€189.99 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 €5 each
Feature tick icon Exclusive print discounts
€264.99 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 €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 111.97
Hands-On Image Processing with Python
€37.99
Learn OpenCV 4 by Building Projects
€36.99
Mastering OpenCV 4
€36.99
Total 111.97 Stars icon
Banner background image

Table of Contents

13 Chapters
Getting Started with OpenCV Chevron down icon Chevron up icon
An Introduction to the Basics of OpenCV Chevron down icon Chevron up icon
Learning Graphical User Interfaces Chevron down icon Chevron up icon
Delving into Histogram and Filters Chevron down icon Chevron up icon
Automated Optical Inspection, Object Segmentation, and Detection Chevron down icon Chevron up icon
Learning Object Classification Chevron down icon Chevron up icon
Detecting Face Parts and Overlaying Masks Chevron down icon Chevron up icon
Video Surveillance, Background Modeling, and Morphological Operations Chevron down icon Chevron up icon
Learning Object Tracking Chevron down icon Chevron up icon
Developing Segmentation Algorithms for Text Recognition Chevron down icon Chevron up icon
Text Recognition with Tesseract Chevron down icon Chevron up icon
Deep Learning with OpenCV 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 Half star icon Empty star icon Empty star icon 2.5
(2 Ratings)
5 star 0%
4 star 50%
3 star 0%
2 star 0%
1 star 50%
Kohei Yoshida Apr 24, 2019
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I'm almost finishing up this book, and I think I have seen enough to give it a review. I'm new to OpenCV but I'm pretty experienced with CMake, and I built OpenCV directly from its source from its github repo in order to follow this book. So, I can't comment on the quality and accuracy of the installation guide in this book since I skipped that part.The rest of the book's content is quite decent, and gave me a very good overview of what sort of functionality is provided by OpenCV. I've noticed some minor errors in the example codes, but nothing that some debugging can't resolve.I also recommend you follow this book on Linux if you have that option. You need access to a webcam since many of the examples do make use of video feeds from camera.I'm also planning on buying a copy of Mastering OpenCV 4 after I finish this book, to further deepen my knowledge of OpenCV.
Amazon Verified review Amazon
Bad Review Apr 01, 2019
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Installation guide is not useful. Either it is not updated or incomplete. Some libraries on the dependencies are no longer there.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela