Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android-vision OCR; Android-vision

Have gone 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 can you automatically identify and pick numbers of a credit card without struggling to tap on it. The current receiveDetection method is

@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 to a method to automatically recognize a valid credit card number(could be anything like a receipt number, bill-order number) as it scans and switch to another intent with the value in-order to perform other activities with it.

like image 913
Job M Avatar asked Oct 18 '22 09:10

Job M


1 Answers

You can use a regex and use it to match every text line it detects. if there is a match to your Credit card number regex, do whatever you wish further. No touch is 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 following 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);
        }
    }
like image 152
abhi rathi Avatar answered Oct 21 '22 05:10

abhi rathi