Search for a specific pattern in text using Android Mobile Vision API

I made a working implementation of an app that uses the Android mobile view API to read text. But is there a way in which I can search for a specific sample of text, like searching where there are 10 digits in a string or something. Is it possible to implement it.

All help would be appreciated.

+3


source to share


1 answer


The mobile appi android has a method called receiveDetections inside the OcrDetectorProcessor class.

This method gets all the characters detected by the camera, and by default this is a display of every character it detects on the screen.

@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);
            OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item);
            mGraphicOverlay.add(graphic);
        }
    }

      



You can edit this method to filter the detected characters and display only what you want to display to the user. So if you say that, according to your question, you want to display any string with 10 characters, you can do so by editing the method like this:

@Override
    public void receiveDetections(Detector.Detections<TextBlock> detections) {
        if(stopScan){
            SparseArray<TextBlock> items = detections.getDetectedItems();
            for (int i = 0; i < items.size(); ++i) {
                TextBlock item = items.valueAt(i);

        //verify string here
                if (item.getValue().length() == 10) {
                    OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item);
                    mGraphicOverlay.add(graphic);
                }
            }
        }
    }

      

0


source







All Articles