29,99 €
If you are a Java developer, student, researcher, or hobbyist wanting to create computer vision applications in Java then this book is for you. If you are an experienced C/C++ developer who is used to working with OpenCV, you will also find this book very useful for migrating your applications to Java.
All you need is basic knowledge of Java, with no prior understanding of computer vision required, as this book will give you clear explanations and examples of the basics.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 180
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: July 2015
Production reference: 1270715
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78328-397-2
www.packtpub.com
Author
Daniel Lélis Baggio
Reviewers
Ngoc Dao
Dileep Kumar Kotha
Domenico Luciani
Sebastian Montabone
Commissioning Editor
Kunal Parikh
Acquisition Editor
Harsha Bharwani
Content Development Editor
Nikhil Potdukhe
Technical Editor
Parag Topre
Copy Editors
Sarang Chari
Sonia Mathur
Swati Priya
Neha Vyas
Project Coordinator
Judie Jose
Proofreader
Safis Editing
Indexer
Monica Ajmera Mehta
Graphics
Disha Haria
Production Coordinator
Arvindkumar Gupta
Cover Work
Arvindkumar Gupta
Daniel Lélis Baggio started his work in computer vision through medical image processing at Instituto do Coração (InCor), which is a heart institute in São Paulo, Brazil, where he worked with intravascular ultrasound (IVUS) image segmentation. After this, he focused on GPGPU and ported that algorithm to work with NVIDIA's CUDA. He also dived into the topic of six degrees of freedom (6DoF), head tracking through a project called EHCI (http://code.google.com/p/ehci/) with the Natural User Interface group.
He is also the author of Mastering OpenCV with Practical Computer Vision Projects, Packt Publishing.
I'd first like to thank God for all the opportunities He has given me as well as for giving me our happy family.
I'd certainly like to thank Professor Sergio Furuie for introducing me to this wonderful world of computer vision. I'd also like to thank Professor Carlos Henrique Forster for his courses on the subject.
A big thanks goes to all the reviewers of this book, who took their time to put constructive and interesting corrections to its contents.
I would also like to thank the people from Packt Publishing—especially Parag Topre, Nikhil Potdukhe, Sriram Neelakantan, Harsha Bharwani, Sageer Parkar, and Nadeem Bagban—without whom, this book would never have been finished. I would also like to thank them for their patience.
I would like to thank my parents, who brought me into this world and educated me. I also thank my brother for always being there for me.
I dedicate this book to my children, who will always be part of my heart.
I'd also like to thank my wife for supporting me day and night in our life's journey.
Ngoc Dao studied computer vision at the Computer Vision and Image Media Lab of the University of Tsukuba, Japan. He has created several high-speed and scalable image matching server systems using Scala, Akka, and MongoDB with OpenCV's Java binding. These systems can scale multiple machines and have successfully been used with many iOS and Android apps.
Other than computer vision, Ngoc is also interested in real-time distributed systems and web frameworks. He is the main author of Xitrum, which is an open source async and clustered web framework for Scala (http://xitrum-framework.github.io). He presented this framework at the Scala Matsuri 2014 conference in Tokyo (http://scalamatsuri.org/en/program/index.html).
I would like to thank Professor Yuichi Ohta, Professor Yoshinari Kameda, and Professor Kitahara Itaru at the University of Tsukuba. They taught me a lot about computer vision.
Dileep Kumar Kotha currently works as a senior software engineer at a telecom firm in Bangalore, India. He is an undergraduate in computer science from the National Institute of Technology, Rourkela, 2012 batch. He started working on image processing during his summer internship at the prestigious IIT Kharagpur and has continued working with OpenCV on Linux machines ever since. Currently, he successfully manages a blog on OpenCV for beginners, which you can find at http://opencvuser.blogspot.in/.
I would like to thank Packt Publishing for giving me the opportunity to review this book and Judie for bearing the delays in the completion of my reviews.
Domenico Luciani is a passionate 22-year-old programmer. He currently works as a software engineer for some companies and is studying computer science at the University of Palermo, Italy.
He is a computer vision enthusiast and loves security and often pentests too; he also takes part in bounty programs for many companies. He has worked with many technologies in the past, such as MongoDB, Node.js, PHP, PostgreSQL, and C. He makes many Node.js modules that he successfully publishes on the NPM website. He collaborated as a reviewer on a published BDD test using a JavaScript book. He studies the Go language (golang) just for fun.
He owns a Raspberry Pi. He loves writing code using vim and manages it with Git. He also writes tests and collaborates with various open source projects on the Web.
In his free time, he likes running and playing Parkour. You can find out more about him at http://dlion.it.
Sebastian Montabone is a computer engineer with a master's of science degree in computer vision. He has worked in areas, such as intelligent IP cameras for automated surveillance, data mining, 3D sensors, game development, and embedded devices.
He is the author of Beginning Digital Image Processing: Using Free Tools for Photographers, Apress. He has also written scientific articles and a computer vision video course OpenCV Computer Vision Application Programming, Packt Publishing.
You can visit his blog at www.samontab.com, where he shares his current projects with the world.
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 all the readers, without whom this book would not have a reason for existing
Living in times when self-driving vehicles are becoming a reality might trigger curious minds as to how could computers' incipient vision works. Having a face recognized for access control, getting our pictures automatically organized by a subject or person, and having characters automatically recognized from paper scans are tasks that have become common in our lives. All these aforementioned actions have been enlisted in the so-called study area of computer vision.
As a scientific discipline, the theory behind systems that can extract information from images can be described as computer vision, and it has been adopted to extract valuable measurements from medical images, as well as to help humans delineate the boundaries of important image areas in the so-called semi-automatic procedures.
In the context of providing a simple-to-use computer vision infrastructure to help people rapidly build sophisticated vision applications, an open source library was created: OpenCV. It was designed for real-time applications and is written in C++, containing several hundred computer vision algorithms.
Although OpenCV had its debut alpha release back in January 1999, it was only in February 2013 that it officially supported desktop Java through bindings. As this is one of the most popular introductory teaching languages adopted in computer science departments as well as K-12 computer-related courses, it is important to have a good reference for how to build vision apps in a Java environment.
This book covers the basic OpenCV computer vision algorithms and their integration with Java. As the Swing GUI widget toolkit is widely adopted to build GUIs in Java, in this book, you will benefit from the chapters that deal with this topic as well as come to know how to set up your development environment that deals with native code bindings. Besides, operations such as stretching, shrinking, warping, and rotating, as well as finding edges, lines, and circles are all covered through interesting and practical sample projects in this book.
As the Kinect device has become a great tool for background segmentation, we have covered it in this chapter as well.
Another hot topic that is commonly explored with computer vision is machine learning, and in this book, you will find useful information to create your own object tracker and to use OpenCV's built-in face tracker as well.
Since Java has been widely used for web applications, we have covered computer vision applications on the server side as well, explaining the details of image uploading and integration with OpenCV.
By the end of this book, you will have a solid background in how to use Java with OpenCV from setup to server side; a brief explanation of the basic computer vision topics are covered in the book. Also, you'll get the source code of several complete projects from which you can extend and add your own functionality.
Chapter 1, Setting Up OpenCV for Java, covers the setting up of a library and development environment. This chapter covers Eclipse and NetBeans IDEs, as well as explaining the Ant and Maven build tools configuration.
Chapter 2, Handling Matrices, Files, Cameras, and GUIs, shows how to access matrices at the pixel level as well as how to load and display images from files and web cameras. It also covers the Swing widget toolkit support and how to work with OpenCV.
Chapter 3, Image Filters and Morphological Operators, deals with the process of removing noise from images as well as morphological operators. It also explains image pyramids and topics such as flood fill and image thresholding.
Chapter 4, Image Transforms, explains important transformations to find edges, such as the Gradient and Sobel filters. Additionally, it also explains line and circle Hough transforms, which are used to identify not only straight but also radial lines. The Discrete Fourier analysis and some distance transforms are also explained in this chapter.
Chapter 5, Object Detection Using Ada Boost and Haar Cascades, demonstrates how to create your own classifier to find some objects, as well as how to use the famous face detection classifier.
Chapter 6, Detecting Foreground and Background Regions and Depth with a Kinect Device, explores the important problem of extracting your background. Furthermore, it explains how to use a Kinect device to retrieve depth information.
Chapter 7, OpenCV on the Server Side, explains how to set up a web server application with OpenCV.
If you are a Java developer, student, researcher, or hobbyist wanting to create computer vision applications in Java then this book is for you. If you are an experienced C/C++ developer who is used to working with OpenCV, you will also find this book very useful for migrating your applications to Java.
All you need is basic knowledge of Java, with no prior understanding of computer vision required, as this book will give you clear explanations and examples of the basics.
If you are a C/C++ developer, student, researcher, or hobbyist wanting to create computer vision applications in Java, then this book is for you. If you are an experienced C/C++ developer who is used to working with OpenCV, you will also find this book very useful to migrate your applications to Java.
All you need is a basic knowledge of Java. No prior understanding of computer vision is required, as this book will give you clear explanations and examples of the basics.
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: "Another way to get the source code is by using the git tool."
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:
Any command-line input or output is written as follows:
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: " Go to Window | Preferences, and type classpath variables in the search box."
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 http://www.packtpub.com/sites/default/files/downloads/3972OS_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.
I'm sure you want to start developing astonishing computer vision applications. You must have heard of a nice C/C++ computer vision library called OpenCV to help you do so. But in case you would like to develop the applications using your knowledge of Java programming, we have good news for you. Since the release of OpenCV 2.4.4 in January 2013, Java bindings have been officially developed. So you can use them not only for desktop Java, but also for Scala development.
This chapter will set you up for OpenCV development right away. As Java developers are mostly used to working with tools such as Eclipse, NetBeans, ApacheAnt, and Maven, we will cover the details of creating a simple OpenCV application using the environment that the Java developers are more used to.
In this chapter, we will do the following:
By the end of this chapter, the user should have an OpenCV for Java installation running on his OS which can easily be linked to Eclipse, NetBeans, Apache Ant, or Maven, the most used tools and building systems for Java.
The first thing to notice when working with OpenCV for Java development is that OpenCV is a C++ library that should be compiled with operating system- specific compilers. The native code that would be generated is platform-dependent. So, the native Linux code won't run in Windows, neither will the Android native code run in OSX. This sounds very different from the bytecode generated for Java, which is executed by an interpreter in any platform. In order to get the native code running in a Java Virtual Machine (JVM), one needs the so called Java Native Interface (JNI). This way, the native code will be required for each platform that your application is going to be run on.
It is important to understand that JNI is a native programming interface. It allows the Java code that runs inside a JVM to interoperate with the applications and libraries written in programming languages such as C, C++, and assembly. Since it bridges the gap between Java and other languages, it needs to convert datatypes from these languages, as well as to create some boilerplate code. Curious readers should refer to the gen_java.py