Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
OpenCV 3 Blueprints

You're reading from  OpenCV 3 Blueprints

Product type Book
Published in Nov 2015
Publisher
ISBN-13 9781784399757
Pages 382 pages
Edition 1st Edition
Languages

Table of Contents (14) Chapters

OpenCV 3 Blueprints
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Getting the Most out of Your Camera System Photographing Nature and Wildlife with an Automated Camera Recognizing Facial Expressions with Machine Learning Panoramic Image Stitching Application Using Android Studio and NDK Generic Object Detection for Industrial Applications Efficient Person Identification Using Biometric Properties Gyroscopic Video Stabilization Index

Chapter 2. Photographing Nature and Wildlife with an Automated Camera

National Geographic is famous for its intimate photos of wild animals. Often, in the magazine's pages, the animals seem larger than life, as if they belong to the same "geographic" scale as the landscapes behind them. This enlargement effect can be achieved by capturing the subject at a very close distance with a wide-angle lens. For example, one memorable photograph by Steve Winter shows a snarling tiger reaching out to strike the lens!

Let's consider the possible methods behind such a photo. The photographer could try to stalk a wild tiger in person, but for safety, this approach would require some distance and a long lens. A close encounter is likely to endanger the human, the tiger, or both. Alternatively, the photographer could use a remote-controlled rover or drone to approach and photograph the tiger. This would be safer but like the first technique it is laborious, only covers one site at a time, and may spoil opportunities...

Planning the camera trap


Our camera trap will use a computer with two attached cameras. One camera will continuously capture low-resolution images. For example, this first camera may be an ordinary webcam. Our software will analyze the low-resolution images to detect the presence of a subject. We will explore three basic detection techniques based on motion, color, and object classification. When a subject is detected, the second camera will activate to capture and save a finite series of high-resolution images. This second camera will be a dedicated photo camera, with its own battery and storage. We will not necessarily analyze and record images at the fastest possible rate; rather, we will take care to conserve the host computer's resources as well as the photo camera's battery power and storage so that our photo trap can function for a long time.

Optionally, our software will configure the photo camera for exposure bracketing. This means that some photos in a series will be deliberately...

Controlling a photo camera with gPhoto2


gPhoto2 is an open source, vendor-neutral camera control tool for Unix-like systems, such as Linux and Mac. It supports photo cameras of multiple brands, including Canon, Nikon, Olympus, Pentax, Sony, and Fuji. The supported features vary by model. The following table lists gPhoto2's major features, alongside the official count of supported cameras for each feature:

Feature

Number of Supported Devices

Description

File transfer

2105

files to and from the device

Image capture

489

Make the device capture an image to its local storage

Configuration

428

Change the device's settings, such as shutter speed

Liveview

309

Continuously grab frames of live video from the device

These numbers are current as of version 2.5.8, and are conservative. For example, some configuration features are supported on the Nikon D80, even though the gPhoto2 documentation does not list this camera as configurable. For our purposes, image capture and configuration...

Detecting the presence of a photogenic subject


Chapter 1, Getting the Most out of Your Camera System, proposed that a photograph ought to capture a subject in a moment. Let's explore this notion further as we search for ways to detect a desirable or "photogenic" subject and moment.

As a medium, photography uses light, an aperture, a photosensitive surface, and time to draw an image of a scene. The earliest photographic technology, in the 1820s, lacked the resolution and speed to convey a detailed subject in a precise moment, but it was able to capture a grainy scene on a sunny day. Later, with better lenses, flashes, and photosensitive surfaces, photography became capable of capturing a sharp scene, a formal portrait, a faster and more natural portrait, and finally a moment of action, frozen in time.

Consider the following series of famous photographs, ranging from 1826 to 1942:

For general interest, here are some details about the preceding photographs:

  • Upper left: View from the Window at Le...

Processing images to show subtle colors and motion


By now, you have probably captured some exposure-bracketed photos and time-lapse photos. Upload them onto your computer using a photo management application, a file browser, or the following gPhoto2 command:

$ gphoto2 --get-all-files

The latter command will upload the files to the current working directory.

We will merge exposure-bracketed photos to create HDR images, which will improve color rendition in shadows and highlights. Similarly, we will merge time-lapse photos to create time-lapse videos, which will show gradual motion on an accelerated scale. We will start by processing some of the sample photos from the book's GitHub repository at https://github.com/OpenCVBlueprints/OpenCVBlueprints/tree/master/chapter_2/CameraTrap/media, and then you will be able to adapt the code to use your photos instead.

Creating HDR images

OpenCV 3 has a new module called "photo". Two of its classes, MergeDebevec and MergeMertens, create an HDR image by merging...

Further study


Computational photography is a diverse and popular field, which combines the work of artists, technicians, and scientists. Thus, there are many types of authors, instructors, and mentors who can help you become a better "computational photographer". Here are just a few examples of helpful guides:

  • Learning Image Processing with OpenCV, by Gloria Bueno García et al (Packt Publishing, 2015), covers a wide range of OpenCV 3's capabilities with respect to image capture, image editing, and computational photography. The book uses C++, and is suitable for beginners in computer vision.

  • The National Geographic Masters of Photography video lectures (The Great Courses, 2015) provide great insight into the goals and techniques of master photographers. Several of the lecturers are wildlife photographers, whose use of camera traps was an inspiration for this chapter.

  • OpenSource Astrophotography, by Karl Sarnow (CreateSpace Independent Publishing Platform, 2013), covers the use of gPhoto2 and...

Summary


This chapter has demonstrated a set of surprisingly flexible commands and classes, which enable us to conduct experiments in computational photography, with short and simple code. We have written scripts to control a photo camera. Along the way, we have acquainted ourselves with gPhoto2, the Bash shell, PTP communication, GVFS mount points, and Python's support for subprocesses. We have also scripted several variations of a photo trap to take pictures when a subject comes into view. For this, OpenCV has provided us with the capability to detect motion, measure color similarities, and classify objects. Finally, we have used OpenCV to combine a set of photos into a time-lapse video or HDR image.

So far, this book has provided a fairly broad survey of ways to capture light as data, control a camera, detect a subject, and process a photo. The remaining chapters will focus on a selection of advanced techniques, which will enable us to perform much finer classification and identification...

lock icon The rest of the chapter is locked
You have been reading a chapter from
OpenCV 3 Blueprints
Published in: Nov 2015 Publisher: ISBN-13: 9781784399757
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.
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}