23,99 €
Starting from the basics of computer vision and OpenCV, we'll take you all the way to creating exciting applications. You will discover that, though computer vision is a challenging subject, the ideas and algorithms used are simple and intuitive, and you will appreciate the abstraction layer that OpenCV uses to do the heavy lifting for you. Packed with many examples, the book will help you understand the main data structures used within OpenCV, and how you can use them to gain performance boosts. Next we will discuss and use several image processing algorithms such as histogram equalization, filters, and color space conversion. You then will learn about image gradients and how they are used in many shape analysis techniques such as edge detection, Hough Line Transform, and Hough Circle Transform. In addition to using shape analysis to find things in images, you will learn how to describe objects in images in a more robust way using different feature detectors and descriptors.
By the end of this book, you will be able to make intelligent decisions using the famous Adaboost learning algorithm.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 182
Veröffentlichungsjahr: 2015
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: December 2015
Production reference: 1071215
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78355-059-3
www.packtpub.com
Author
Amgad Muhammad
Reviewers
Noritsuna Imamura
André Moreira
Commissioning Editor
Neil Alexander
Acquisition Editor
Meeta Rajani
Content Development Editor
Mayur Pawanikar
Technical Editor
Manthan Raja
Copy Editor
Tasneem Fatehi
Project Coordinator
Nidhi Joshi
Proofreader
Safis Editing
Indexer
Monica Ajmera Mehta
Graphics
Ahmed H. Alley
Kirk D'Penha
Jason Monteiro
Production Coordinator
Arvindkumar Gupta
Cover Work
Arvindkumar Gupta
Amgad Muhammad has a master's degree in computer science from the American University in Cairo. He is a data scientist passionate about building and designing machine learning models and engineering features in computer vision research. He started working with computer vision in 2011, and now he is developing state-of-the-art machine learning and computer vision algorithms in the field of biometric extraction and registration, including face and person detection, human tracking, and 2D/3D-based pose estimation.
First, I would like to thank my lovely wife, Noha, and my beautiful kids, Zain, Hla, and Darine, for their continuous care so that I could finish this book. The book is the fruit of my family's support and understanding, in spite of all the time it took me away from them, and all the weekends I spent in front of my computer. It was really a challenging and long journey, having a full-time job and my graduate studies while writing this book, but, as a loving and caring family, we were able to pull through.
I would also like to thank my best friend, Ahmed Hassan Alley, for the beautiful graphics and illustrations. And I would like to thank Mayur Pawanikar, Manthan Raja, and Meeta Rajani for helping me throughout the editing process; they made it really easy.
Noritsuna Imamura is a specialist in embedded Linux/Android-based computer vision, and is one of the main members of SIProp.org (http://www.siprop.org/). His main works are as follows:
He can be contacted via e-mail at <[email protected]>.
André Moreira received his master's degree in computer science from Pontifical Catholic University of Rio de Janeiro, Brazil in 2015. Currently he is PhD candidate in the same university.
He graduated with a bachelor's degree in computer science from Universidade Federal do Maranhão (UFMA) in Brazil. During his undergraduate degree, he was a member of Labmint's research team and worked with medical imaging, specifically breast cancer detection and diagnosis using image processing.
Currently, he works as a researcher and system analyst at Instituto Tecgraf, one of the major research and development labs in computer graphics in Brazil. He has been working extensively with PHP, HTML, and CSS since 2007. Nowadays, he develops projects in C++11/C++14, along with SQLite, Qt, Boost, and OpenGL. More information about him can be acquired on his personal website at www.andredsm.com.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
To my wife, Noha, and my children, Zain, Hla, and Darine
Learn how to use OpenCV to develop vision-aware, intelligent Android applications in a step-by-step tutorial and join the interesting and rapidly expanding field of computer vision to enable your Android phone to make sense of the world.
Starting from the basics of computer vision and OpenCV, we'll take you through all the ways to create exciting applications. You will discover that although computer vision is a challenging subject, the ideas and algorithms used are simple and intuitive, and you will appreciate the abstraction layer that OpenCV offers in order to do the heavy lifting for you.
Packed with many examples, the book will help you understand the main data structures used in OpenCV, and how you can use them to gain performance boosts. Next, we will discuss and use several image processing algorithms, such as histogram equalization, filters, and color space conversion. You then will learn about image gradients and how they are used in many shape analysis techniques, such as edge detection, Hough line transform, and Hough circle transform. In addition to using shape analysis to find things in images, you will learn how to describe objects in images in a more robust way using different feature detectors and descriptors. Finally, you will be able to make intelligent decisions using machine learning, specifically, the famous adaptive boosting learning algorithm and cascade classifiers.
Chapter 1, Getting Yourself Ready, explains how to start using OpenCV to develop vision-aware Android applications in a step-by-step fashion.
Chapter 2, App 1 - Building Your Own Darkroom, shows you how images are stored and represented in OpenCV, and how to utilize this representation to implement interesting algorithms that will enhance the way your images look.
Chapter 3, App 2 - Software Scanner, explains how to implement your next application, a software scanner. It allows people to take a photo of, let's say, a receipt, and apply some transformations to make it look as if it was scanned. In this chapter, we will introduce two important topics that will help us to reach our final goal.
The first topic will be about spatial filtering and its definition and applications. The second topic will be about a famous shape analysis technique called the Hough transform. You will learn about the basic idea behind this technique that has made it very popular and widely used, and we will use the OpenCV implementation to start fitting lines and circles to a set of edge pixels.
Chapter 4, App 2 - Applying Perspective Correction, continues to build on the application that we started in Chapter 3. We will use the concepts that you've learned, namely, the edge detection and Hough line transform, to do perspective correction to a quadrilateral object. Applying perspective transformation to an object will change the way that we see it; this idea will come in handy when you take pictures of documents, receipts, and so on, and you want to a have better view of the captured image or a scan-like copy.
Chapter 5, App 3 - Panoramic Viewer, starts working on a new application. The goal of the application is to stitch two images together in order to form a panoramic view, and in this chapter, we will introduce the concept of image features and why they are important, and we will see them in action.
Chapter 6, App 4 – Automatic Selfie, introduces a new application. The goal of the application is to be able to take a selfie without touching your phone's screen. Your application will be able to detect a certain hand gesture that will trigger the process of saving the current camera frame.
If you are an Android developer and want to know how to implement vision-aware applications using OpenCV, then this book is definitely for you.
It would be very helpful if you understand the basics of image processing and computer vision, but no prior experience is required.
In this book, you will find a number of text styles 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 uninstall the previous installation, go to the previous installation directory and run tadp_uninstall.exe."
A block of code is set as follows:
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "You will need to choose the type of the installation. Select a custom installation and click Next."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
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 for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[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.
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.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
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/0593OS_ColorImages.pdf.
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 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.
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.
In this chapter, I will explain, in a step-by-step fashion, how to start using OpenCV to develop vision-aware Android applications.
The Open Source Computer Vision (OpenCV) software library has over 2,500 optimized algorithms; the library includes a comprehensive set of both classic and state-of-the-art computer vision and machine learning algorithms. It has been around for a decade and released under the Berkeley Software Distribution (BSD) license, making it easy for users to utilize and modify the code.
OpenCV is downloaded over seven million times and used by well-established companies such as Google, Yahoo, Microsoft, Intel, IBM, Sony, and Honda. Moreover, OpenCV supports several desktop and mobile operating systems including Windows, Linux, Mac OS X, Android, and iOS.
In this book, we will work with OpenCV for Android, which is a part of OpenCV that runs on the Android operating system.
I'll be covering two scenarios for the installation and to get ready; first, if you are starting a clean installation for Android, it is recommended that you start with Tegra Android Development Pack (TADP). The other scenario is a manual setup of every component needed to run Android with OpenCV. You would probably go with this option if you already have a previous installation of the Android development environment. We will cover the following topics:
TADP was released by NVIDIA to make the preparation for the Android development environment a seamless process.
NVIDIA has released TADP version 3.0r4 to support Android SDK (23.0.2), NDK (r10c), and OpenCV for Tegra 2.4.8.2, which is a regular OpenCV4Android SDK extended with Tegra-specific optimizations.
To get TADP, visit https://developer.nvidia.com/tegra-android-development-pack and follow the steps to become a registered developer; it is a free membership.
Once you have your membership activated, log in and download the version corresponding to your operating system. NVIDIA supports the following operating systems:
In my case, I have Windows 7 64-bit on my machine, so from now on, all the upcoming steps are tested and working fine on this operating system. However, I don't expect any major changes if you are working with a different operating system.
For the Ubuntu installation, TADP will need you to have root privileges, so make sure that you do.
Once you finish downloading the TADP installer, launch it and perform the following steps:
Note that if you have a previous installation, you will get a warning message that the previous installation needs to be uninstalled. To uninstall the previous installation, go to the previous installation directory and run tadp_uninstall.exe.
Sometimes, the uninstaller doesn't clean everything. In this case, you need to delete the contents of the previous installation directory manually.
Sometimes, the installer window will not respond; this is okay. After a few minutes, the installation will continue in a normal way.
Yes, TADP will download and install everything for you; yet you still need to do some post-installation configuration in order to make sure that everything will work properly.
You need to install a system image for every Android SDK platform installed in case you want to run an emulator with this SDK platform as a target.
To do so, just follow these simple steps:
