OCR 安卓视觉OCR技术

4
我已经查看了在Github上的Android OCR视觉样例,链接如下:https://codelabs.developers.google.com/codelabs/mobile-vision-ocr/index.html?index=..%2F..%2Findex#0 如何自动识别并选择信用卡号码,而不是手动输入呢?目前的receiveDetection方法为:
@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
    mGraphicOverlay.clear();
    SparseArray<TextBlock> items = detections.getDetectedItems();
    for (int i = 0; i < items.size(); ++i) {
        TextBlock item = items.valueAt(i);
        if (item != null && item.getValue() != null) {
            Log.d("Processor", "Text detected! " + item.getValue());
        }
        OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item);
        mGraphicOverlay.add(graphic);
    }
}

@Override
public void release() {
    mGraphicOverlay.clear();
}

我希望能有一种方法自动识别有效的信用卡号码(可以是任何像收据号码、账单订单号等),并在扫描后切换到另一个意图,并使用该值执行其他活动。


嗨,虽然这不是解决您问题的方法。但为什么不使用https://www.card.io/呢? - Pranaysharma
我正在尝试创建一个应用程序来辅助OCR解决方案。 - Job M
1个回答

3

您可以使用正则表达式并将其用于匹配检测到的每个文本行。如果您的信用卡号码正则表达式有匹配项,则可以执行进一步操作。无需触碰。

您可以尝试使用此正则表达式(取自此问题

^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$

在以下方法中:
  @Override
    public void receiveDetections(Detector.Detections<TextBlock> detections) {
        mGraphicOverlay.clear();
        SparseArray<TextBlock> items = detections.getDetectedItems();
        for (int i = 0; i < items.size(); ++i) {
            TextBlock item = items.valueAt(i);
            if (item != null && item.getValue() != null) {
      List<Line> textComponents = (List<Line>) item.getComponents();
                                    for (Line currentText : textComponents) {
                                        String text = currentText.getValue();
                                          if (word.matches(CREDIT_CARD_PATTERN){

                                           do your stuff here...

                                       }
                                    }
                                }
            }

            OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item);
            mGraphicOverlay.add(graphic);
        }
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接