Book Image

Mastering OpenCV 3 - Second Edition

By : Shervin Emami, David Millán Escrivá, Daniel Lelis Baggio, Roy Shilkrot, Eugene Khvedchenia, Jason Saragih
Book Image

Mastering OpenCV 3 - Second Edition

By: Shervin Emami, David Millán Escrivá, Daniel Lelis Baggio, Roy Shilkrot, Eugene Khvedchenia, Jason Saragih

Overview of this book

As we become more capable of handling data in every kind, we are becoming more reliant on visual input and what we can do with those self-driving cars, face recognition, and even augmented reality applications and games. This is all powered by Computer Vision. This book will put you straight to work in creating powerful and unique computer vision applications. Each chapter is structured around a central project and deep dives into an important aspect of OpenCV such as facial recognition, image target tracking, making augmented reality applications, the 3D visualization framework, and machine learning. You’ll learn how to make AI that can remember and use neural networks to help your applications learn. By the end of the book, you will have created various working prototypes with the projects in the book and will be well versed with the new features of OpenCV3.
Table of Contents (14 chapters)
Title Page
Mastering OpenCV 3 Second Edition
About the Authors
About the Reviewer
Customer Feedback

About the Authors

Daniel Lélis Baggio started his work in computer vision through medical image processing at InCor (Instituto do Coração – Heart Institute) in São Paulo, where he worked with intravascular ultrasound image segmentation. Since then, he has focused on GPGPU and ported the segmentation algorithm to work with NVIDIA's CUDA. He has also dived into 6degrees of freedom head tracking with a natural user interface group through a project called ehci ( He now works for the Brazilian Air Force.


Shervin Emami, born in Iran, taught himself electronics and hobby robotics during his early teens in Australia. While building his first robot at the age of 15, he learned how RAM and CPUs work. He was so amazed by the concept that he soon designed and built a whole Z80 motherboard to control his robot, and wrote all the software purely in binary machine code using two push buttons for 0s and 1s.

After learning that computers can be programmed in much easier ways such as assembly language and even high-level compilers, Shervin became hooked on computer programming and has been programming desktops, robots, and smartphones nearly every day since then. During his late teens, he created Draw3D (, a 3D modeler with 30,000 lines of optimized C and assembly code that rendered 3D graphics faster than all the commercial alternatives of the time, but he lost interest in graphics programming when 3D hardware acceleration became available.

In University, Shervin took a class on Computer Vision and became greatly interested in it. So, for his first thesis in 2003, he created a real-time face detection program based on Eigenfaces, using OpenCV (beta 3) for the camera input. For his master's thesis in 2005, he created a visual navigation system for several mobile robots using OpenCV (v0.96).

From 2008, he worked as a freelance Computer Vision Developer in Abu Dhabi and Philippines, using OpenCV for a large number of short-term commercial projects that included:

  • Detecting faces using Haar or Eigenfaces
  • Recognizing faces using Neural Networks, EHMM, or Eigenfaces
  • Detecting the 3D position and orientation of a face from a single photo using AAM and POSIT
  • Rotating a face in 3D using only a single photo
  • Face preprocessing and artificial lighting using any 3D direction from a single photo
  • Gender recognition
  • Facial expression recognition
  • Skin detection
  • Iris detection
  • Pupil detection
  • Eye-gaze tracking 
  • Visual-saliency tracking
  • Histogram matching
  • Body-size detection
  • Shirt and bikini detection
  • Money recognition
  • Video stabilization 
  • Face recognition on iPhone
  • Food recognition on iPhone
  • Marker-based augmented reality on iPhone (the second-fastest iPhone augmented reality app at the time)

OpenCV was putting food on the table for Shervin's family, so he began giving back to OpenCV through regular advice on the forums and by posting free OpenCV tutorials on his website ( In 2011, he contacted the owners of other free OpenCV websites to write this book. He also began working on computer vision optimization for mobile devices at NVIDIA, working closely with the official OpenCV developers to produce an optimized version of OpenCV for Android. In 2012, he also joined the Khronos OpenVL committee for standardizing the hardware acceleration of computer vision for mobile devices, on which OpenCV will be based in the future.



David Millán Escrivá was 8 years old when he wrote his first program on an 8086 PC with basic language, which enabled the 2D plotting of basic equations. In 2005, he finished his studies in IT through the Universitat Politécnica de Valencia with honors in human-computer interaction supported by computer vision with OpenCV (v0.96). He had a final project based on this subject and published it on HCI Spanish congress. He participated in Blender, an open source, 3D-software project, and worked on his first commercial movie Plumiferos—Aventuras voladorasas, as a computer graphics software developer.

David now has more than 10 years of experience in IT, with experience in computer vision, computer graphics, and pattern recognition, working on different projects and start-ups, applying his knowledge of computer vision, optical character recognition, and augmented reality. He is the author of the DamilesBlog (, where he publishes research articles and tutorials about OpenCV, Computer Vision in general, and Optical Character Recognition algorithms. David has reviewed the book gnuPlot Cookbook, Packt Publishing, written by Lee Phillips.


Khvedchenia Ievgen is a Computer Vision expert from Ukraine. He started his career with research and development of a camera-based driver assistance system for Harman International. He then began working as a computer vision consultant for ESG. Nowadays, he is a self-employed developer focusing on the development of augmented reality applications. Ievgen is the author of the Computer Vision Talks blog (,where he publishes research articles and tutorials pertaining to computer vision and augmented reality.


Jason Saragih received his BE in mechatronics (with honors) and PhD in computer science from the Australian National University, Canberra, Australia, in 2004 and 2008, respectively. From 2008 to 2010, he was a Postdoctoral fellow at the Robotics Institute of Carnegie Mellon University, Pittsburgh, PA. From 2010 to 2012, he worked at the Commonwealth Scientific and Industrial Research Organization (CSIRO) as a research scientist. He is currently a senior research scientist at Visual Features, an Australian tech start-up company.

Dr. Saragih has made a number of contributions to the field of computer vision, specifically on the topic of deformable model registration and modeling. He is the author of two nonprofit open source libraries that are widely used in the scientific community; DeMoLib and FaceTracker, both of which make use of generic computer vision libraries, including OpenCV.


Roy Shilkrot is a researcher and professional in the area of computer vision and computer graphics. He obtained a BSc in computer science from Tel-Aviv-Yaffo Academic College, and an MSc from Tel-Aviv University. He is currently a PhD candidate in Media Laboratory of the Massachusetts Institute of Technology (MIT) in Cambridge.

Roy has over seven years of experience as a software engineer in start-up companies and enterprises. Before joining the MIT Media Lab as a research assistant, he worked as a technology strategist in the Innovation Laboratory of Comverse, a telecom solutions provider. He also dabbled in consultancy, and worked as an intern for Microsoft research at Redmond.