Skip to content

Commit

Permalink
Merge pull request #218 from BlinkID/release/v5.6.0
Browse files Browse the repository at this point in the history
Release/v5.6.0
  • Loading branch information
i1E authored Jul 17, 2020
2 parents 338466a + 3791f4f commit e3b33ca
Show file tree
Hide file tree
Showing 78 changed files with 5,172 additions and 573 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android:
components:
- platform-tools
- tools
- build-tools-28.0.3
- build-tools-29.0.2
- android-29
- extra-android-m2repository
script:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
android:name="com.microblink.blinkid.imagescan.ScanImageActivity"
android:screenOrientation="portrait" />

<activity
android:name="com.microblink.blinkid.imagescan.CombinedScanImageActivity"
android:screenOrientation="portrait" />

</application>

</manifest>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.microblink.blinkid.customcamera.Camera1Activity;
import com.microblink.blinkid.customcamera.camera2.Camera2Activity;
import com.microblink.blinkid.demo.R;
import com.microblink.blinkid.imagescan.CombinedScanImageActivity;
import com.microblink.blinkid.imagescan.ScanImageActivity;
import com.microblink.entities.Entity;
import com.microblink.entities.recognizers.Recognizer;
Expand Down Expand Up @@ -72,6 +73,13 @@ public void run() {
}
}));

items.add(new MenuListItem("Scan with combined recognizer", new Runnable() {
@Override
public void run() {
startScanActivityForResult(CombinedScanImageActivity.class);
}
}));

items.add(new MenuListItem("Camera 1 activity", new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -115,6 +123,7 @@ private void startScanActivityForResult(Class activityClass) {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
mRecognizerBundle.loadFromIntent(data);
Recognizer recognizer = mRecognizerBundle.getRecognizers()[0];
Entity.Result result = recognizer.getResult();
if (!(result instanceof MrtdRecognizer.Result)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
package com.microblink.blinkid.imagescan;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.microblink.blinkid.demo.R;
import com.microblink.directApi.DirectApiErrorListener;
import com.microblink.directApi.RecognizerRunner;
import com.microblink.entities.recognizers.RecognizerBundle;
import com.microblink.entities.recognizers.blinkid.generic.BlinkIdCombinedRecognizer;
import com.microblink.hardware.orientation.Orientation;
import com.microblink.metadata.MetadataCallbacks;
import com.microblink.metadata.recognition.FirstSideRecognitionCallback;
import com.microblink.recognition.RecognitionSuccessType;
import com.microblink.view.recognition.ScanResultListener;

import java.io.IOException;
import java.io.InputStream;

import androidx.annotation.NonNull;

public class CombinedScanImageActivity extends Activity {

private static final String ASSETS_BITMAP_NAME_FRONT_SIDE = "cro_ID_front1.jpg";
private static final String ASSETS_BITMAP_NAME_BACK_SIDE = "cro_ID_back1.jpg";

private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888;

private static final String TAG = "CombinedScanImage";

/** Scan action button */
private Button mScanButton;

/** Front side bitmap for recognition. */
private Bitmap mFrontBitmap;
/** Back side bitmap for recognition. */
private Bitmap mBackBitmap;

/** Progress dialog shown while recognition is in progress */
private ProgressDialog mProgress;

/** Recognizer for scanning front and back side of a document */
private BlinkIdCombinedRecognizer mBlinkIdCombinedRecognizer = new BlinkIdCombinedRecognizer();

/** RecognizerRunner that will run recognizers on given image */
private RecognizerRunner mRecognizerRunner;

/** Flag which indicates whether first side of a document has been successfully scanned or not */
private boolean mFirstSideScanned = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan_image_combined);

mScanButton = findViewById(R.id.btnScan);
mFrontBitmap = readImageFromAssets(ASSETS_BITMAP_NAME_FRONT_SIDE);
mBackBitmap = readImageFromAssets(ASSETS_BITMAP_NAME_BACK_SIDE);

ImageView ivImageFront = findViewById(R.id.ivImageFront);
ivImageFront.setImageBitmap(mFrontBitmap);
ImageView ivImageBack = findViewById(R.id.ivImageBack);
ivImageBack.setImageBitmap(mBackBitmap);

}

private Bitmap readImageFromAssets(String assetName) {
// initial bitmap is loaded from assets
AssetManager assets = getAssets();
InputStream istr = null;
try {
istr = assets.open(assetName);
// load initial bitmap from assets
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = BITMAP_CONFIG;
return BitmapFactory.decodeStream(istr, null, options);
} catch (IOException e) {
// handle exception
Log.e(TAG, "Failed to load image from assets!");
Toast.makeText(this, "Failed to load image from assets!", Toast.LENGTH_LONG).show();
finish();
return null;
} finally {
if (istr != null) {
try {
istr.close();
} catch (IOException ignorable) {
// do nothing
}
}
}
}

@Override
protected void onStart() {
super.onStart();

// get the recognizer runner instance
mRecognizerRunner = RecognizerRunner.getSingletonInstance();

MetadataCallbacks metadataCallbacks = new MetadataCallbacks();
// set first side recognition callback to be notified when front side is successfully scanned
metadataCallbacks.setFirstSideRecognitionCallback(mFirstSideRecognitionCallback);
mRecognizerRunner.setMetadataCallbacks(metadataCallbacks);

// initialize recognizer runner singleton
mRecognizerRunner.initialize(this, new RecognizerBundle(mBlinkIdCombinedRecognizer), new DirectApiErrorListener() {
@Override
public void onRecognizerError(@NonNull Throwable t) {
Log.e(TAG, "Failed to initialize recognizer.", t);
Toast.makeText(CombinedScanImageActivity.this, "Failed to initialize recognizer. Reason: "
+ t.getMessage(), Toast.LENGTH_LONG).show();
finish();
}
});
}

/**
* Handler for button "Scan"
*/
public void scanButtonHandler(View view) {
if (mFrontBitmap == null || mBackBitmap == null) {
return;
}

// disable button
mScanButton.setEnabled(false);
// show progress dialog
mProgress = new ProgressDialog(this);
mProgress.setIndeterminate(true);
mProgress.setMessage("Performing recognition");
mProgress.setCancelable(false);
mProgress.show();

// reset recognition state to clear all previous results
mRecognizerRunner.resetRecognitionState();
// send front side image to recognition
mRecognizerRunner.recognizeBitmap(
mFrontBitmap,
Orientation.ORIENTATION_LANDSCAPE_RIGHT,
mScanResultListenerFrontSide
);
}

@Override
protected void onStop() {
super.onStop();
if (mRecognizerRunner != null) {
// terminate the native library
mRecognizerRunner.terminate();
}
}

FirstSideRecognitionCallback mFirstSideRecognitionCallback = new FirstSideRecognitionCallback() {
@Override
public void onFirstSideRecognitionFinished() {
mFirstSideScanned = true;
}
};

private ScanResultListener mScanResultListenerFrontSide = new ScanResultListener() {
@Override
public void onScanningDone(@NonNull RecognitionSuccessType recognitionSuccessType) {
if (mFirstSideScanned) {
// send back side image to recognition
mRecognizerRunner.recognizeBitmap(
mBackBitmap,
Orientation.ORIENTATION_LANDSCAPE_RIGHT,
mScanResultListenerBackSide
);
} else {
prepareForNextCombinedRecognition();
showFailureMessage();
}
}
};

private ScanResultListener mScanResultListenerBackSide = new ScanResultListener() {
@Override
public void onScanningDone(@NonNull RecognitionSuccessType recognitionSuccessType) {
prepareForNextCombinedRecognition();
if (recognitionSuccessType != RecognitionSuccessType.UNSUCCESSFUL) {
showResultsDialog(mBlinkIdCombinedRecognizer.getResult());
} else {
showFailureMessage();
}
}
};

private void showResultsDialog(BlinkIdCombinedRecognizer.Result result) {
StringBuilder sbResults = new StringBuilder();
String newline = String.format("%n");
sbResults.append("First name: ").append(result.getFirstName()).append(newline);
sbResults.append("Last name: ").append(result.getLastName()).append(newline);
sbResults.append("Personal number: ").append(result.getPersonalIdNumber()).append(newline);
// ... there are also other result fields to extract

new AlertDialog.Builder(this)
.setTitle("Scan results")
.setMessage(sbResults.toString())
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.create()
.show();
}

private void showFailureMessage() {
Toast.makeText(CombinedScanImageActivity.this, "Nothing scanned!", Toast.LENGTH_SHORT).show();
}

private void prepareForNextCombinedRecognition() {
mFirstSideScanned = false;
runOnUiThread(new Runnable() {
@Override
public void run() {
mScanButton.setEnabled(true);
mProgress.dismiss();
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.microblink.directApi.RecognizerRunner;
import com.microblink.entities.recognizers.RecognizerBundle;
import com.microblink.hardware.orientation.Orientation;
import com.microblink.recognition.FeatureNotSupportedException;
import com.microblink.recognition.RecognitionSuccessType;
import com.microblink.view.recognition.ScanResultListener;

Expand Down Expand Up @@ -66,7 +65,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_scan_image);

mScanButton = findViewById(R.id.btnScan);
mImgView = findViewById(R.id.imgImage);
mImgView = findViewById(R.id.ivImageFront);

Intent intent = getIntent();
mRecognizerBundle.loadFromIntent(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</RelativeLayout>

<ImageView
android:id="@+id/imgImage"
android:id="@+id/ivImageFront"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >

<Button
android:id="@+id/btnScan"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:onClick="scanButtonHandler"
android:text="@string/scan" >
</Button>
</RelativeLayout>

<ImageView
android:id="@+id/ivImageFront"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/toolbar" />

<ImageView
android:id="@+id/ivImageBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/ivImageFront" />

</RelativeLayout>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected void extractData(BlinkIdCombinedRecognizer.Result result) {
add(R.string.PPIssueDate, result.getDateOfIssue());
add(R.string.PPDateOfExpiry, result.getDateOfExpiry());
add(R.string.PPDateOfExpiryPermanent, result.isDateOfExpiryPermanent());
add(R.string.PPExpired, result.isExpired());

add(R.string.PPPlaceOfBirth, result.getPlaceOfBirth());
add(R.string.PPNationality, result.getNationality());
Expand Down Expand Up @@ -61,11 +62,13 @@ protected void extractData(BlinkIdCombinedRecognizer.Result result) {
extractMRZResult(result.getMrzResult());
}

add(R.string.MBDocumentFrontImageColorStatus, result.getDocumentFrontImageColorStatus().name());
add(R.string.MBDocumentBackImageColorStatus, result.getDocumentBackImageColorStatus().name());
add(R.string.MBDocumentFrontImageMoireStatus, result.getDocumentFrontImageMoireStatus().name());
add(R.string.MBDocumentBackImageMoireStatus, result.getDocumentBackImageMoireStatus().name());
add(R.string.MBDocumentFrontImageBlurred, result.getFrontImageAnalysisResult().isBlurred());
add(R.string.MBDocumentFrontImageColorStatus, result.getFrontImageAnalysisResult().getDocumentImageColorStatus().name());
add(R.string.MBDocumentFrontImageMoireStatus, result.getFrontImageAnalysisResult().getDocumentImageMoireStatus().name());

add(R.string.MBDocumentBackImageBlurred, result.getBackImageAnalysisResult().isBlurred());
add(R.string.MBDocumentBackImageColorStatus, result.getBackImageAnalysisResult().getDocumentImageColorStatus().name());
add(R.string.MBDocumentBackImageMoireStatus, result.getBackImageAnalysisResult().getDocumentImageMoireStatus().name());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected void extractData(BlinkIdRecognizer.Result result) {
add(R.string.PPIssueDate, result.getDateOfIssue());
add(R.string.PPDateOfExpiry, result.getDateOfExpiry());
add(R.string.PPDateOfExpiryPermanent, result.isDateOfExpiryPermanent());
add(R.string.PPExpired, result.isExpired());

add(R.string.PPPlaceOfBirth, result.getPlaceOfBirth());
add(R.string.PPNationality, result.getNationality());
Expand Down Expand Up @@ -61,8 +62,9 @@ protected void extractData(BlinkIdRecognizer.Result result) {
extractMRZResult(result.getMrzResult());
}

add(R.string.MBDocumentImageColorStatus, result.getDocumentImageColorStatus().name());
add(R.string.MBDocumentImageMoireStatus, result.getDocumentImageMoireStatus().name());
add(R.string.MBDocumentImageBlurred, result.getImageAnalysisResult().isBlurred());
add(R.string.MBDocumentImageColorStatus, result.getImageAnalysisResult().getDocumentImageColorStatus().name());
add(R.string.MBDocumentImageMoireStatus, result.getImageAnalysisResult().getDocumentImageMoireStatus().name());

}

Expand Down
Loading

0 comments on commit e3b33ca

Please sign in to comment.