Getting started

The SDK works on many platforms and comes with support for many programming languages but this section focus on Android and Java. Please check the previous section for more information on how to use the sample applications.

Adding the SDK to your project (Android)

The SDK is distributed as an Android Studio module and you can add it as reference or you can also build it and add the AAR to your project. I’m more comfortable with C++ on Visual Studio or Xcode and I find Android Studio buggy and very hard to configure. For example, when I downloaded OpenALPR for Android project for the benchmark (speed comparison) it failed to build because the gradle version wasn’t install and I had to change it. Then, the maven repository was missing and I had to correct it. Then, the build task failed because the value defined in “compileSdkVersion” was not supported. Fixed the version and I still have warnings (mostly deprecated features) in build.gradle.

So, to make your life easier we’ll not recommend referencing the SDK project in your application but just add references to the sources:

In your build.gradle file add:

android {

 # This is the block to add within "android { } " section
 sourceSets {
  main {
   jniLibs.srcDirs += ['path-to-your-ultimateALPR-SDK/binaries/android/jniLibs']
   java.srcDirs += ['path-to-your-ultimateALPR-SDK/java/android']
   assets.srcDirs += ['path-to-your-ultimateALPR-SDK/assets/models']
  }
 }


}

If you prefer adding the SDK as reference, then we assume you’re an experimented developer and will find how to do it by yourself or just check the sample applications (they are referencing the SDK project instead of including the sources).

Using the API (Android)

It’s hard to be lost when you try to use the API as there are only 3 useful functions: init, process and deInit.

The C++ API is defined here.

import org.doubango.ultimateAlpr.Sdk.ULTALPR_SDK_IMAGE_TYPE;
import org.doubango.ultimateAlpr.Sdk.UltAlprSdkEngine;
import org.doubango.ultimateAlpr.Sdk.UltAlprSdkParallelDeliveryCallback;
import org.doubango.ultimateAlpr.Sdk.UltAlprSdkResult;

final static String CONFIG = "{" +
        "\"debug_level\": \"info\"," +
        "\"gpgpu_enabled\": true," +

        "\"detect_minscore\": 0.1," +
        "\"detect_quantization_enabled\": true," +

        "\"recogn_score_type\": \"min\"," +
        "\"recogn_minscore\": 0.3," +
        "\"recogn_rectify_enabled\": false," +
        "\"recogn_quantization_enabled\": true" +
"}";

/**
* Parallel callback delivery function used to notify about new results.
* This callback will be called few milliseconds (before next frame is completely processed)
* after process function is called.
*/
static class MyUltAlprSdkParallelDeliveryCallback extends UltAlprSdkParallelDeliveryCallback {
        @Override
        public void onNewResult(UltAlprSdkResult result) { }
}

final MyUltAlprSdkParallelDeliveryCallback mCallback = new MyUltAlprSdkParallelDeliveryCallback(); // set to null to disable parallel mode

@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        // Initialize the engine
        assert UltAlprSdkEngine.init(
                        getAssets(),
                        CONFIG,
                        mCallback
        ).isOK();
}

// Camera listener: https://developer.android.com/reference/android/media/ImageReader.OnImageAvailableListener
final ImageReader.OnImageAvailableListener mOnImageAvailableListener = new ImageReader.OnImageAvailableListener() {

        @Override
        public void onImageAvailable(ImageReader reader) {
                        try {
                            final Image image = reader.acquireLatestImage();
                            if (image == null) {
                                return;
                            }

                            // ANPR/ALPR recognition
                            final Image.Plane[] planes = image.getPlanes();
                            final UltAlprSdkResult result = UltAlprSdkEngine.process(
                                ULTALPR_SDK_IMAGE_TYPE.ULTALPR_SDK_IMAGE_TYPE_YUV420P,
                                planes[0].getBuffer(),
                                planes[1].getBuffer(),
                                planes[2].getBuffer(),
                                image.getWidth(),
                                image.getHeight(),
                                planes[0].getRowStride(),
                                planes[1].getRowStride(),
                                planes[2].getRowStride(),
                                planes[1].getPixelStride()
                            );
                            assert result.isOK();

                            image.close();

                        } catch (final Exception e) {
                           e.printStackTrace();
                        }
        }
};

@Override
public void onDestroy() {
        // DeInitialize the engine
        assert UltAlprSdkEngine.deInit().isOK();

        super.onDestroy();
}

Again, please check the sample applications for more information.