bdswiss erfahrung

Welcome, Guest
Username: Password: Remember me

TOPIC: ONYX 3.x Getting Started Guide

ONYX 3.x Getting Started Guide 03 Jul 2014 19:27 #8

  • wlucas
  • wlucas's Avatar
  • Offline
  • Administrator
  • Posts: 4
  • Karma: 0
Welcome to the Onyx SDK, and thank you for purchasing it! In the following guide, you will learn
how to setup a simple “Hello World” style application utilizing the Onyx SDK. This guide will
hopefully act as a springboard for integrating Onyx with your new or existing projects.
You will need a few things to get started with Onyx for Android:
OpenCV SDK for Android (2.4.5 or later)
● Onyx SDK for Android (included with this guide)
Eclipse ADT enabled IDE (make sure NDK Plugins are enabled)
Android NDK

Creating the project
First, we’ll start off creating the project.
Click File >> New >> Android Application Project.

Make sure the Minimum Required SDK version is API 14: Android 4.0 (IceCreamSandwich). Compile With can be set to the latest API level.

We don’t require a custom icon for this project, so we uncheck the Create custom launcher icon field.

Finally, we choose Blank Activity and then finish up creating the project.

Adding OpenCV and Onyx SDKs
In this section, we will be adding the OpenCV and Onyx dependencies to the project.

Add C++ Nature to the project
Our SDK utilizes the Android NDK, so we will need to add C++ capabilities in our project. Add C++ Nature by right-clicking OnyxHelloWorld >> New >> Other...

Under C/C++ select Convert to a C/C++ Project (Adds C/C++ Nature), and click Next.

Select Makefile project under Project type, and --Other Toolchain-- under Toolchains, and click Finish.

Add helper environment variables to project
Now that we have a C/C++ nature we can add some environment variables to help with the NDK build process. Right-click on OnyxHelloWorld >> Properties >> C/C++ Build >> Environment. Click the Add... button and create an environment variable called OPENCV_ANDROID_ROOT. This path should point to the base folder of the OpenCV Android SDK (e.g., <YOUR-DOWNLOAD-LOCATION>\OpenCV-X.Y.Z-android-sdk):

We will do the same thing again for the ONYX_ANDROID_ROOT variable:

Finally, one last time for the NDKBUILDCMD. On Windows, you should set this to ndk-build.cmd on Linux this should be set to ndk-build:

Configure external builder
In this step, we will set the ndk-build to be the default builder. In order to do this, right-click on OnyxHelloWorld >> Properties >> C/C++ Build. Under the Builder Settings tab uncheck Use default build command and enter: ${NDKROOT}/${NDKBUILDCMD} for the Build command. Click OK when done.

Add jni resources to project
We will add JNI resources to the project to enable the use of both OpenCV and Onyx SDKs. Right-click the OnyxHelloWorld >> New >> Folder. Make sure the Folder name: field reads jni:

Next, add two files to the jni folder: and

In the file, add the following code:
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)


include $(OPENCV_ANDROID_ROOT)/sdk/native/jni/

In the file, add the code below:
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-14

To test these settings (make sure you are in the Java Perspective within Eclipse), select Project >> Build Project. If all is successful, you should see console output similar to the following:
11:56:40 **** Incremental Build of configuration Default for project OnyxHelloWorld ****
/home/wlucas/android-ndk-r8e/ndk-build all 
Install        : => libs/armeabi-v7a/
Prebuilt       : <= /home/wlucas/src/onyx-X.Y.Z-android-sdk/libs/armeabi-v7a/
Install        : => libs/armeabi-v7a/

11:56:41 Build Finished (took 167ms)

11:56:41 Build Finished (took 167ms)

Import OpenCV Android SDK to project
To import the OpenCV Android SDK (i.e., the Java interface), select File >> Import... Next, select Android >> Existing Code Into Workspace, and click Next:

On the following screen, navigate to the OpenCV SDK folder (e.g., OpenCV-2.4.5-android-sdk/sdk), and click Finish:

Add OpenCV Library to the project
Right-click OnyxHelloWorld >> Properties >> Android. Click the Add... button and select OpenCV Library - 2.4.5. If successful, you should see the library appear as is shown below:

Add Onyx Library to the project
Right-click OnyxHelloWorld >> Properties >> Java Build Path. Select the Libraries tab; click Add External JARs... Navigate the onyx-X.Y.Z.jar file located under your onyx-X.Y.Z-android-sdk folder. It should look like below:

Next, we need to make sure it is enabled to work properly. Now, click on the Order and Export tab. Make sure onyx-X.Y.Z.jar is checked. Click OK when done.

Optionally add Onyx Javadocs to the Onyx library
Right-click OnyxHelloWorld >> Properties >> Java Build Path and go the Libraries tab. Expand the onyx-X.Y.Z.jar item and select Javadoc as is shown below:

Once Javadoc is selected, click the Edit... button. Browse to your $(ONYX_ANDROID_ROOT)/onyx-javadocs folder and click OK.

Adding Onyx User Interface to the project
Now that the libraries are setup correctly, we can finally start to code!

Add permissions and features to the AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET"/>

<uses-feature android:name="" />
<uses-feature android:name="" />
<uses-feature android:name="android.hardware.flash" />

Add an OnyxFragment to the Activity’s layout
We will start off by removing the default TextView Android added for us in the res/layout/activity_main.xml file. In it’s place we’ll add the OnyxFragment. You should have something like the following:
<RelativeLayout xmlns:android=""
    tools:context=".MainActivity" >

    <fragment android:name="com.dft.onyx.ui.OnyxFragment"
        android:layout_height="match_parent" />


Initialize JNI libraries for OpenCV and Onyx
Add the following code above the onCreate method, and add the necessary imports.
private static final String TAG = MainActivity.class.getSimpleName();

static {
	if(!OpenCVLoader.initDebug()) {
		Log.d(TAG, "Unable to load OpenCV!");
	} else {
		Log.i(TAG, "OpenCV loaded successfully");

Integrating Onyx Licensing code
Add the following onResume method to your
protected void onResume() {

	License lic = License.getInstance(this);
	try {
	} catch (LicenseException e) {
            // Notify user of error as desired...

You will need to add your license key to the application that was provided to you either for trial or purchase.

Now let’s build the project and make sure it runs. Select Project >> Build Project, and then click the Run icon. You should see a camera preview with an ellipse in the center.

Working with the Onyx Fragment callbacks
At this point, you should have a working camera preview. Now let’s actually start capturing some fingerprints.

Adding callbacks to the OnyxFragment
Add two member variables to your MainActivity:
private FingerprintTemplate mCurrentTemplate = null;
private FingerprintTemplate mPreviousTemplate = null;
private OnyxFragment mFragment = null;

Next, create a callback handler for errors:
private OnyxFragment.ErrorCallback mErrorCallback = new OnyxFragment.ErrorCallback() {

	public void onError(Error arg0, String arg1, Exception arg2) {
		switch(arg0) {
			Log.d(TAG, "Error occurred: " + arg1);


Finally, create a callback handler to handle the fingerprint template that gets captured:
private FingerprintTemplateCallback mTemplateCallback = new FingerprintTemplateCallback() {

	public void onFingerprintTemplateReady(FingerprintTemplate fingerprintTemplate) {
		if(mCurrentTemplate == null) {
			mCurrentTemplate = fingerprintTemplate;
		} else {
			mPreviousTemplate = mCurrentTemplate;
			mCurrentTemplate = fingerprintTemplate;
			float matchScore;
			try {
				matchScore = tfp.verify(mPreviousTemplate, mCurrentTemplate);
				if(matchScore >= 0.1) {
							"Successful match: " + matchScore,
				} else {
							"Failed to match: " + matchScore,
			} catch (Exception e) {
				Log.e(TAG, "Verify failed: " + e.getMessage());




This callback handler creates a very simple matching pipeline for illustration, you will not want to use this in production most likely. It just illustrates the key points of capturing and matching fingerprint templates. If two sequential prints are the same, it will match. Otherwise, it will not match.

In your onCreate method, add the following code to capture a FingerprintTemplate:
mFragment = (OnyxFragment)getFragmentManager()
mFragment.setProcessingCallbacks(null, null, mTemplateCallback);

Run the demo application again, and place your fingertip underneath the ellipse reticle and wait for the app to automatically capture your fingerprint. Continue capturing fingerprints to see the Toast messages appear.

You can also find the full source code for this project and others under your $(ONYX_ANDROID_ROOT)/samples folder.
Last Edit: 19 Nov 2014 21:43 by wlucas. Reason: Prepping for ONYX 4.x launch
The administrator has disabled public write access.
Time to create page: 0.164 seconds