Book Image

Computer Vision with Python 3

By : Saurabh Kapur
Book Image

Computer Vision with Python 3

By: Saurabh Kapur

Overview of this book

<p>This book is a thorough guide for developers who want to get started with building computer vision applications using Python 3. The book is divided into five sections: The Fundamentals of Image Processing, Applied Computer Vision, Making Applications Smarter,Extending your Capabilities using OpenCV, and Getting Hands on. Throughout this book, three image processing libraries Pillow, Scikit-Image, and OpenCV will be used to implement different computer vision algorithms.</p> <p>The book aims to equip readers to build Computer Vision applications that are capable of working in real-world scenarios effectively. Some of the applications that we will look at in the book are Optical Character Recognition, Object Tracking and building a Computer Vision as a Service platform that works over the internet.</p>
Table of Contents (17 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
7
Introduction to Computer Vision using OpenCV

Preface

Computer vision has gone through significant advancements over the last few years. These advancements have not only made a great impact of computer science but also of other fields, such as medicine, space exploration, and defense. From microscopic organisms to celestial particles light-years away, using computer vision techniques researchers are able to analyze their images to make progress in these fields. Computer vision is now being used as a tool to facilitate research and development in many other fields.

Going forward, the impact of computer vision will have an even greater impact—the most recent application being driverless cars. To be able to be a part of this ongoing revolution, it is important that we are able to understand and implement computer vision algorithms. This book will introduce the reader to three computer vision libraries written for Python—Pillow, Scikit-image, and OpenCV. Through examples and code snippets, the book will help the reader understand the basics of image processing, morphological operations, and eventually, complex feature detection algorithms.

What this book covers

Chapter 1, Introduction to Image Processing, as the name suggests, introduces the reader to the basics of image processing. Starting with some common use cases of image processing, the chapter goes on to explain how to install different image processing libraries. The next few sections in the chapter explain how to read/write an image and perform basic image manipulation operations.

Chapter 2, Filters and Features, gives the reader an overview of what filters and features mean in the context of computer vision. We start with convolution, which forms the basis of applying any filter to an image. Then we look at some common filters, such as Gaussian Blur and Median Blur. The second half of the chapter explains the basic image features and how they are implemented using Python.

Chapter 3, Drilling Deeper into Features – Object Detection, walks the reader through some of the sophisticated image feature extraction algorithms, such as Local Binary Pattern and ORB. These algorithms help to identify objects in an image and match them with other images that have the same objects in them. Such matching algorithms form the basis of the most complex computer vision algorithms.

Chapter 4, Segmentation – Understanding Images Better, has a different theme than the last two chapters. This chapter looks at different image segmentation algorithms, namely, contour detection, superpixels, watershed, and normalized graph cut. These algorithms are fairly easy to implement and run in almost real time. Image segmentation can be use in real-world applications such as background subtraction, image understanding, and scene labeling. Recent advances in machine learning, especially deep learning, have enabled more sophisticated methods of image segmentation that involve almost no manual tuning of parameters.

Chapter 5, Integrating Machine Learning with Computer Vision, brings together two different fields together. This chapter shows how machine learning algorithms can be implemented for images. We implement a classic image classification program for digit recognition.

Chapter 6, Image Classification Using Neural Networks, is an extension of the last chapter. In this chapter, we implement digit classification using advanced machine learning technique called neural networks. We install a new library called Keras to implement the neural network.

Chapter 7, Introduction to Computer Vision Using OpenCV, introduces the readers to a new computer vision library called OpenCV. In this chapter, we revisit all the image processing concepts and algorithms that we have read so far in the book and implement them using OpenCV.

Chapter 8Object Detection Using OpenCV, explains different feature extraction algorithms and we will be using OpenCV to implement all the algorithms.

Chapter 9, Video Processing Using OpenCV, explains how to work with videos instead of images. The chapter uses code snippets to walk the reader through how to capture and save a video. It then explains how to perform operations such as resizing and changing the color space in videos. In the last section, we see how to implement object tracking in videos.

Chapter 10, Computer Vision as a Service, is the last chapter and it provides an overview of how production-scale computer vision systems are built. The chapter focuses on the infrastructure that is needed for computer vision algorithms. A simple computer vision service is implemented, giving the readers a flavor of how services such as Google Image search are built.

What you need for this book

The software required for this book are as follows:

  • Python 3.5
  • Pillow 4.0
  • Scikit-image (Skimage) 0.13.0
  • OpenCV 3.2
  • Sklearn 0.18
  • Keras 2.0
  • Flask 0.12.2

Who this book is for

The book is ideal for developers who have basic knowledge of Python and want to build a strong foundation in implementing computer vision algorithms. The book is also suitable for developers with theoretical knowledge of computer vision but who lack the experience of implementing the algorithms.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows:

"To save or write an image we can use the imsave() function."

A block of code is set as follows:

>>> from PIL import Image
>>> img = Image.open("image.png")
>>> img.getpixel((100,100))
output
(150, 188, 233, 255)
>>> img.convert("L").getpixel((100,100))

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

>>> from skimage import io
 >>> img = io.imread("image.png")
 >>> io.imshow("image.png")
 >>> io.show()

Any command-line (including commands in the R console) input or output is written as follows:

$: pip install Pillow

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes, for example, appear in the text like this: "Clicking the Next button moves you to the next screen."

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important to us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply email [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your email address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Computer-Vision-with-Python-3. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/ComputerVisionwithPython3_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.