Reader small image

You're reading from  OpenCV By Example

Product typeBook
Published inJan 2016
Reading LevelIntermediate
PublisherPackt
ISBN-139781785280948
Edition1st Edition
Languages
Tools
Right arrow
Authors (3):
Prateek Joshi
Prateek Joshi
author image
Prateek Joshi

Prateek Joshi is the founder of Plutoshift and a published author of 9 books on Artificial Intelligence. He has been featured on Forbes 30 Under 30, NBC, Bloomberg, CNBC, TechCrunch, and The Business Journals. He has been an invited speaker at conferences such as TEDx, Global Big Data Conference, Machine Learning Developers Conference, and Silicon Valley Deep Learning. Apart from Artificial Intelligence, some of the topics that excite him are number theory, cryptography, and quantum computing. His greater goal is to make Artificial Intelligence accessible to everyone so that it can impact billions of people around the world.
Read more about Prateek Joshi

David Millán Escrivá
David Millán Escrivá
author image
David Millán Escrivá

David Millán Escrivá was 8 years old when he wrote his first program on an 8086 PC in Basic, which enabled the 2D plotting of basic equations. In 2005, he finished his studies in IT with honors, through the Universitat Politécnica de Valencia, in human-computer interaction supported by computer vision with OpenCV (v0.96). He has worked with Blender, an open source, 3D software project, and on its first commercial movie, Plumiferos, as a computer graphics software developer. David has more than 10 years' experience in IT, with experience in computer vision, computer graphics, pattern recognition, and machine learning, working on different projects, and at different start-ups, and companies. He currently works as a researcher in computer vision.
Read more about David Millán Escrivá

Vinícius G. Mendonça
Vinícius G. Mendonça
author image
Vinícius G. Mendonça

Vinícius G. Mendonça is a professor at PUCPR and a mentor at Apple Developer Academy. He has a master's degree in Computer Vision and Image Processing (PUCPR) and a specialization degree in Game Development (Universidade Positivo). He is also one of the authors of the book Learn OpenCV 4 by Building Projects, also by Packt Publishing. He has been in this field since 1996. His former experience includes designing and programming a multithreaded framework for PBX tests at Siemens, coordination of Aurélio Dictionary software (including its apps for Android, IOS, and Windows phones), and coordination of an augmented reality educational activity for Positivo's Mesa Alfabeto, presented at CEBIT. Currently, he works with server-side Node.js at a company called Tenet Tech.
Read more about Vinícius G. Mendonça

View More author details
Right arrow

Chapter 6. Learning Object Classification

In the previous chapter, we introduced you to the basic concepts of object segmentation and detection. This means isolating the objects that appear in an image for future processing and analysis.

This chapter covers how to classify each of these isolated objects. In order to allow us to classify each object, we need to train our system to be capable of learning the required parameters to decide which specific label should be assigned to the detected object (depending on the different categories taken into account during the training phase).

This chapter is going to introduce you to the basic concepts of machine learning to classify images with different labels.

We will create a basic application based on the segmentation algorithm, as discussed in Chapter 5, Automated Optical Inspection, Object Segmentation, and Detection. This segmentation algorithm extracts parts of an image, which contains objects. For each object, we will extract the different features...

Introducing machine learning concepts


Machine learning is an old concept that was defined in 1959 by Arthur Samuel as a field of study that gives computers the ability to learn without being explicitly programmed. Tom. M. Mitchel provided a more formal definition. In this definition, Tom links the concept of samples or experiences, labels, and performance measurements.

Note

The machine learning definition by Arthur Samuel is referenced from Some Studies in Machine Learning Using the Game of Checkers in the IBM Journal of Research and Development (Volume: 3, Issue: 3), p. 210 and a phrase in The New Yorker and Office Management the same year.

The more formal definition by Tom. M. Mitchel is referenced from Machine Learning Book, McGray Hill 1997 (http://www.cs.cmu.edu/afs/cs.cmu.edu/user/mitchell/ftp/mlbook.html).

Machine learning involves pattern recognition and the learning theory in artificial intelligence and is related to computational statistics.

Machine learning is used in hundreds of applications...

Computer Vision and the machine learning workflow


The Computer Vision applications with machine learning have a common basic structure. This structure is divided into different steps that are repeated in almost all Computer Vision applications, and some others are omitted. In the following diagram, we show you the different steps involved:

Almost any Computer Vision application starts with a preprocessing stage that is applied to the input image. Preprocessing involves light removal conditions and noise, thresholding, blur, and so on.

After we apply all the preprocessing steps required to the input image, the second step is segmentation. In the segmentation step, we need to extract the regions of interest of an image and isolate each one as a unique object of interest. For example, in a face detection system, we need to separate the faces from the rest of the parts in the scene.

After getting the objects inside the image, we continue with the next step. We need to extract all the features of...

Automatic object inspection classification example


Continuing with the example of the previous chapter, the automatic object inspection segmentation, where a carrier tape contains three different types of objects (nuts, screws, and rings), and with Computer Vision, we will be able to recognize each one of them to send notifications to a robot or similar to put each one in different boxes.

In Chapter 5, Automated Optical Inspection, Object Segmentation, and Detection, we preprocessed the input images and extracted the regions of interest of images and isolated each object using different techniques. Now, we will apply all these concepts, as explained in previous sections, in this example to extract features and classify each object and allow to possible robot to put each one in different boxes. In our application, we are only going to show the labels of each image in an image, but we can send the positions in the image and the labels to other devices as a robot.

Then, our goal is from an input...

Feature extraction


Now, let's extract the features of each object. To understand the feature concept of a feature vector, we will extract very simple features, but it is enough to get good results. In other solutions, we can get more complex features, such as texture descriptors, contour descriptors, and so on.

In our example, we only have these three types of objects, nuts, rings, and screws, in different possible positions. All these possible objects and positions are shown in the following figure:

We will explore the good characteristics that will help the computer to identify each object. The characteristics are as follows:

  • The area of an object

  • The aspect ratio, which is the width divided by the height of the bounding rectangle

  • The number of holes

  • The number of contour sides

These characteristics can describe our objects very well, and if we use all of them, the classification error can be very small. However, in our implemented example, we will use only the first two characteristics, the...

Summary


In this chapter, we learned the basics of the machine learning model and how to apply a small sample application to understand all the basic tips required to create our own ML application.

Machine learning is complex and involves different techniques for each use case (supervised learning, unsupervised, clustering, and so on), and we learned how to create the most typical ML application and the supervised learning with an SVM.

The most important concepts in supervised machine learning are: first, we need to have an appropriate number of samples or datasets; and second, we need to correctly choose the features that describe our objects correctly. For more information on image features, refer to Chapter 8, Video Surveillance, Background Modeling, and Morphological Operations. Third, choose the best model that gives us the best predictions.

If we don't reach the correct predictions we have to check each one of these concepts to look for where the issue is.

In the next chapter, we will introduce...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
OpenCV By Example
Published in: Jan 2016Publisher: PacktISBN-13: 9781785280948
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.
undefined
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

Authors (3)

author image
Prateek Joshi

Prateek Joshi is the founder of Plutoshift and a published author of 9 books on Artificial Intelligence. He has been featured on Forbes 30 Under 30, NBC, Bloomberg, CNBC, TechCrunch, and The Business Journals. He has been an invited speaker at conferences such as TEDx, Global Big Data Conference, Machine Learning Developers Conference, and Silicon Valley Deep Learning. Apart from Artificial Intelligence, some of the topics that excite him are number theory, cryptography, and quantum computing. His greater goal is to make Artificial Intelligence accessible to everyone so that it can impact billions of people around the world.
Read more about Prateek Joshi

author image
David Millán Escrivá

David Millán Escrivá was 8 years old when he wrote his first program on an 8086 PC in Basic, which enabled the 2D plotting of basic equations. In 2005, he finished his studies in IT with honors, through the Universitat Politécnica de Valencia, in human-computer interaction supported by computer vision with OpenCV (v0.96). He has worked with Blender, an open source, 3D software project, and on its first commercial movie, Plumiferos, as a computer graphics software developer. David has more than 10 years' experience in IT, with experience in computer vision, computer graphics, pattern recognition, and machine learning, working on different projects, and at different start-ups, and companies. He currently works as a researcher in computer vision.
Read more about David Millán Escrivá

author image
Vinícius G. Mendonça

Vinícius G. Mendonça is a professor at PUCPR and a mentor at Apple Developer Academy. He has a master's degree in Computer Vision and Image Processing (PUCPR) and a specialization degree in Game Development (Universidade Positivo). He is also one of the authors of the book Learn OpenCV 4 by Building Projects, also by Packt Publishing. He has been in this field since 1996. His former experience includes designing and programming a multithreaded framework for PBX tests at Siemens, coordination of Aurélio Dictionary software (including its apps for Android, IOS, and Windows phones), and coordination of an augmented reality educational activity for Positivo's Mesa Alfabeto, presented at CEBIT. Currently, he works with server-side Node.js at a company called Tenet Tech.
Read more about Vinícius G. Mendonça