How to extract text from image Android app

前端 未结 4 1859
眼角桃花
眼角桃花 2021-02-01 22:52

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

4条回答
  •  遇见更好的自我
    2021-02-01 23:34

    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 textBlocks = textRecognizer.detect(imageFrame);
    
    for (int i = 0; i < textBlocks.size(); i++) {
        TextBlock textBlock = textBlocks.get(textBlocks.keyAt(i));
        imageText = textBlock.getValue();                   // return string
    }
    

提交回复
热议问题