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 Github repository contains binaries for Android, iOS, Raspberry Pi and Windows. The next sections explain how to add the SDK to an existing project.

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).

Linux, Windows, Raspberry Pi and Others

The shared libraries are under “ultimateALPR-SDK/binaries/**<platform>**”. The header file at “ultimateALPR-SDK/c++”. You can use any C++ compiler/linker.

The samples are under “ultimateALPR-SDK/samples/**<platform>**”.

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," +

        "\"pyramidal_search_enabled\": true," +
        "\"pyramidal_search_sensitivity\": 0.28," +
        "\"pyramidal_search_minscore\": 0.5," +
        "\"pyramidal_search_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.