2

I am trying to scan an image taken from resources using a Recognizer with a RegerParserSettings inside a fragment. The problem is that BaseRecognitionResult obtained through the callback onScanningDone is always null. I have tried to set up the RecognitionSettings with MRTDRecognizer and worked fine, so I think that the library is properly integrated. This is the source code that I am using:

@Override
public void onAttach(Context context) {
    ...

    try {
        mRecognizer = Recognizer.getSingletonInstance();
        mRecognizer.setLicenseKey(context, LICENSE_KEY);
    } catch (FeatureNotSupportedException | InvalidLicenceKeyException e) {
        Log.d(TAG, e.getMessage());
    }
    buildRecognitionSettings();
    mRecognizer.initialize(context, mRecognitionSettings, new DirectApiErrorListener() {
        @Override
        public void onRecognizerError(Throwable t) {
            //Handle exception

        }
    });
}

private void buildRecognitionSettings() {
        mRecognitionSettings = new RecognitionSettings();
        mRecognitionSettings.setRecognizerSettingsArray(setupSettingsArray());
}

private RecognizerSettings[] setupSettingsArray() {
        RegexParserSettings regexParserSettings = new RegexParserSettings("[A-Z0-9]{17}");
        BlinkOCRRecognizerSettings sett = new BlinkOCRRecognizerSettings();
        sett.addParser("myRegexParser", regexParserSettings);
        return new RecognizerSettings[] { sett };
}

I scan the image like:

mRecognizer.recognizeBitmap(bitmap, Orientation.ORIENTATION_PORTRAIT, FragMicoblink.this);

And this is the callback handled in the fragment

@Override
public void onScanningDone(RecognitionResults results) {
    BaseRecognitionResult[] dataArray = results.getRecognitionResults();

    //dataArray is null

    for(BaseRecognitionResult baseResult : dataArray) {
        if (baseResult instanceof BlinkOCRRecognitionResult) {
            BlinkOCRRecognitionResult result = (BlinkOCRRecognitionResult) baseResult;
            if (result.isValid() && !result.isEmpty()) {
                String parsedAmount = result.getParsedResult("myRegexParser");
                if (parsedAmount != null && !parsedAmount.isEmpty()) {
                    Log.d(TAG, "Result: " + parsedAmount);
                }
            }
        }
    }
}`

Thanks in advance!

Cerovec
  • 1,273
  • 10
  • 19
Spirrow
  • 1,120
  • 6
  • 18

1 Answers1

2

Helllo Spirrow.

The difference between your code and SegmentScanActivity is that your code uses DirectAPI, which can process only single bitmap image you send for processing, while SegmentScanActivity processes camera frames as they arrive from the camera. While doing so, it can utilize time redundant information to improve the OCR quality, i.e. it combines consecutive OCR results from multiple video frames to obtain a better quality OCR result.

This feature is not available via DirectAPI - you need to use either SegmentScanActivity, or custom scan activity with our camera management.

You can also find out more here: https://github.com/BlinkID/blinkid-android/issues/54

Regards

Rohit Poudel
  • 1,793
  • 2
  • 20
  • 24
culoi
  • 41
  • 1
  • 4