21

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

Boken
  • 4,825
  • 10
  • 32
  • 42
MrAnderson1992
  • 399
  • 1
  • 3
  • 11
  • I am also looking for solution something like this and while reading, I landed on SO here. I would like to ask you did you find any feasible solution for this. After reading two answers down I am bit confused. Which one did you follow and what were their accuracy. Mind to share your case studies ? Thank you. – Lokesh Pandey Apr 19 '17 at 04:57

4 Answers4

27

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
}
user7176550
  • 1,501
  • 14
  • 19
4

From this 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.
Gunaseelan
  • 14,415
  • 11
  • 80
  • 128
1

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

Arnav Rao
  • 6,692
  • 2
  • 34
  • 31
0

There is a different option. You can upload your image to the server, OCR it from the server, then get the result.

Nadia Solovyeva
  • 207
  • 1
  • 7
  • Thank you for the reply, how reliable would this be? Are there any real-world applications out there that use this method? – MrAnderson1992 May 22 '16 at 15:40
  • Again thank you for your reply. Is there a possibility you could add some details in there? How accurate can it be?, What real world applications use it? I tested an industry standard OCR and it did not provide anything more than 40% accuracy. (For my needed use) – MrAnderson1992 May 25 '16 at 11:12
  • accuracy depends on your input quality, please share image sample, the question cannot be answered without the image samples. – Nadia Solovyeva May 25 '16 at 11:31
  • I understand this and that is why the accuracy level is so low. The images will never me the same and the quality of them will change dramatically from size, text, colours, quality etc. – MrAnderson1992 May 25 '16 at 11:57
  • OK. There are real-word applications which do that client-server way, but I'm not sure if I'm allowed to tell the app names (probably not). The attched image gets only 1 OCR error (% replaced by *), I don't see any problems here. – Nadia Solovyeva May 25 '16 at 12:04
  • Thanks again, please check the latest images I added. My main thought it I cannot control how well the images are taken by the user so in that case I cannot control the results. It is essential that the results are 100% accurate. – MrAnderson1992 May 25 '16 at 12:09
  • This this input quality and modern day OCR technologies, the only way to have 100% correct OCR results is a human verificator. Though this won't help for the image 2 (no one can read that), and probably will not help for image 3 (it is readable, but human verificator does make mistakes when forced to do lots of work, and for this input quality mistake is inavoidable). Checking receipt summa against "Total" field will help to indicate the error. Capturing recepies with one's mobile phone is an obvious usage scenario, and it even works for 8+ megapixels phone cameras. – Nadia Solovyeva May 26 '16 at 03:15
  • @НадеждаТарашкевич How can I OCR an image in server ? Is there any server side application that does that or we need to build our own ? If there is any application mind to share the names or link ? – Lokesh Pandey Apr 19 '17 at 05:06