Microblink识别器设置RegexParserSettings

时间:2017-08-29 07:31:32

标签: android fragment ocr

我正在尝试使用Recognizer在片段内部RegerParserSettings扫描从资源中获取的图像。 问题是通过回调BaseRecognitionResult获得的onScanningDone始终为空。我尝试使用MRTDRecognizer设置RecognitionSettings并且工作正常,所以我认为该库已正确集成。这是我正在使用的源代码:

@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 };
}

我扫描图像如:

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

这是片段

中处理的回调
@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);
                }
            }
        }
    }
}`

提前致谢!

1 个答案:

答案 0 :(得分:1)

Helllo Spirrow。

您的代码与SegmentScanActivity之间的区别在于您的代码使用DirectAPI,它只能处理您发送进行处理的单个位图图像,而SegmentScanActivity会处理相机帧相机。在这样做的同时,它可以利用时间冗余信息来提高OCR质量,即它结合了多个视频帧的连续OCR结果,以获得更高质量的OCR结果。

DirectAPI无法使用此功能 - 您需要使用我们的camera management SegmentScanActivity或自定义扫描活动。

您还可以在此处了解更多信息: https://github.com/BlinkID/blinkid-android/issues/54

此致