Google Vision API Text Recognizer is not working

穿精又带淫゛_ 提交于 2021-01-27 16:31:22

问题


I have used Google vision API to read text from any object like newspaper or text in wall. I have tried same sample from Google developer website but my Text Recognizer always return false on IsOperational function. am tested on Blackberry keyone and also tested on Moto x play its working fine.

Gradle file : compile 'com.google.android.gms:play-services-vision:11.0.4'

Can anyone help me on this. Thanks in Advance

TextRecognizer textRecognizer = new TextRecognizer.Builder(context).build();
textRecognizer.setProcessor(new OcrDetectorProcessor(mGraphicOverlay, OcrCaptureActivity.this));
if(!textRecognizer.isOperational()) { 
  Log.e("TextRecog","Not Operational"); IntentFilter lowstorageFilter = new 
  IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;
}

回答1:


The isOperational method from [TextRecognizer] (https://developers.google.com/android/reference/com/google/android/gms/vision/text/TextRecognizer) is inherited from Detector class. The method doesn't immediately returns true after setting up.

From the docs

"Indicates whether the detector has all of the required dependencies available locally in order to do detection.

When an app is first installed, it may be necessary to download required files. If this returns false, those files are not yet available. Usually this download is taken care of at application install time, but this is not guaranteed. In some cases the download may have been delayed."

Basically, if it's returning false, code it to wait and retry. I assume you are running tests on a phone, you will need to give it some time to download all the required libraries before that method will return true.




回答2:


add the vision api's metadata on your App manifest

 <meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
<meta-data
    android:name="com.google.android.gms.vision.DEPENDENCIES"
    android:value="ocr"/>



回答3:


you have to add this to your AndroidManifest.xml

    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    >


    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.gms.vision.DEPENDENCIES"
        android:value="ocr"/>


来源:https://stackoverflow.com/questions/47570243/google-vision-api-text-recognizer-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!