Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Android Application Programming with OpenCV
Android Application Programming with OpenCV

Android Application Programming with OpenCV: For Java developers OpenCV is a fantastic opportunity to benefit from the popularity of image related mobile apps on Android. This book teaches you all you need to know about computer vision with practical projects.

eBook
€8.99 €22.99
Paperback
€28.99
Subscription
Free Trial
Renews at €18.99p/m

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

Android Application Programming with OpenCV

Chapter 2. Working with Camera Frames

In this chapter, we focus on building a basic photo capture app, which uses OpenCV to capture frames of camera input. Our app will enable the user to preview, save, edit, and share photos. It will interface with other apps on the device, via Android's MediaStore and Intent classes. Thus, we will learn how to build bridges between OpenCV and standard Android. Subsequent chapters will expand our app, using more functionality from OpenCV.

Note

The complete Eclipse project for this chapter can be downloaded from my website, http://nummist.com/opencv/5206_02.zip.

Designing our app – Second Sight


Let's make an app that enables people to see new visual patterns, to animate and interact with these patterns, and to share them as pictures. The idea is simple and versatile. Anyone, from a child to a computer vision expert, can appreciate the patterns. Through the magic of computer vision on a mobile device, any user can more readily see, change, and share hidden patterns in any scene.

For this app, I chose the name Second Sight, a phrase that is sometimes used in mythology to refer to supernatural and symbolic visions.

At its core, Second Sight is a camera app. It will enable the user to preview, save, and share photos. Like many other camera apps, it will also let the user to apply filters to the preview and the saved photos. However, many of the filters will not be traditional photographic effects. For example, the more complex filters will enable the user to see stylized edges or even rendered objects that blend with the real scene (augmented reality...

Creating the Eclipse project


We need to create a new Eclipse project for our app. We may do this in the same workspace that we already used for the OpenCV library project and samples. Alternatively, if we use another workspace, we must import the OpenCV library project into this workspace too. (For instructions on setting the workspace and importing the library project, see the Building the OpenCV samples with Eclipse section of Chapter 1, Setting Up OpenCV.)

Open Eclipse to a workspace that contains the library project. Then, from the menu system, navigate to File | New | Android Application Project. The New Android Application window should appear. Enter the options that are shown in the following screenshot:

The Target SDK and Compile With fields should be set to API 11 (Android 3.0) or higher. It is safe to choose the most recent API version, which, at the time of writing, is API 17: Android 4.2 (Jelly Bean). The Minimum Required SDK field should be left at the default, API 8: Android...

Enabling camera and disk access in the manifest


The AndroidManifest.xml (the manifest) file specifies an Android app's requirements and components. Compared to the default manifest, the manifest in Second Sight needs to do the following additional work:

We can accomplish these tasks by editing the uses-permission, uses-feature, and activity tags in the...

Creating menu and string resources


Our app's menus and localizable text are described in XML files. Identifiers in these resource files are referenced by Java code, as we will see later.

Note

For details about Android app resources, see the official documentation at http://developer.android.com/guide/topics/resources/index.html.

First, let's edit res/menu/activity_camera.xml so that it has the following implementation, describing the menu items for CameraActivity:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
  <item
    android:id="@+id/menu_next_camera"
    android:orderInCategory="100"
    android:showAsAction="ifRoom|withText"
    android:title="@string/menu_next_camera"/>
  <item
    android:id="@+id/menu_take_photo"
    android:orderInCategory="100"
    android:showAsAction="always|withText"
    android:title="@string/menu_take_photo"/>
</menu>

Note that we use the android:showAsAction attribute to make menu items appear in the app's top bar...

Previewing and saving photos in CameraActivity


Our main activity, CameraActivity, needs to do the following:

  • On startup, use OpenCV Manager to ensure that the appropriate OpenCV shared libraries are available. (For more information about OpenCV Manager, refer back to the Building the OpenCV samples with Eclipse section in Chapter 1, Setting Up OpenCV.)

  • Display a live camera feed.

  • Provide the following menu actions:

    • Switch the active camera (for a device that has multiple cameras).

    • Save a photo and insert it into MediaStore so that it is accessible to apps such as Gallery. Immediately open the photo in LabActivity.

We will use OpenCV functionality wherever feasible, even though we could just use the standard Android libraries to display a live camera feed, save a photo, and so on.

OpenCV provides an abstract class called CameraBridgeViewBase, which represents a live camera feed. This class extends Android's SurfaceView class, so that its instances can be part of the view hierarchy. Moreover, a...

Deleting, editing, and sharing photos in LabActivity


Our second activity, LabActivity, needs to do the following:

  • From the previous activity, receive a URI and file path for a PNG file

  • Display the image that is contained in the PNG file

  • Provide the following menu actions:

    • Show a confirmation dialog. On confirmation, delete the PNG file and finish the activity.

    • Show an intent chooser so that the user may select an app to edit the PNG file. (The URI is passed with the EDIT intent.)

    • Show a chooser so that the user may select an app to share or send the PNG file. (The URI is passed with the SEND intent.)

All of this functionality relies on standard Android library classes, notably the Intent class. Intents are the means by which activities communicate with each other. An activity receives an intent from its parent (the activity that created it) and may receive intents from its children (activities it created) as they finish. The communicating activities may be in different applications. An intent may...

Summary


We have used OpenCV to create and show a live camera feed, and to save still images from this feed. We have also seen how to integrate the camera feed's lifecycle into the Android activity lifecycle, and how to share saved images across the boundaries of activities and applications.

The next chapter will expand our Second Sight app by adding various image filtering options to the menus of CameraActivity and LabActivity.

Left arrow icon Right arrow icon

Key benefits

  • Set up OpenCV and an Android development environment on Windows, Mac, or Linux
  • Capture and display real-time videos and still images
  • Manipulate image data using OpenCV and Apache Commons Math
  • Track objects and render 2D and 3D graphics on top of them
  • Create a photo-capture and photo-sharing app that supports a variety of filters with a real-time preview feature

Description

Take a smartphone from your pocket, and within a few seconds, you can snap a photo, manipulate it, and share it with the world. You have just achieved mass production of image data. With a computer vision library such as OpenCV, you can analyze and transform copious amounts of image data in real time on a mobile device. The upshot to this is that you, as developers, can provide mobile users with many new kinds of images, constantly highlighting certain visual features that are of artistic or practical interest. Android is a convenient platform for such experiments because it uses a high-level language (Java), it provides standardized interfaces for sharing image data between applications, and it is mostly open source, so everyone can study its implementation. Android Application Programming with OpenCV is a practical, hands-on guide that covers the fundamental tasks of computer vision—capturing, filtering, and analyzing images-with step-by-step instructions for writing both an application and reusable library classes. Android Application Programming with OpenCV looks at OpenCV's Java bindings for Android and dispels mysteries such as which version of these bindings to use, how to integrate with standard Android functionality for layout, event handling, and data sharing, and how to integrate with OpenGL for rendering. By following the clear, concise, and modular examples provided in this book, you will develop an application that previews, captures, and shares photos with special effects based on color manipulation, edge detection, image tracking, and 3D rendering.Beneath the application layer, you will develop a small but extensible library that you can reuse in your future projects. This library will include filters for selectively modifying an image based on edge detection, 2D and 3D image trackers, and adapters to convert the Android system's camera specifications into OpenCV and OpenGL projection matrices. If you want a quick start in computer vision for Android, then this is the book for you. By the end of Android Application Programming with OpenCV, you will have developed a computer vision application that integrates OpenCV, Android SDK, and OpenGL.

Who is this book for?

This book is for Java developers who are new to computer vision and who would like to learn about how it is used in relation to application development. It is assumed that you have previous experience in Java, but not necessarily Android. A basic understanding of image data (for example pixels and color channels) would be helpful too. You are expected to have a mobile device running Android 2.2 (Froyo) or greater and it must have a camera.

What you will learn

  • Install OpenCV and an Android development environment on Windows, Mac, or Linux
  • Capture, display, and save images
  • Make images accessible to other apps via Android s MediaStore and Intent classes
  • Integrate OpenCV events and views with Android s standard activity lifecycle and view hierarchy
  • Learn how OpenCV uses matrices to store data about images, recognizable features in images, and camera characteristics
  • Apply curves and other color transformations to simulate the look of old photos, movies, or video games
  • Apply convolution filters that sharpen, blur, emboss, or darken edges and textures in an image
  • Track real-world objects, especially printed images, in 2D and 3D space
  • Extract camera data from Android SDK and use it to construct OpenCV and OpenGL projection matrices
  • Render basic 3D graphics in OpenGL

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 25, 2013
Length: 130 pages
Edition : 1st
Language : English
ISBN-13 : 9781849695213
Vendor :
Google
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 : Sep 25, 2013
Length: 130 pages
Edition : 1st
Language : English
ISBN-13 : 9781849695213
Vendor :
Google
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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 €5 each
Feature tick icon Exclusive print discounts
€264.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 €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 103.97
Android Application Programming with OpenCV
€28.99
Mastering OpenCV with Practical Computer Vision Projects
€37.99
OpenCV Computer Vision Application Programming Cookbook Second Edition
€36.99
Total 103.97 Stars icon
Banner background image

Table of Contents

5 Chapters
Setting Up OpenCV Chevron down icon Chevron up icon
Working with Camera Frames Chevron down icon Chevron up icon
Applying Image Effects Chevron down icon Chevron up icon
Recognizing and Tracking Images Chevron down icon Chevron up icon
Combining Image Tracking with 3D Rendering Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8
(9 Ratings)
5 star 22.2%
4 star 55.6%
3 star 11.1%
2 star 0%
1 star 11.1%
Filter icon Filter
Top Reviews

Filter reviews by




HS Aug 26, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
GREAT book for new to android programmers. It's light, easy to follow, and provides a good overview of various image processing features. Sample projects are fun and easy to develop or modify for your own use.
Amazon Verified review Amazon
Nathan Waters Jun 01, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Short and sweet! Great way to get your feet wet in Computer Vision and Graphics on Android.
Amazon Verified review Amazon
Jung W. Suh Dec 07, 2013
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This book guides for easy start of OpenCV at Android environment. It starts with the scratch and basics such as development environment setting through practical examples, so it helps to even novice of both Android and OpenCV. Since this book is not thick and easily read, we can go through the book quickly and can go to the next level.
Amazon Verified review Amazon
Pradeep Jul 26, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Nice and compact book - gets started on OpenCV and Image processing with Android! However, could have been little more elaborate on OpenCV fundamentals too.
Amazon Verified review Amazon
Kindle Customer Dec 14, 2013
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I received a review copy from PacktPub.comThe book does a nice job of introducing the reader to OpenCV under Android. It starts with the basics (installing, setting up the development environment, and compiling), then moves on to capturing images, applying filters/effects, tracking in 2D, tracking in 3D, and finally rendering 3D objects on top of a camera image for Augmented Reality.The code in the book is provided for easy compiling, and is nicely commented for easy reading.
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.