首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android-vision OCR;Android-vision

Android-vision OCR;Android-vision
EN

Stack Overflow用户
提问于 2017-07-02 22:40:40
回答 1查看 1.1K关注 0票数 5

我在github link https://codelabs.developers.google.com/codelabs/mobile-vision-ocr/index.html?index=..%2F..%2Findex#0上浏览了Android OCR vision示例。

如何在不费力点击的情况下自动识别和挑选信用卡号码。当前的receiveDetection方法是

代码语言:javascript
复制
@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();
}

我想要一种方法,以自动识别有效的信用卡号码(可以是任何像收据号码,账单订单号码),因为它扫描并切换到另一个意图的值,以便执行其他活动。

EN

回答 1

Stack Overflow用户

发布于 2017-09-20 14:57:06

您可以使用正则表达式,并使用它来匹配它检测到的每个文本行。如果有匹配的信用卡号码正则表达式,做任何你想要的进一步。不需要触摸。

您可以尝试这个正则表达式(取自this question)

代码语言:javascript
复制
^(?: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})$

在以下方法中

代码语言:javascript
复制
  @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);
        }
    }
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44871965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档