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.
I have tried to pass gray scale image to the detector but it didn't work.
Please suggest how can I make text readable.