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
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.

Arrow left icon
Profile Icon Joseph Howse
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (9 Ratings)
Paperback Sep 2013 130 pages 1st Edition
eBook
$9.99 $22.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Joseph Howse
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (9 Ratings)
Paperback Sep 2013 130 pages 1st Edition
eBook
$9.99 $22.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$9.99 $22.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781849695206
Vendor :
Google
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Sep 25, 2013
Length: 130 pages
Edition : 1st
Language : English
ISBN-13 : 9781849695206
Vendor :
Google
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 $5 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 $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 136.97
Android Application Programming with OpenCV
$38.99
Mastering OpenCV with Practical Computer Vision Projects
$48.99
OpenCV Computer Vision Application Programming Cookbook Second Edition
$48.99
Total $ 136.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.