Dhaval Gulhane
Dhaval Gulhane

Reputation: 157

Not able to read text from image using Mobile Vision API

I'm developing a mobile application, where I'm trying to extract meter reading from an image captured by the camera.

I have done research and by trial and error, finally decided to use Google's Mobile Vision API instead of tesseract-ocr or OpenCV

So I have developed a small app using Text Recognition API provided under Mobile Vision API. Here is code.

  if (detector.isOperational() && bitmap != null) {
                imageView.setImageBitmap((Bitmap) data.getExtras().get("data"));
                Frame frame = new Frame.Builder().setBitmap(bitmap).build();
                SparseArray<TextBlock> textBlocks = detector.detect(frame);
                String blocks = "";
                String lines = "";
                String words = "";
                for (int index = 0; index < textBlocks.size(); index++) {
                    //extract scanned text blocks here
                    TextBlock tBlock = textBlocks.valueAt(index);
                    blocks = blocks + tBlock.getValue() + "\n" + "\n";
                    for (Text line : tBlock.getComponents()) {
                        //extract scanned text lines here
                        lines = lines + line.getValue() + "\n";
                        for (Text element : line.getComponents()) {
                            //extract scanned integer here
                            if(element.getValue().matches("\\d+")){
                                words = words + element.getValue();
                            }
                        }
                    }
                }
                if (textBlocks.size() == 0) {
                    scanResults.setText("Scan Failed: Found nothing to scan");
                } else {
                    scanResults.setText(scanResults.getText() + "Blocks: " + "\n");
                    scanResults.setText(scanResults.getText() + blocks + "\n");
                    scanResults.setText(scanResults.getText() + "---------" + "\n");
                    scanResults.setText(scanResults.getText() + "Lines: " + "\n");
                    scanResults.setText(scanResults.getText() + lines + "\n");
                    scanResults.setText(scanResults.getText() + "---------" + "\n");
                    scanResults.setText(scanResults.getText() + "Words: " + "\n");
                    scanResults.setText(scanResults.getText() + words + "\n");
                    scanResults.setText(scanResults.getText() + "---------" + "\n");
                }
            } else {
                scanResults.setText("Could not set up the detector!");
            }

Everything works fine but it is not able to read digits from marked area from below image.

Not able to read data area in red rectangle

I have tried to pass gray scale image to the detector but it didn't work.

Please suggest how can I make text readable.

Upvotes: 3

Views: 1192

Answers (1)

nassim youssef
nassim youssef

Reputation: 1

What you can do is first extracting the line that have numbers in it and you need to remove any characters that isn't a number or alphabet and build your string, than you need to check for every character in this string to see if it contains an alphabet before it or after it if there is an alphabet than the character your analyzing isn't valid otherwise it's valid. It worked for me but still lacking detection stability.

I hope this answers your problem

Upvotes: 0

Related Questions