OCR for Android; Android vision

After going through the Android OCR vision sample on github link https://codelabs.developers.google.com/codelabs/mobile-vision-ocr/index.html?index=..%2F..%2Findex#0

How you can automatically identify and select credit card numbers without trying to use it. Current getDetection Method

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

I want the method to automatically recognize a valid credit card number (maybe anything, for example, receipt number, order account number) when it scans and switches to another intent with a value in order to perform other actions with it,

+5
source share
1 answer

You can use a regular expression and use it to match every text line that it detects. if there is a match with your regular expression credit card number, do whatever you want. No touch required.

You can try this regex (taken from 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})$ 

in the next method

  @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); } } 
+2
source

Source: https://habr.com/ru/post/1269412/


All Articles