Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
iOS Application Development with OpenCV 3
iOS Application Development with OpenCV 3

iOS Application Development with OpenCV 3: Create four mobile apps and explore the world through photography and computer vision

Arrow left icon
Profile Icon Joseph Howse
Arrow right icon
Can$12.99 Can$39.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (5 Ratings)
eBook Jun 2016 228 pages 1st Edition
eBook
Can$12.99 Can$39.99
Paperback
Can$49.99
Subscription
Free Trial
Arrow left icon
Profile Icon Joseph Howse
Arrow right icon
Can$12.99 Can$39.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (5 Ratings)
eBook Jun 2016 228 pages 1st Edition
eBook
Can$12.99 Can$39.99
Paperback
Can$49.99
Subscription
Free Trial
eBook
Can$12.99 Can$39.99
Paperback
Can$49.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

iOS Application Development with OpenCV 3

Chapter 2. Capturing, Storing, and Sharing Photos

For many people, photography is a collaborative and social activity. This is not just a new perspective. Even the pioneers of photography spent long hours sharing their creative processes with family, students, models, and curious members of the public, who hoped to be immortalized in this new art form.

Today's technology enables people to collaborate and socialize in a short time and at a great distance. As we discussed in the previous chapter, the iPhone offers a set of unobtrusive and intuitive tools to any user who wants to capture, edit, and share photos from this small screen. For better or worse, a few taps of the user's fingers have replaced all the manual work of the studio, darkroom, print shop, and delivery service.

This chapter addresses the technical challenges of developing a mobile workflow for the social photographer. We will accomplish the following tasks:

  • Configure the camera, including focus and exposure...

Planning a photo sharing application

When it opens, LightWork will present a vintage photograph and toolbar containing a few items. The following screenshot shows it all:

Planning a photo sharing application

This bucolic image is an early color photograph, shot in 1902 by Adolf Miethe, a German photographer, professor, and inventor. The photo almost looks like a painting due to its coarse grain and pastel colors. However, it is a true example of a color photographic process. Miethe captured a scene on three photographic plates behind three different filters: red, green, and blue. Then, to recreate a multicolored image, he superimposed the three images using a projection process with different colors of light or a printing process with different dyes. Similar techniques are still in use today in our digital sensors, monitors, and printers.

LightWork will also be capable of displaying a live preview from a camera. However, for our purposes, a static (still) image is also a useful preview. A static image (unlike a camera preview...

Configuring the project

Create an Xcode project named LightWork using the Single View Application template. Configure the project according to the instructions in the Configuring the project section in Chapter 1, Setting Up Software and Hardware. Next, we will take a few additional configuration steps because LightWork depends on more frameworks and requires a camera.

Adding frameworks

Besides its dependency on opencv2.framework, LightWork also depends on the following standard frameworks from the iOS SDK:

  • Accelerate.framework: This is optional but recommended because it enables OpenCV to use advanced optimizations
  • AssetsLibrary.framework
  • AVFoundation.framework
  • CoreGraphics.framework
  • CoreMedia.framework
  • CoreVideo.framework
  • Photos.framework
  • QuartzCore.framework
  • Social.framework
  • UIKit.framework

Add these frameworks to the Build Phases | Link Binary With Libraries section of the project settings.

Specifying the camera requirement

Currently, there is a camera in all devices that support iOS 9. However, perhaps...

Defining and laying out the view controller

As discussed in the previous chapter, we may declare GUI elements in a view controller's source code and lay them out in a storyboard. Thus, to begin, let's open ViewController.m and define the private interface of our ViewController class. The interface depends on headers from the iOS SDK's Photos and Social frameworks as well as the OpenCV framework. Moreover, it depends on headers that define the public interfaces of our own classes, ViewController and VideoCamera. The latter class will handle many aspects of camera input and video display and we will write it later in the Controlling the camera section. Let's import these dependencies by adding the following code at the start of ViewController.m:

#import <Photos/Photos.h>
#import <Social/Social.h>

#import <opencv2/core.hpp>
#import <opencv2/imgcodecs.hpp>
#import <opencv2/imgcodecs/ios.h>
#import <opencv2/imgproc.hpp>

#import "ViewController...

Controlling the camera

The iOS SDK and OpenCV provide several programming interfaces for camera control. Within the iOS SDK, AVFoundation is the general-purpose framework for all recording and playback of audiovisual (AV) content. AVFoundation provides complete access to the iOS camera's parameters, including the image format, focus, exposure, flash, frame rate, and digital zoom (crop factor). However, AVFoundation does not solve any GUI problems. The application developer may create a custom camera GUI, use a higher-level framework that provides a GUI, or automate the camera so that it operates without GUI input. AVFoundation is sufficiently flexible to support any of these designs, but this flexibility comes at a price as AVFoundation is complex.

Note

The official AVFoundation Programming Guide is located at https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG.

The iOS SDK implements a standard camera GUI in the UIImagePickerController class,...

Working with various color formats

As we have seen, OpenCV and the iOS SDK work with various formats for color and grayscale images and sometimes we need to convert between formats. Let's step back from the code for a few moments to discuss the differences between formats and the problems that can arise if we do not perform the correct conversions.

RGB, BGR, RGBA, and BGRA

You probably learned the 24-bit RGB color format long ago, the first time you picked a custom color in a paint program or word processor. A pixel's color is represented by a sequence of three values, each with a range of 0 to 255 (that is, 8 bits or 1 byte). The first value is the color's red component or channel, followed by green, and lastly blue. For example, the color of an amber traffic light is (255, 126, 0), a mixture of lots of red and some green, but no blue. A series of pixel data makes an image.

The 24-bit BGR format simply reverses the channel order. For example, the color of the amber traffic...

Planning a photo sharing application


When it opens, LightWork will present a vintage photograph and toolbar containing a few items. The following screenshot shows it all:

This bucolic image is an early color photograph, shot in 1902 by Adolf Miethe, a German photographer, professor, and inventor. The photo almost looks like a painting due to its coarse grain and pastel colors. However, it is a true example of a color photographic process. Miethe captured a scene on three photographic plates behind three different filters: red, green, and blue. Then, to recreate a multicolored image, he superimposed the three images using a projection process with different colors of light or a printing process with different dyes. Similar techniques are still in use today in our digital sensors, monitors, and printers.

LightWork will also be capable of displaying a live preview from a camera. However, for our purposes, a static (still) image is also a useful preview. A static image (unlike a camera preview...

Configuring the project


Create an Xcode project named LightWork using the Single View Application template. Configure the project according to the instructions in the Configuring the project section in Chapter 1, Setting Up Software and Hardware. Next, we will take a few additional configuration steps because LightWork depends on more frameworks and requires a camera.

Adding frameworks

Besides its dependency on opencv2.framework, LightWork also depends on the following standard frameworks from the iOS SDK:

  • Accelerate.framework: This is optional but recommended because it enables OpenCV to use advanced optimizations

  • AssetsLibrary.framework

  • AVFoundation.framework

  • CoreGraphics.framework

  • CoreMedia.framework

  • CoreVideo.framework

  • Photos.framework

  • QuartzCore.framework

  • Social.framework

  • UIKit.framework

Add these frameworks to the Build Phases | Link Binary With Libraries section of the project settings.

Specifying the camera requirement

Currently, there is a camera in all devices that support...

Defining and laying out the view controller


As discussed in the previous chapter, we may declare GUI elements in a view controller's source code and lay them out in a storyboard. Thus, to begin, let's open ViewController.m and define the private interface of our ViewController class. The interface depends on headers from the iOS SDK's Photos and Social frameworks as well as the OpenCV framework. Moreover, it depends on headers that define the public interfaces of our own classes, ViewController and VideoCamera. The latter class will handle many aspects of camera input and video display and we will write it later in the Controlling the camera section. Let's import these dependencies by adding the following code at the start of ViewController.m:

#import <Photos/Photos.h>
#import <Social/Social.h>

#import <opencv2/core.hpp>
#import <opencv2/imgcodecs.hpp>
#import <opencv2/imgcodecs/ios.h>
#import <opencv2/imgproc.hpp>

#import "ViewController.h"
#import ...

Controlling the camera


The iOS SDK and OpenCV provide several programming interfaces for camera control. Within the iOS SDK, AVFoundation is the general-purpose framework for all recording and playback of audiovisual (AV) content. AVFoundation provides complete access to the iOS camera's parameters, including the image format, focus, exposure, flash, frame rate, and digital zoom (crop factor). However, AVFoundation does not solve any GUI problems. The application developer may create a custom camera GUI, use a higher-level framework that provides a GUI, or automate the camera so that it operates without GUI input. AVFoundation is sufficiently flexible to support any of these designs, but this flexibility comes at a price as AVFoundation is complex.

Note

The official AVFoundation Programming Guide is located at https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG.

The iOS SDK implements a standard camera GUI in the UIImagePickerController class, which...

Working with various color formats


As we have seen, OpenCV and the iOS SDK work with various formats for color and grayscale images and sometimes we need to convert between formats. Let's step back from the code for a few moments to discuss the differences between formats and the problems that can arise if we do not perform the correct conversions.

RGB, BGR, RGBA, and BGRA

You probably learned the 24-bit RGB color format long ago, the first time you picked a custom color in a paint program or word processor. A pixel's color is represented by a sequence of three values, each with a range of 0 to 255 (that is, 8 bits or 1 byte). The first value is the color's red component or channel, followed by green, and lastly blue. For example, the color of an amber traffic light is (255, 126, 0), a mixture of lots of red and some green, but no blue. A series of pixel data makes an image.

The 24-bit BGR format simply reverses the channel order. For example, the color of the amber traffic light is (0, 126...

Starting and stopping the busy mode


Remember that we want to show an activity indicator and disable all the toolbar items while LightWork is busy saving or sharing a photo. Conversely, when LightWork is no longer busy with the photo, we want to hide the activity indicator and re-enable the toolbar items. As these actions affect the GUI, we must ensure that they run on the app's main thread.

Note

If our code is running on a background thread, nothing will happen when we try to show or hide the activity indicator.

To run code on a specific thread, we can make a post to the thread's event queue. The iOS SDK provides a C function, dispatch_async, which takes a target queue and code block as arguments. Another C function, dispatch_get_main_queue(), enables us to get the main thread's event queue. Let's use these functions in the following helper method, which starts the busy mode:

- (void)startBusyMode {
  dispatch_async(dispatch_get_main_queue(), ^{
    [self.activityIndicatorView startAnimating...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Efficiently harness iOS and OpenCV to capture and process high-quality images at high speed
  • Develop photographic apps and augmented reality apps quickly and easily
  • Detect, recognize, and morph faces and objects

Description

iOS Application Development with OpenCV 3 enables you to turn your smartphone camera into an advanced tool for photography and computer vision. Using the highly optimized OpenCV library, you will process high-resolution images in real time. You will locate and classify objects, and create models of their geometry. As you develop photo and augmented reality apps, you will gain a general understanding of iOS frameworks and developer tools, plus a deeper understanding of the camera and image APIs. After completing the book's four projects, you will be a well-rounded iOS developer with valuable experience in OpenCV.

Who is this book for?

If you want to do computational photography and computer vision on Apple’s mobile devices, then this book is for you. No previous experience with app development or OpenCV is required. However, basic knowledge of C++ or Objective-C is recommended.

What you will learn

  • Use Xcode and Interface Builder to develop iOS apps
  • Obtain OpenCV s standard modules and build extra modules from source
  • Control all the parameters of the iOS device s camera
  • Capture, save, and share photos and videos
  • Analyze colors, shapes, and textures in ordinary and specialized photographs
  • Blend and compare images to create special photographic effects and augmented reality tools
  • Detect faces and morph facial features
  • Classify coins and other objects

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 30, 2016
Length: 228 pages
Edition : 1st
Language : English
ISBN-13 : 9781785281464
Vendor :
Apple
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jun 30, 2016
Length: 228 pages
Edition : 1st
Language : English
ISBN-13 : 9781785281464
Vendor :
Apple
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Can$ 189.97
OpenCV 3 Computer Vision Application Programming Cookbook
Can$69.99
OpenCV By Example
Can$69.99
iOS Application Development with OpenCV 3
Can$49.99
Total Can$ 189.97 Stars icon
Banner background image

Table of Contents

6 Chapters
1. Setting Up Software and Hardware Chevron down icon Chevron up icon
2. Capturing, Storing, and Sharing Photos Chevron down icon Chevron up icon
3. Blending Images Chevron down icon Chevron up icon
4. Detecting and Merging Faces of Mammals Chevron down icon Chevron up icon
5. Classifying Coins and Commodities Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(5 Ratings)
5 star 40%
4 star 40%
3 star 0%
2 star 20%
1 star 0%
Sai Prasanth Dec 01, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
great book. I had some questions about the code and Joseph was kind enough to answer them personally. Kudos! Good for beginners of ObjC
Amazon Verified review Amazon
Amazon Customer Jul 18, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a very handy book for not only those that are getting started with iOS but also those who want to specifically focus on OpenCV with iOS. The code is well written and documented and explains concepts in a nice and crisp manner.
Amazon Verified review Amazon
Wayne Duquaine Jan 20, 2024
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Feefo Verified review Feefo
Andre Frank Jan 04, 2017
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I would highly recommend this book for all beginners who wants to use OpenCV3 for IOS development. The writer explains the OpenCV classes/methods very good. Step by step you will learn what exactly OpenCV is and how you can use it for IOS development. There are not so much tutorials but this doesn't matter. The level of details and complexity gains with every tutorial.At the end you will have a solid knowledge to write own code with OpenCV.You also learn how to install OpenCV in a correct way . It can be frustrating to do so without introduction...The only negative aspect for me was the format of the eBook. I struggled with line breaks of the printed source code. It looks a bit fragmented.
Amazon Verified review Amazon
Dillon Jun 30, 2017
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
I tried the first project, but could not get it to work. I download the necessary components and imported the OpenCV library, but it still would not work, thus rendering the rest of the book useless.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.