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. But, the easiest way to add the SDK to your project is by directly including the source.

In your build.gradle file add:

android {

 # This is the block to add within "android { } " section
 sourceSets {
  main {
   jniLibs.srcDirs += ['path-to-your-ultimateCreditCard-SDK/binaries/android/jniLibs']
   java.srcDirs += ['path-to-your-ultimateCreditCard-SDK/java/android']
   assets.srcDirs += ['path-to-your-ultimateCreditCard-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.ULTCCARD_SDK_IMAGE_TYPE;
import org.doubango.ultimateAlpr.Sdk.UltCreditCardSdkEngine;
import org.doubango.ultimateAlpr.Sdk.UltCreditCardSdkResult;

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

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

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

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

        // Initialize the engine
        assert UltCreditCardSdkEngine.init(
                        getAssets(),
                        CONFIG
        ).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;
                            }

                            // Credit card detection and recognition
                            final Image.Plane[] planes = image.getPlanes();
                            final UltCreditCardSdkResult result = UltCreditCardSdkEngine.process(
                                ULTCCARD_SDK_IMAGE_TYPE.ULTCCARD_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();

                                // The result contains JSON string to parse in order to get recognitions
                                // result.json();

                            image.close();

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

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

        super.onDestroy();
}

Again, please check the sample applications for more information.