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
zł157.99
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
zł39.99 zł125.99
Paperback
zł157.99
Subscription
Free Trial
Arrow left icon
Profile Icon Joseph Howse
Arrow right icon
zł157.99
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
zł39.99 zł125.99
Paperback
zł157.99
Subscription
Free Trial
eBook
zł39.99 zł125.99
Paperback
zł157.99
Subscription
Free Trial

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to Poland

Premium delivery 7 - 10 business days

zł110.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Poland

Premium delivery 7 - 10 business days

zł110.95
(Includes tracking information)

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 zł20 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 zł20 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 553.97
Android Application Programming with OpenCV
zł157.99
Mastering OpenCV with Practical Computer Vision Projects
zł197.99
OpenCV Computer Vision Application Programming Cookbook Second Edition
zł197.99
Total 553.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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela