BlinkID C SDK version 5.16.0
C SDK documentation

Quick start

In order to perform recognition, you first need to create a concrete recognizer object. Each recognizer object is specific for each object that needs to be scanned. After creating required recognizer objects, you need to create recognizer runner object that will use given recognizer objects to perform recognition of images.

A simple example that uses generic ID recognizer to scan information from any ID document would look like this:

  1. (Android only) initialize Android JNI context. This is required on Android in order for license validation and resource loading to work.
    // jniEnv is of type "JNIEnv *" and available to every JNI funcion
    // context is of type "jobject" and must point to instance "android.content.Context" java object. It is recommended to use application context
    // to avoid memory leaks. For more information, please see: https://android-developers.googleblog.com/2009/01/avoiding-memory-leaks.html
    MB_API void MB_CALL recognizerAPIInitializeAndroidApplication(JNIEnv *env, jobject applicationContext)
    Sets the JNI application context to the SDK. This is required in order for SDK to be able to load res...
  2. (Desktop platforms only) define the location of cache folder. This is required to store some cache files when online licenses are used. On mobile platforms those files are stored into app's private folder, but on desktop platforms it is required to define a unique folder in order to avoid clashes with other applications using the same SDK.
    recognizerAPISetCacheLocation( "/path/to/cache/folder" );
    MB_API MBRecognizerErrorStatus MB_CALL recognizerAPISetCacheLocation(char const *cacheFolder)
    Sets the location where cache files will be stored on desktop platforms. The given folder may or may ...
  3. Insert your license key
    MBRecognizerErrorStatus errorStatus = recognizerAPIUnlockWithLicenseKey( "Add license key here" );
    {
    // handle failure
    }
    MB_API MBRecognizerErrorStatus MB_CALL recognizerAPIUnlockWithLicenseKey(char const *licenseKeyBase64)
    Unlocks the SDK with given license key encoded as base64 string. NOTE: This function is not thread sa...
    MBRecognizerErrorStatus
    Enumeration of all possible error statuses.
    Definition: RecognizerError.h:28
    @ MB_RECOGNIZER_ERROR_STATUS_SUCCESS
    Definition: RecognizerError.h:30
  4. Set path to folder containing resources required by the library. The function recognizerAPISetResourcesLocation requires absolute path to folder containing all files from "resources/non-android" folder from the distribution on all platforms except Android. On Android it requires relative path to folder within "assets" containing all files from the "resources/android" folder from the distribution.
    MBRecognizerErrorStatus errorStatus = recognizerAPISetResourcesLocation( "/path/to/resources/non-android" );
    {
    // handle failure
    }
    MB_API MBRecognizerErrorStatus MB_CALL recognizerAPISetResourcesLocation(char const *resourcePath)
    Sets the location where required resources will be loaded from. If not set, "res" folder within curre...
  5. Create and configure generic ID recognizer
    MBBlinkIdRecognizer * blinkIdRecognizer = NULL;
    // initialize default settings values
    // optionally tweak settings for your needs
    idSettings.allowBlurFilter = MB_TRUE;
    MBRecognizerErrorStatus errorStatus = = blinkIdRecognizerCreate( &blinkIdRecognizer, &idSettings );
    {
    // handle failure
    }
    #define MB_TRUE
    True constant for C SDK.
    Definition: Types.h:26
    #define MB_FALSE
    False constant for C SDK.
    Definition: Types.h:23
  6. Create and configure recognizer runner
    MBRecognizerPtr recognizers[] = { blinkIdRecognizer };
    runnerSett.numOfRecognizers = 1;
    runnerSett.recognizers = recognizers;
    MBRecognizerRunner * recognizerRunner = NULL;
    errorStatus = recognizerRunnerCreate( &recognizerRunner, &runnerSett );
    {
    // handle failure
    }
    void * MBRecognizerPtr
    Typedef for pointer to generic Recognizer object.
    Definition: Recognizer.h:32
    MBRecognizerRunner data structure.
    MB_API MBRecognizerErrorStatus MB_CALL recognizerRunnerCreate(MBRecognizerRunner **recognizerRunner, MBRecognizerRunnerSettings const *settings)
    Allocates and initializes the recognizer runner object.
    Recognizer runner settings data structure.
    Definition: RecognizerRunner.h:65
    size_t numOfRecognizers
    Definition: RecognizerRunner.h:84
    MB_API void MB_CALL recognizerRunnerSettingsDefaultInit(MBRecognizerRunnerSettings *)
    Populate MBRecognizerRunnerSettings structure with default values.
    MBRecognizerPtr const * recognizers
    Definition: RecognizerRunner.h:79
  7. Prepare the image to be recognized. Image first needs to be created from from memory. To create image from memory buffer use recognizerImageCreateFromRawImage.

    int image_width, image_height, image_stride;
    MBByte * image_buffer;
    // populate above variables (i.e. by loading image file or capturing image with camera)
    MBRecognizerErrorStatus status = recognizerImageCreateFromRawImage( &img, image_buffer, image_width, image_height, image_stride, MB_RAW_IMAGE_TYPE_BGR );
    printf("Failed to create image. Reason: %s", recognizerErrorToString(status));
    }
    MB_API char const *MB_CALL recognizerErrorToString(MBRecognizerErrorStatus errorStatus)
    @ MB_RAW_IMAGE_TYPE_BGR
    Definition: RecognizerImage.h:53
    unsigned char MBByte
    Byte type for C SDK.
    Definition: Types.h:29
    MBRecognizerImage data structure. Holds image on which recognition will bw performed.
    MB_API MBRecognizerErrorStatus MB_CALL recognizerImageCreateFromRawImage(MBRecognizerImage **image, MBByte const *input, uint16_t width, uint16_t height, uint16_t bytesPerRow, MBRawImageType rawType)
    Allocates and creates MBRecognizerImage object from raw image. NOTE: This function will not make copy...

    Alternatively, you can use recognizerImageLoadFromFile to directly create MBRecognizerImage by loading a supported file.

    MBRecognizerErrorStatus status = recognizerImageLoadFromFile( &img, "path/to/image.jpg" );
    printf("Failed to load image from file. Reason: %s", recognizerErrorToString(status));
    }
    MB_API MBRecognizerErrorStatus MB_CALL recognizerImageLoadFromFile(MBRecognizerImage **image, char const *path)
    Allocates and creates MBRecognizerImage object from given file. NOTE: Only JPG and PNG file types are...
  8. Once you have created an image, you can perform recognition using method recognizerRunnerRecognizeFromImage.
    MBRecognizerResultState resultState = recognizerRunnerRecognizeFromImage( recognizerRunner, imageWrapper.recognizerImage, MB_FALSE, NULL );
    if ( resultState != MB_RECOGNIZER_RESULT_STATE_EMPTY )
    {
    // obtain results from recognizers (see Step 4)
    }
    MBRecognizerResultState
    Definition: Recognizer.h:39
    @ MB_RECOGNIZER_RESULT_STATE_EMPTY
    Definition: Recognizer.h:41
    MB_API MBRecognizerResultState MB_CALL recognizerRunnerRecognizeFromImage(MBRecognizerRunner *recognizerRunner, MBRecognizerImage const *image, MBBool imageIsVideoFrame, MBRecognitionCallback const *callback)
    Performs recognition of given image.
  9. Obtain result structure from each of the recognizers. If some recognizer's result's state is MB_RECOGNIZER_RESULT_STATE_VALID, then it contains recognized data.
    blinkIdRecognizerResult( &result, blinkIdRecognizer );
    if ( result.baseResult.state == MB_RECOGNIZER_RESULT_STATE_VALID )
    {
    // you can use data from the result
    }
    @ MB_RECOGNIZER_RESULT_STATE_VALID
    Definition: Recognizer.h:53
  10. Finally, when done, clean the memory. Each structure has method for releasing it.
    recognizerRunnerDelete( &recognizerRunner );
    // make sure that recognizers are deleted *AFTER* recognizerRunner
    blinkIdRecognizerDelete( &blinkIdRecognizer );
    MB_API MBRecognizerErrorStatus MB_CALL recognizerImageDelete(MBRecognizerImage **image)
    Deletes the image object and sets pointer to NULL.
    MB_API MBRecognizerErrorStatus MB_CALL recognizerRunnerDelete(MBRecognizerRunner **recognizerRunner)
    Deletes the recognizer runner object and sets a pointer to it to NULL. Note that recognizers that wer...

Additional info

For any inquiries, additional information or instructions please contact us at help.microblink.com. When contacting, please state which product and which platform you are using so we can help you more quickly. Also, please state that you are using C SDK and state the version you are using. You can obtain the library version with function recognizerAPIGetVersionString.