java neural network
Forum  |  Blog  |  Wiki  
Get Java Neural Network Framework Neuroph at SourceForge.net. Fast, secure and Free Open Source software downloads
      

CREATING ANDROID IMAGE RECOGNITION APPLICATION USING NETBEANS AND NEUROPH

by Dalibor Micic

This guide will give you an overview on how to develop simple Android application for image recognition using NetBeans 7, NBAndroid plugin and Neuroph framework version 2.6.

Android SDK installation guide

Download Android SDK starter package from http://developer.android.com/sdk/index.html (the SDK starter package is not a full development environment-it includes only the core SDK Tools, which you can use to download the rest of the SDK components (such as the latest Android platform).

If you downloaded the Windows installer (.exe file), run it now and it will check whether the proper Java SE Development Kit (JDK) is installed (installing it, if necessary), then install the SDK Tools into a default location (which you can modify). Make a note of the name and location of the SDK directory on your system - you will need to refer to the SDK directory later, when using the SDK tools from the command line.

After the installation is completed start SDK Manager.

You need to download at least one platform into your environment, so that you will be able to compile an application and set up an Android Virtual Device (AVD) to run it on (in the emulator). Android 2.1 is supported on approximately 98% of Android phones and this is the platform that is going to be used in this example. You can also download other platforms as well.

SDK Platform-tools includes more tools that are required for application development. These tools are platform-dependent and typically update only when a new SDK platform is made available, in order to support new features in the platform. These tools are always backward compatible with older platforms, but you must be sure that you have the latest version of these tools when you install a new SDK platform.

The Samples components give you source code that you can use to learn about Android, load as a project and run, or reuse in your own app. Note that multiple samples components are available - one for each Android platform version. When you are choosing a samples component to download, select the one whose API Level matches the API Level of the Android platform that you plan to use. To be able to run this example, select Tools -> Android SDK Platform-tools and Android 2.1 (API 7) -> SDK Platform and install them.

NBAndroid installation guide

NBAndroid (http://www.nbandroid.org) is a plugin that provides support for the whole development cycle of Android applications and it will be used in this example.

Installation is very simple. Open plug-in manager in NetBeans (Tools -> Plugins) and select Settings tab. Click on Add and add following URL http://kenai.com/projects/nbandroid/downloads/download/updatecenter/updates.xml

Press OK and go to Available plugins. Select Android and Android Test Runner For NetBeans 7.0+ (there is also Android Test Runner For NetBeans 6.9 and NetBeans 6.9.1 for use with older versions of NetBeans) and install them.

Next step is to configure Android SDK path. Go to Tools -> Options, open Miscellaneous tab and specify location of Android SDK.

Android test application

Create new Android project in NetBeans, go to File -> New Project and select Android project. On next screen select target platform (in our case it is Android 2.1). We can rename activity that will automatically be created for us (an activity is an application component that provides a screen with which users can interact in order to do something. Each activity is given a window in which to draw its user interface. More about Activities on http://developer.android.com/guide/topics/fundamentals/activities.html)

Application is going to be very simple, it will first load neural network and then it will display the main screen. By tapping anywhere on the main screen, it will open a phone's gallery. After selecting an image from gallery, it will show the selected image and display the name of the recognized image.

Layout is defined in layout/main.xml and string values are defined in values/strings.xml

Neural network (.nnet file) should be placed in folder /raw. In order to run the application, AVD (Android Virtual Device) needs to be created first. Go to ANDROID_SDK_ROOT and start AVD Manager.

Press New and create a new AVD.

After creating a new AVD, the created AVD will be shown in list of existing Android Virtual Devices.

Close this window and go back to NetBeans. In order to start the application, select project and press F6. After a few seconds, the Select device dialog is shown with previously created Neuroph_Emulator AVD already selected. Press OK and wait until the emulator is loaded (this may take some time).

Select Neuroph Example from applications list.

Application loads neural network on start.

If you wish to create your own neural network using Neuroph, please read Image recognition with neural networks.

Important notice: When you a load neural network in Android, you need to do it in a separate thread with increased stack size

new Thread(null, loadDataRunnable, "networkLoader", 32000).start();

or you will get a java.lang.StackOverflowError.

After it finishes loading, click on "Tap here" and select an image from gallery (gallery shows all images from your phone or, in this case, from emulator. At this point, gallery is empty so we need to put some images. On Windows, go to Start -> Run, type cmd and press OK. Android Debug Bridge (adb) is a command line tool that lets you communicate with an emulator instance or connected Android-powered device and it is located in ANDROID_SDK_ROOT\platform-tools. To put an image on the phone, use the following command:

adb push mypic.jpg /sdcard/

Close the emulator and run the project once again. After loading a neural network, click on "Tap here to select image" and select an image from gallery. Application will try to recognize the image and it will ouput the result.


DOWNLOAD:

Source code for Neuroph Android Example can be downloaded from here.

See also:

Image Recognition with Neural Networks How To

      Java Get Powered      Java Get Powered                           Get Java Neural Network Framework Neuroph at SourceForge.net. Fast, secure and Free Open Source software downloads