Using Google's Mobile Vision to recognize Text in a static image?

I'm trying to write a basic ocr android app using Google's Mobile Vision API, but I'm having difficulty actually getting the app to recognize text in a static image. I've looked through the codelabs tutorial, other people's questions, namely every single stackoverflow question with the android-vision tag, and the documentation, but I still haven't had any luck. I know someone else asked a similar question but the answer posted there doesn't work.

Here's an excerpt of my code

Bitmap photo = (Bitmap) extras.get("data");
        pictureOcrView.setImageBitmap(photo);
        Context context = getApplicationContext();
        TextRecognizer ocrFrame = new TextRecognizer.Builder(context).build();
        Frame frame = new Frame.Builder().setBitmap(photo).build();
        if (ocrFrame.isOperational()){
            Log.e(TAG, "Textrecognizer is operational");
        }
        SparseArray<TextBlock> textBlocks = ocrFrame.detect(frame);

        for (int i = 0; i < textBlocks.size(); i++) {
            TextBlock textBlock = textBlocks.get(textBlocks.keyAt(i));

            Log.e(TAG, "something is happening");
            }

I don't understand what the issue is. It's not like I'm getting garbled text, I'm just not receiving any text at all. When I test this application with a picture of text that functioned for the codelab tutorial I get nothing. It seems like the textBlock array isn't even being created, but I don't know why. I know I've created the frame because I can still run other frame methods like getHeight successfully, and the isOperational() has been returning true.

Any suggestions on what I'm doing wrong?


I have just had the same issue. The problem is that the image that you are processing is not the whole photo just a thumbnail (got by calling extras.get("data")). In order to access the full image you need to save it and then use it. Details on how to do that can be found at the below link: https://developer.android.com/training/camera/photobasics.html


In my case. When I get bitmap from camera or gallery,that bitmap orientation has been rotated. TextRecognizer can't detect text because bitmap is rotated. You must rotate bitmap to correct orientation.

You can rotate image by doing with this comment

链接地址: http://www.djcxy.com/p/36886.html

上一篇: 所有数据都没有使用Entity Framework Core插入到MySql实例中

下一篇: 使用Google的移动视觉识别静态图像中的文字?