我在github link https://codelabs.developers.google.com/codelabs/mobile-vision-ocr/index.html?index=..%2F..%2Findex#0上浏览了Android OCR vision示例。
如何在不费力点击的情况下自动识别和挑选信用卡号码。当前的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();
}我想要一种方法,以自动识别有效的信用卡号码(可以是任何像收据号码,账单订单号码),因为它扫描并切换到另一个意图的值,以便执行其他活动。
发布于 2017-09-20 14:57:06
您可以使用正则表达式,并使用它来匹配它检测到的每个文本行。如果有匹配的信用卡号码正则表达式,做任何你想要的进一步。不需要触摸。
您可以尝试这个正则表达式(取自this question)
^(?: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);
}
}https://stackoverflow.com/questions/44871965
复制相似问题