Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract text from image Android app

I am working on a feature for my Android app. I would like to read text from a picture then save that text in a database. Is using OCR the best way? Is there another way? Google suggests in its documentation that NDK should only be used if strictly necessary but what are the downfalls exactly?

Any help would be great.

Image to be OCR'd

enter image description here

enter image description here

enter image description here

like image 474
MrAnderson1992 Avatar asked May 17 '16 23:05

MrAnderson1992


People also ask

What app can i use to extract text from a picture?

Google Keep. The excellent note-taking app from Google packs in some neat tricks and has a lot of creative uses. It also has built-in support for OCR. In our testing, we found that Google Keep's text extraction worked pretty consistently across both simple and complex text formatting.

Can you extract text from an image?

You can capture text from a scanned image, upload your image file from your computer, or take a screenshot on your desktop. Then simply right click on the image, and select Grab Text. The text from your scanned PDF can then be copied and pasted into other programs and applications. How can I copy text from an image?

How can I convert image to text in mobile?

Google Goggles converts an image of text to actual text that you can copy, paste and manipulate in any other way. It can translate the resulting text into many different languages. It can recognize business cards and add them to your Android device as contacts.


3 Answers

you can use google vision library for convert image to text, it will give better output from image. Add below library in build gradle:

   compile 'com.google.android.gms:play-services-vision:10.0.0+'

    TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();

Frame imageFrame = new Frame.Builder()

        .setBitmap(bitmap)                 // your image bitmap
        .build();

String imageText = "";


SparseArray<TextBlock> textBlocks = textRecognizer.detect(imageFrame);

for (int i = 0; i < textBlocks.size(); i++) {
    TextBlock textBlock = textBlocks.get(textBlocks.keyAt(i));
    imageText = textBlock.getValue();                   // return string
}
like image 59
user7176550 Avatar answered Oct 17 '22 12:10

user7176550


From my Simple example of OCRReader in Android tutorial you can read text from image and also you can scan for text using camera, using very simple code.

This library is developed using Mobile Vision Text API

For scan text from camera

OCRCapture.Builder(this)
        .setUseFlash(true)
        .setAutoFocus(true)
        .buildWithRequestCode(CAMERA_SCAN_TEXT);

For extract text from image

String text = OCRCapture.Builder(this).getTextFromUri(pickedImage);
//You can also use getTextFromBitmap(Bitmap bitmap) or getTextFromImage(String imagePath) buplic APIs from OCRLibrary library.
like image 41
Gunaseelan Avatar answered Oct 17 '22 11:10

Gunaseelan


Text from an image can be extracted using Firebase machine learning (ML) kit. There are two versions of the text recognition API, on-device API (free) and on-cloud API.

To use the API, first create BitMap of the image, which should be upright. Then create FirebaseVisionImage object passing the bitmap object.

FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);

Then create FirebaseVisionTextRecognizer object.

FirebaseVisionTextRecognizer textRecognizer = FirebaseVision.getInstance()
        .getCloudTextRecognizer();

Then pass the FirebaseVisionImage object to processImage() method, add listeners to the resulting task and capture the extracted text in success callback method.

textRecognizer.processImage(image)
                .addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
                    @Override
                    public void onSuccess(FirebaseVisionText firebaseVisionText) {
                       //process success
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                     @Override
                     public void onFailure(@NonNull Exception e) {
                       //process failure
                     }
                 });

For complete example which shows how to use Firebase ML text recognizer, see https://www.zoftino.com/extracting-text-from-images-android

like image 1
Arnav Rao Avatar answered Oct 17 '22 11:10

Arnav Rao