BlinkID / blinkid-android

Everything you need to add AI-driven ID scanning into your native Android app.
https://microblink.com/identity/identity-document-scanning/
443 stars 153 forks source link

MRTD result display issue #160

Closed damolaobaleke closed 5 years ago

damolaobaleke commented 5 years ago

Hi, I'm trying to use the MrtdRecognizer and i have added some settings to my recognizer . It scans the document(International Passport) , although it takes a while on the Nokia 2 . The main issue i'm having is after the document has been scanned , the result isn't being displayed. I've followed the steps given in the "Performing your first scan" under the blink-id SDK for android,

However, I'm not getting the result displayed and neither am i obtaining the scanning results in the OnActivityResult method. The details are not being populated. After scanning is done what shows on the screen is my layout as seen in the image attached . Nokia2-Testing

Environment Details

**BlinkID version:4.9.1

**Device model:Nokia 2 | TA-1029

**Device Android version:7.1.1

**Device ABI (processor architecture, e.g. ARMv7):

Chipset - Qualcomm MSM8909v2 Snapdragon 212 (28 nm) CPU - Quad-core 1.3 GHz , ARMCortex-A7 GPU - Adreno 304.

LogFile-TestingScan.txt

Code Below `package Com.hackathon;

import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity;

import com.microblink.activity.DocumentScanActivity; import com.microblink.entities.recognizers.Recognizer; import com.microblink.entities.recognizers.RecognizerBundle; import com.microblink.entities.recognizers.blinkid.mrtd.MrtdRecognizer; //import com.microblink.results.ocr.OcrResult; import com.microblink.uisettings.ActivityRunner; import com.microblink.uisettings.DocumentUISettings;

import static Com.hackathon.MainActivity.MY_REQUEST_CODE;

public class MRTD extends AppCompatActivity { private MrtdRecognizer TravelDRecognizer; // Machine Readable travel document recognizer private RecognizerBundle mRecognizerBundle;

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.activity_self_on_boarding); // view is mapped to...

    //create InternationalPassport Recognizer object
    TravelDRecognizer = new MrtdRecognizer();

    //Initializing
    TravelDRecognizer.setReturnFullDocumentImage(true);
    TravelDRecognizer.setDetectGlare(true);

    // bundle MRDT recognizers into RecognizerBundle
    mRecognizerBundle = new RecognizerBundle(TravelDRecognizer);

    // declare scanning method to start scanning
    StartScanning();

    //com.microblink.util.Log.setLogLevel(com.microblink.util.Log.LogLevel.LOG_VERBOSE);
}

public void StartScanning() {
    // Settings for DocumentScanActivity(passport)
    DocumentUISettings settings_IntP = new DocumentUISettings(mRecognizerBundle);

    // Start activity
    ActivityRunner.startActivityForResult(this, MY_REQUEST_CODE, settings_IntP);
}

// Obtain scanning results from here
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == MY_REQUEST_CODE)
        if (resultCode == DocumentScanActivity.RESULT_OK && data != null) {
            // loading the data into MRTD recognizer bundled within my RecognizerBundle
            mRecognizerBundle.loadFromIntent(data);
            // now Machine readable travel document recognizer object that was bundled within RecognizerBundle
            // has been updated with results obtained during scanning session

            // Result gotten by invoking get result() on my recognizer
            MrtdRecognizer.Result result = TravelDRecognizer.getResult();

            if (result.getResultState() == Recognizer.Result.State.Valid) {
                //crop picture and compare to selfie
         }
     }
}

} `

Log file

Please enable logging by following instructions here and attach full log file.

Additional information

If there is anything else that you think can help us resolve the issue, write it here.

SandraZiv commented 5 years ago

Hi,

can you please provide code that shows how you use the result?

I added simple logging of the result as well as image preview in your code and it worked normally, here is a snippet:

...

if (result.getResultState() == Recognizer.Result.State.Valid) {
    Log.d("TEST_LOG", result.getMrzResult().getMrzText());

    // some ImageView to display result
    imageView.setImageBitmap(result.getFullDocumentImage().convertToBitmap());
}

Let me know if it works for you.

damolaobaleke commented 5 years ago

Hi,

Thank you. I'm still in the process of writing the code that shows how i use the result. Although i tried the snippet and it doesn't work for me yet. It currently gives me this error: "java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Bitmap com.microblink.image.Image.convertToBitmap()' on a null object reference".

//logging of result from debug messages Log.d("TEST_LOG", result.getMrzResult().getMrzText());

                      //---------------------- Some ImageView to display result
                // Initialize image view
                ImageView ImageResults =  findViewById(R.id.imageViewResults) 
                ImageResults.setImageBitmap(result.getFullDocumentImage().convertToBitmap());`

Then i tried using this line of code ImageResults.setImageBitmap(Objects.requireNonNull(result.getFullDocumentImage()).convertToBitmap()); It gives the java.lang.NullPointerException

SandraZiv commented 5 years ago

Hi,

what about just MRZ text? Can you read it?

Also please make sure that you have enabled getting full image document in Recognizer: recognizer.setReturnFullDocumentImage(true);

damolaobaleke commented 5 years ago

Hi,

Yes i can read the MRZ text. Also getting full image document has been set as well , you should see that in my earlier code. After the MRZ has been scanned/read the error comes up when trying to display the result with the imageview

damolaobaleke commented 5 years ago

Any ideas on whats wrong with the displaying of result @SandraKuzmic @culoi

i1E commented 5 years ago

Hi @damolaobaleke,

we have tested everything again and it seems that everything works fine in our samples. Can you please prepare minimal project with you integration code and send it to support@microblink.com. We will check where is the problem.

i1E commented 5 years ago

Also, can you please test our BlinkID_AllRecognizersSample. Does it work as expected on your device, are you able to obtain full document image from the MrtdRecognizer?

damolaobaleke commented 5 years ago

Hi @i1E,

I just tested the Blink_IDAllRecognizersSample and it works as expected. I am able to obtain a full image from the MrtdRecognizer, but i cant find where the result is being populated.

Please could you look at my code below and test it, see if it works, . `package Com.hackathon;

import android.content.Intent; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.ImageView;

import com.microblink.activity.DocumentScanActivity; import com.microblink.entities.recognizers.Recognizer; import com.microblink.entities.recognizers.RecognizerBundle; import com.microblink.entities.recognizers.blinkid.mrtd.MrtdRecognizer; //import com.microblink.results.ocr.OcrResult; //import com.microblink.image.Image; import com.microblink.entities.recognizers.blinkid.mrtd.MrzResult; import com.microblink.entities.recognizers.blinkid.passport.PassportRecognizer; import com.microblink.image.Image; import com.microblink.uisettings.ActivityRunner; import com.microblink.uisettings.DocumentUISettings; import com.microblink.util.Log;

import static Com.hackathon.MainActivity.MY_REQUEST_CODE;

public class MRTD extends AppCompatActivity { private MrtdRecognizer TravelDRecognizer; // Machine Readable travel document recognizer private RecognizerBundle mRecognizerBundle;

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.activity_drivers_l); // view is mapped to...

    //create InternationalPassport Recognizer object
    TravelDRecognizer = new MrtdRecognizer();

    //Initializing Travel document recognizer settings
    TravelDRecognizer.setReturnFullDocumentImage(true);
    TravelDRecognizer.setDetectGlare(true);
    TravelDRecognizer.shouldReturnFullDocumentImage();
    TravelDRecognizer.setEncodeFullDocumentImage(true);

    // bundle MRDT recognizers into RecognizerBundle
    mRecognizerBundle = new RecognizerBundle(TravelDRecognizer);

    // declare scanning method to start scanning
    StartScanning();

}

private void StartScanning() {
    // Settings for DocumentScanActivity(passport)
    DocumentUISettings Settings = new DocumentUISettings(mRecognizerBundle);

    // Start activity
    ActivityRunner.startActivityForResult(this, MY_REQUEST_CODE, Settings);
}
    // Confirm and cancel buttons
public void footerButtonClickHandler(View view) {
    // When confirm is clicked Go to selfie camera
    finish();
}

    // Obtain scanning results from here
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == MY_REQUEST_CODE)
        if (resultCode == DocumentScanActivity.RESULT_OK && data != null) {
            // loading the data into MRTD recognizer bundled within my RecognizerBundle
            mRecognizerBundle.loadFromIntent(data);

            // now Machine readable travel document recognizer object that was bundled within RecognizerBundle
            // has been updated with results obtained during scanning session

            // Result gotten by invoking get result() on my recognizer
            MrtdRecognizer.Result result = TravelDRecognizer.getResult();
            result.getFullDocumentImage();

            if (result.getResultState() == Recognizer.Result.State.Valid) {
                //logging of result from debug messages
                Log.d("TEST_LOG", result.getMrzResult().getMrzText());

            }
         }
     }
}

//com.microblink.util.Log.setLogLevel(com.microblink.util.Log.LogLevel.LOG_VERBOSE);--> For checking full log

);`

SandraZiv commented 5 years ago

Hi,

can you try adding this line of code MicroblinkSDK.setIntentDataTransferMode(IntentDataTransferMode.PERSISTED_OPTIMISED); in Application file where you set the license key?

Application file should look like this:

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        MicroblinkSDK.setLicenseFile("path/to/license/file/within/assets/dir", this);
        MicroblinkSDK.setIntentDataTransferMode(IntentDataTransferMode.PERSISTED_OPTIMISED);
    }
}

Then try to show result image in your activity.

damolaobaleke commented 5 years ago

Hi,

That line of code fixed it, thank you. It reads the machine readable zone now and shows the full document image, but only the full document image. Is there a way it can read it and extract all the data in different fields,(for example, primary ID, Expiry date etc.). Just like in the sample/Demo. Would i have to create several Textviews to display that and arrange it or is there a method ?

Also i still cant find where its being extracted, even in the BlinkID_AllRecognizersSample. I'd expect it to be extracted into an object, which is the (result) created. Thank you

damolaobaleke commented 5 years ago

Please where do i find the recognition results as well@SandraKuzmic @i1E . Thank you

SandraZiv commented 5 years ago

Hi,

yes, you can extract various fields from MrzResult. List of all fields and its data types are listed in the documentation. You have to arrange it in your layout by yourself as shown in the sample we sent or you can check out how our ResultActivity from BlinkIDSample is implemented.

Image is originally extracted as an instance of class Image which is part of Microblink SDK and it has a method convertToBitmap() which allows you to display it as Android Bitmap which is used in the sample.

Recognition Result can be extracted in an object from your recognizer: recognizer.getResult(), the complete code is provided in the sample as well.

damolaobaleke commented 5 years ago

Hi,

Thanks for this. In the process of displaying ,i noticed the Date of Birth and Date of expiry cant be displayed with a Textview because that's the wrong Layout tag. Although i also saw the Modifier & type to be DateResult. How can this dates be displayed please ?. In other words, which layout tag displays the custom created Modifier(DateResult) @SandraKuzmic . Thank you

SandraZiv commented 5 years ago

Hi,

DateResult is our class for capturing date from documents. It has a method for getting String representation of date: getOriginalDateString() and getStringResult() which can then be passed to TextView and displayed.

More information about these methods can be found here.

damolaobaleke commented 5 years ago

Hi,

I tried this, Please look at my code DateResult dateofbirth = new DateResult(); dateofbirth.getOriginalDateString(((TextView) findViewById(R.id.DOBd)));

I get the error : getOriginalDateString( ) in DateResult cannot be appliedto(android.widget.TextView) @SandraKuzmic  

damolaobaleke commented 5 years ago

Hi,

Please i'd also like to let you know that the UsdlCombinedRecognizer isn't scanning the Nigerian drivers License fully, it scans the front but not the back. Could you please check this out ? Thank you @i1E @SandraKuzmic

This same Environment: **BlinkID version:4.9.1

**Device model:Nokia 2 | TA-1029

**Device Android version:7.1.1

**Device ABI (processor architecture, e.g. ARMv7):

Chipset - Qualcomm MSM8909v2 Snapdragon 212 (28 nm) CPU - Quad-core 1.3 GHz , ARMCortex-A7 GPU - Adreno 304.

SandraZiv commented 5 years ago

Hi,

here is sample code for displaying date result in TextView:

// save date result in String variable
dateText = result.getMrzResult().getDateOfBirth.getOriginalDateString();

// display text in textview
((TextView) findViewById(R.id.DOBd)).setText(dateText);

Regarding your problem with scanning Nigerian drivers license, can you please try scanning it with our official app BlinkId and let me know if it works there.

damolaobaleke commented 5 years ago

Hi,

I actually tried scanning it with both the Allrecognizers Sample and the official app BlinkId and it didnt work on either of them.

SandraZiv commented 5 years ago

Hi,

can you please send images of that document (Nigerian Drivers License) to support@microblink.com so we can check it and see where the problem is.

damolaobaleke commented 5 years ago

Hi,

Thank you. I will do that now , although I've just found out that it works on a different environment. The Blinkid app scans the drivers license on this environment. Could the camera of the Nokia 2 be the problem or the nokia 2 itself be the problem ? Infinix smart 3: Android version 9.0(pie) RAM - 1GB Cortex-A53

i1E commented 5 years ago

Hi @damolaobaleke,

thank you for the report. Unfortunately, we don't have Nokia 2 at the office to test on it.

The quality of the device and camera definitely affects the scanning process, the Nokia 2 is a low end device and it is possible that it has some problems with reading high density barcodes from the back side of the driver's license.

You can try scanning in landscape orientation to make the barcode as close as possible.

damolaobaleke commented 5 years ago

Hi@i1E @SandraKuzmic

Thanks for the answer, i'll try that. I'm currently using the Liveness recognizer class and i keep trying to use the terminatenative() method from the documentation, but i cant access it with my Liveness recognizer object, because its protected . Please how is this method used ? Also i'm trying to use it because i get this error in my code

No implementation found for long com.microblink.entities.recognizers.liveness.LivenessRecognizer.nativeConstruct() (tried Java_com_microblink_entities_recognizers_liveness_LivenessRecognizer_nativeConstruct and Java_com_microblink_entities_recognizers_liveness_LivenessRecognizer_nativeConstruct__)

Thank you.

i1E commented 5 years ago

Hi @damolaobaleke,

LivenessRecognizer is not part of the BlinkID SDK, how did you get that error? Which library dependencies do you have in your application?

damolaobaleke commented 5 years ago

Hi@i1E

I should have noted it to you. I'm also now using the Blink-id verify SDK thats why, so i have this dependency implemented now implementation project(':LibPhotoPay').

So i'm using the liveness recognizer now as well

i1E commented 5 years ago

Hi @damolaobaleke,

then please contact us at support@microlblink.com, I am closing this issue because it is not relevant for BlinkID SDK.