Skip to content

Commit

Permalink
Merge pull request #17 from blinkinput/release/v3.4.0
Browse files Browse the repository at this point in the history
Release/v3.4.0
  • Loading branch information
i1E authored Sep 22, 2017
2 parents 3a389d7 + a3fb7ba commit 4aeeec3
Show file tree
Hide file tree
Showing 126 changed files with 10,534 additions and 1,684 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
import com.microblink.recognition.InvalidLicenceKeyException;
import com.microblink.recognizers.BaseRecognitionResult;
import com.microblink.recognizers.RecognitionResults;
import com.microblink.recognizers.blinkocr.BlinkOCRRecognitionResult;
import com.microblink.recognizers.blinkocr.BlinkOCRRecognizerSettings;
import com.microblink.recognizers.blinkinput.BlinkInputRecognitionResult;
import com.microblink.recognizers.blinkinput.BlinkInputRecognizerSettings;
import com.microblink.recognizers.blinkocr.parser.generic.RawParserSettings;
import com.microblink.recognizers.settings.RecognitionSettings;
import com.microblink.recognizers.settings.RecognizerSettings;
import com.microblink.results.ocr.CharWithVariants;
import com.microblink.results.ocr.OcrChar;
import com.microblink.results.ocr.OcrResult;
import com.microblink.util.CameraPermissionManager;
Expand All @@ -46,7 +47,7 @@ public class CombinationScanActivity extends Activity implements CameraEventsLis

// obtain your licence key at http://microblink.com/login or
// contact us at http://help.microblink.com
private static final String LICENSE_KEY = "OEWESRMK-OENGL3VK-IVWYB4DY-OTNT457T-5PGLUYNA-IVQ2ARLB-UBCWCAAC-IYXKU56C";
private static final String LICENSE_KEY = "GZLX6RM4-KUOPKVFO-F27ZHP23-GKFVGELE-GXCYIOHW-DNT6JOYT-RNJRDRDR-CTHZ4N3O";

/** RecognizerView is the built-in view that controls camera and recognition */
private RecognizerView mRecognizerView;
Expand Down Expand Up @@ -119,8 +120,8 @@ protected void onCreate(Bundle savedInstanceState) {
finish();
}

// create BlinkOCR recognizer settings object and add parser to it
BlinkOCRRecognizerSettings ocrSett = new BlinkOCRRecognizerSettings();
// create BlinkInput recognizer settings object and add parser to it
BlinkInputRecognizerSettings ocrSett = new BlinkInputRecognizerSettings();
RawParserSettings rawSett = new RawParserSettings();

// add raw parser with name "Raw" to default parser group
Expand All @@ -130,7 +131,7 @@ protected void onCreate(Bundle savedInstanceState) {
// prepare recognition settings
RecognitionSettings recognitionSettings = new RecognitionSettings();
// set recognizer settings array that is used to configure recognition
// BlinkOCRRecognizer will be used in the recognition process
// BlinkInputRecognizer will be used in the recognition process
recognitionSettings.setRecognizerSettingsArray(new RecognizerSettings[]{ocrSett});
mRecognizerView.setRecognitionSettings(recognitionSettings);

Expand Down Expand Up @@ -355,8 +356,8 @@ public void onScanningDone(RecognitionResults results) {
BaseRecognitionResult[] dataArray = results.getRecognitionResults();
// we have enabled only one recognizer, so we expect only one element in dataArray
if (dataArray != null && dataArray.length == 1) {
if (dataArray[0] instanceof BlinkOCRRecognitionResult) {
BlinkOCRRecognitionResult result = (BlinkOCRRecognitionResult) dataArray[0];
if (dataArray[0] instanceof BlinkInputRecognitionResult) {
BlinkInputRecognitionResult result = (BlinkInputRecognitionResult) dataArray[0];

String scanned = result.getParsedResult("Raw");

Expand All @@ -372,13 +373,13 @@ public void onScanningDone(RecognitionResults results) {
mOcrResult.setText("Horizontal text: " + iteratorToString(iter));

if(mLastScannedImage != null) {
OcrChar ch = iter.getCurrentChar();
CharWithVariants ch = iter.getCurrentCharWithVariants();

// now determine position of image where vertical text is expected
// let's say it is the whole vertical strip of image ending with
// first letter of string "Carat Weight"

float charX = ch.getPosition().getX();
float charX = ch.getChar().getPosition().getX();

// determine region that will be scanned for vertical text as vertical
// strip left of string "Carat Weight"
Expand All @@ -401,8 +402,8 @@ public void onScanningDone(RecognitionResults results) {
public void onScanningDone(RecognitionResults results) {
BaseRecognitionResult[] baseRecognitionResults = results.getRecognitionResults();
if (baseRecognitionResults != null && baseRecognitionResults.length == 1) {
if (baseRecognitionResults[0] instanceof BlinkOCRRecognitionResult) {
BlinkOCRRecognitionResult result = (BlinkOCRRecognitionResult) baseRecognitionResults[0];
if (baseRecognitionResults[0] instanceof BlinkInputRecognitionResult) {
BlinkInputRecognitionResult result = (BlinkInputRecognitionResult) baseRecognitionResults[0];
final String verticalText = result.getParsedResult("Raw");
runOnUiThread(new Runnable() {
@Override
Expand Down Expand Up @@ -433,7 +434,7 @@ private String iteratorToString(OcrResultIterator i) {
StringBuilder sb = new StringBuilder();
OcrResultIterator iter = new OcrResultIterator(i);
while(iter.hasNext()) {
sb.append(iter.getCurrentChar().getValue());
sb.append(iter.getCurrentCharWithVariants().getChar().getValue());
boolean newLine = iter.moveToNext();
if(newLine) {
sb.append('\n');
Expand All @@ -460,20 +461,20 @@ private OcrResultIterator findString(String str, OcrResult result) {
private boolean stringMatch(String str, OcrResultIterator iter) {
OcrResultIterator iterCopy = new OcrResultIterator(iter);
for (int pos = 0; pos < str.length(); ++pos) {
if(!charMatch(str.charAt(pos), iterCopy.getCurrentChar())) return false;
if(!charMatch(str.charAt(pos), iterCopy.getCurrentCharWithVariants())) return false;
if(pos != str.length() - 1 && !iterCopy.hasNext()) return false;
iterCopy.moveToNext();
}
return true;
}

/**
* Returns true if char matches given OcrChar or any of its recognition alternatives
* Returns true if char matches given char or any of its recognition alternatives
*/
private boolean charMatch(char c, OcrChar ocrC) {
if(c == ocrC.getValue()) return true;
private boolean charMatch(char c, CharWithVariants ocrCharWithVariants) {
if(c == ocrCharWithVariants.getChar().getValue()) return true;
// check alternatives
OcrChar[] variants = ocrC.getRecognitionVariants();
OcrChar[] variants = ocrCharWithVariants.getRecognitionVariants();
if (variants != null) { // some chars do not have alternatives
for (OcrChar var : variants) {
if (c == var.getValue()) return true;
Expand Down Expand Up @@ -513,7 +514,7 @@ public OcrResultIterator(OcrResultIterator other) {
mLine = other.mLine;
}

public OcrChar getCurrentChar() {
public CharWithVariants getCurrentCharWithVariants() {
return mOcrResult.getBlocks()[mBlock].getLines()[mLine].getChars()[mChar];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MenuActivity extends Activity {

// obtain your licence key at http://microblink.com/login or
// contact us at http://help.microblink.com
static final String LICENSE_KEY = "OEWESRMK-OENGL3VK-IVWYB4DY-OTNT457T-5PGLUYNA-IVQ2ARLB-UBCWCAAC-IYXKU56C";
static final String LICENSE_KEY = "GZLX6RM4-KUOPKVFO-F27ZHP23-GKFVGELE-GXCYIOHW-DNT6JOYT-RNJRDRDR-CTHZ4N3O";

/** List view elements. */
private ListElement[] mElements;
Expand Down Expand Up @@ -122,7 +122,7 @@ private ListElement buildMRTDDetectorElement() {
// Decoding info is used to define the position in the detected location that is
// interesting (it is expressed as rectangle relative to detected rectangle)
// and the height of the dewarped image obtained from that position.
DecodingInfo di = new DecodingInfo(new Rectangle(0.f, 0.f, 1.f, 1.f), 100, "MRZ");
DecodingInfo di = new DecodingInfo(new Rectangle(0.f, 0.f, 1.f, 1.f), 500, "MRTD");

// Prepare machine readable travel document detector settings with defined
// decoding info.
Expand Down
Loading

0 comments on commit 4aeeec3

Please sign in to comment.