Native code in Android Quad Detection



Similar documents
Development_Setting. Step I: Create an Android Project

OpenCV on Android Platforms

Tutorial on OpenCV for Android Setup

Introduction to Native Android Development with NDK

System Reference 2013

Android Hands-On Labs

Multithreading and Java Native Interface (JNI)!

Android and OpenCV Tutorial

RTI Connext DDS. Core Libraries Getting Started Guide Addendum for Android Systems Version 5.2.0

Intel Integrated Native Developer Experience (INDE): IDE Integration for Android*

Android NDK Native Development Kit

l What is Android? l Getting Started l The Emulator l Hello World l ADB l Text to Speech l Other APIs (camera, bitmap, etc)

With a single download, the ADT Bundle includes everything you need to begin developing apps:

Hello World. by Elliot Khazon

Mocean Android SDK Developer Guide

Tutorial on Basic Android Setup

The "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.

Android Setup Phase 2

Example Connection between USB Host and Android

Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department. Mobile Computing ECOM Eng. Wafaa Audah.

Advertiser Campaign SDK Your How-to Guide

Download and Installation Instructions. Android SDK and Android Development Tools (ADT) Microsoft Windows

AllJoyn Android Environment Setup Guide

Android Development. 吳 俊 興 國 立 高 雄 大 學 資 訊 工 程 學 系

Installing the Android SDK

Android Development Tutorial. Nikhil Yadav CSE40816/ Pervasive Health Fall 2011

ID TECH UniMag Android SDK User Manual

APPLICATION NOTE. Getting Started with pylon and OpenCV

Fahim Uddin 1. Java SDK

How To Develop Android On Your Computer Or Tablet Or Phone

Download and Installation Instructions. Android SDK and Android Development Tools (ADT)

The Decaffeinated Robot

Introduction to NaviGenie SDK Client API for Android

Building graphic-rich and better performing native applications. Pro. Android C++ with the NDK. Onur Cinar

Extending your Qt Android application using JNI

PubMatic Android SDK. Developer Guide. For Android SDK Version 4.3.5

Download and Installation Instructions. Android SDK and Android Development Tools (ADT) Microsoft Windows

Android Environment SDK

Getting Started with Android Development

Installing Eclipse C++ for Windows

CS 253: Intro to Systems Programming

Università Degli Studi di Parma. Distributed Systems Group. Android Development. Lecture 1 Android SDK & Development Environment. Marco Picone

Programming with Android: SDK install and initial setup. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Using Intel C++ Compiler in Eclipse* for Embedded Linux* targets

How to Create an Android Application using Eclipse on Windows 7

Tutorial: Android Object API Application Development. SAP Mobile Platform 2.3 SP02

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

Programming with Android: SDK install and initial setup. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Table of Contents. Adding Build Targets to the SDK 8 The Android Developer Tools (ADT) Plug-in for Eclipse 9

YouthQuest Quick Key FOB Project

Technical Note. TN_134 FTDI Android D2XX Driver

Develop a Hello World project in Android Studio Capture, process, store, and display an image. Other sensors on Android phones

Android Environment SDK

Android Programming. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

GearVRf Developer Guide

Basic Android Setup Windows Version

Developing Android Apps: Part 1

Android 4.4 App Development Essentials

Android Application Development

Tutorial: Android Object API Application Development. SAP Mobile Platform 2.3

Oracle FLEXCUBE Direct Banking Android Tab Client Installation Guide Release

Application Development Setup Guide

Android: How To. Thanks. Aman Nijhawan

Oculus Mobile Software Development Kit (SDK) Device and Environment Setup Guide

Lecture 1 Introduction to Android

BIRT Application and BIRT Report Deployment Functional Specification

Introduction to Android

Using Microsoft Visual Studio API Reference

An Introduction to Android Application Development. Serdar Akın, Haluk Tüfekçi

How to develop your own app

Operational Decision Manager Worklight Integration

HTTPS hg clone plugin library SSH hg clone plugin library

5 reasons to choose Streamezzo SDK over Android SDK Page 2

KaleidaGraph Quick Start Guide

How To Write A File Station In Android.Com (For Free) On A Microsoft Macbook Or Ipad (For A Limited Time) On An Ubuntu 8.1 (For Ubuntu) On Your Computer Or Ipa (For

How to build your first Android Application in Windows

ART 170: Web Design 1

Numerical Algorithms Group

Issues in Android on Mobile Platform and Their Resolution

341 - Bioinformatics Android Coursework

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

Android Development Setup [Revision Date: 02/16/11]

CS 528 Mobile and Ubiquitous Computing Lecture 2: Android Introduction and Setup. Emmanuel Agu

Iotivity Programmer s Guide Soft Sensor Manager for Android

Developing In Eclipse, with ADT

IDE Integration for Android* Part of the Intel Integrated Native Developer Experience (Intel INDE) 1.5.7

Tutorial: Android Object API Application Development. Sybase Unwired Platform 2.2 SP02

What else can you do with Android? Inside Android. Chris Simmonds. Embedded Linux Conference Europe Copyright 2010, 2net Limited.

NVIDIA Tegra Android Platform Support Pack Getting Started Guide

Mobile Application Development 2014

ADT Plugin for Eclipse

Eddy Integrated Development Environment, LemonIDE for Embedded Software System Development

Smart Shopping- An Android Based Shopping Application

Android Programming and Security

Android Development Tools for Eclipse

Login with Amazon Getting Started Guide for Android. Version 2.0

Transcription:

Native code in Android Quad Detection 21 July 2013 This document provides information on how to build and run native (C/C++) code in Android platform using Android NDK and then use its scope to auto capture an image when a quadrilateral object (close to a rectangle) is detected inside the camera view of an Android phone. Author: Rahul Bhat

Table of Contents S.No Topic Page No 1 Introduction 3 2 Setting up the Environment 3 3 Calling the native code 6 4 Quad Detection 7 5 Auto Capture when a Quadrilateral is detected 8

1. Introduction This document provides information on how to build and run native (C/C++) code in Android platform using Android NDK and then use its scope to auto capture an image when a quadrilateral object (close to a rectangle) is detected inside the camera view of an Android phone 2. Setting up the Environment 1. Prerequisites: Eclipse with Android SDK and ADT plugin. 2. The NDK plugin currently works with CDT 7.0.2 or CDT 8.0.2. 1. Install CDT from Eclipse update site http://download.eclipse.org/tools/cdt/releases/indigo. 2. Install Android NDK Plugin from Eclipse update site https://dl-ssl.google.com/android/eclipse/. 3. Set the path to Android NDK: Eclipse -> Window -> Preferences -> Android -> NDK -> set path to the NDK 3. For running native C/C++ code in Android platform, you need to convert your project to C/C++ project to add native nature to the project. Right click on your project and then click on New Other Under C/C++

4. Now right click on your project and then click Properties. You will see C/C++ Build item. Give the path of your ndk-build.cmd to Build Command edit box or you can set an environment variable to your ndkbuild.cmd file path. 5. Now click on Behavior tab and set the environment variables as shown. 6. Now to go to C/C++ General item and click on Include tab and set the path to Android NDK include folder for GNU C and/or GNU C++. Eg: C:\Users\rahul.bhat\Downloads\android-ndk-r8e-windows-x86\android-ndk-r8e\platforms\android- 9\arch-arm\usr\include

7. Write your C/C++ code and place the file inside jni folder alogn with Android.mk and Application.mk file. a. In Android.mk file, you can refer any library you want to include in your native code. Eg: include C:\Users\rahul.bhat\Downloads\OpenCV-2.4.5-android-sdk\sdk\native\jni\OpenCV.mk b. Also you can assign the source file. LOCAL_SRC_FILES := ImageProcessing.cpp c. This is how a Application.mk file looks like:- APP_STL := gnustl_static APP_CPPFLAGS := -frtti -fexceptions APP_ABI := armeabi-v7a APP_MODULES := ImageProcessing

3. Calling the native code Calling the native C/C++ code from Java class. 1. Create a function with native keyword. // Native JNI // public native boolean ImageProcessing(int width, int height, byte[] framedata, int [] pixels); 2. Call the method from your java class. ImageProcessing(PreviewSizeWidth, PreviewSizeHeight, FrameData, pixels); 3. Your function in the C/C++ file should be in the following format. Java_package_callingClass_nativeMethodWithParameters E.g: com.ied is my package name so it would be written as com_ied. Java_com_ied_CameraPreview_ImageProcessing( JNIEnv* env, jobject this, jint width, jint height, jbytearray NV21FrameData, jintarray outpixels) { //your code in C/C++ return booleanvalue; } 4. Now whenever you try to run your code, it will compile/build your native code and create a library under obj and lib folder with name as libclassname.so. In this example, it is libimageprocessing.so. So you need to load this library through you java code. static { } System.loadLibrary("ImageProcessing");// Just the name of the C/C++ file 5. If your C/C++ code contains error, the build will fail. Resolve the errors and try again. After build is successful and a library file is created, your android application is ready to use the native code.

4. Quad Detection 1. First, I tried Image processing (detecting edges) using Java (Sobel Algorithm) but it turned out to be very slow. It took around 10-12s for detecting edges and hence, it was not feasible for real time quadrilateral detection. Original Image Final Image 2. Next step I took was to use C++ for image processing part of the application. 3. Thanks to OpenCV they provide API for Canny Edge Detection that is written in C++.

4. For using C++ along with Java, I had to use Android NDK and CDT plug-in. 5. CDT plug-in for eclipse helps you to write and compile the code in C/C++. 6. Android NDK builds all the native code (C/C++) using ndk-build.cmd. All the native code will be built before the android application is built and launched. 7. After the native code is built, you will get a library file at the following location :-..\workspace\project_name\obj\local\armeabi-v7a\objs\ 8. In my current approach, I created a Camera View in Android which loads the above built native library (containing built C/C++ code) and using a thread constantly sends camera data to native code for processing and when a quadrilateral figure is detected, native code returns true as Boolean value and image is captured 5. Auto Capture when a Quadrilateral is detected 1. The data received by the camera view is passed to Open CV API for canny edge detection. 2. Next step to retrieve the contours from the data received after canny edge detection. 3. Going through each contour, skip small or non-convex objects and check if the contour has a size of 4. 4. If contour has size=4, then go through following steps: a. Number of vertices of polygonal curve b. Get the cosines of all corners c. Sort ascending the cosine values d. Get the lowest and the highest cosine e. Use the degrees obtained above to determine the shape of the contour f. If min Cosine value is greater than -0.1 and max Cosine value is <=0.3, we have a quadrilateral figure. g. Click the image instantly.