3

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;
}
Ying Li
  • 2,500
  • 2
  • 13
  • 37
venkatesh kumar
  • 167
  • 2
  • 10
  • Show us your code – Kuls Nov 30 '17 at 09:44
  • All the occurrences of your "Am" should be "I" for correct English. – Matthias Nov 30 '17 at 09:45
  • 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; } – venkatesh kumar Nov 30 '17 at 09:49
  • @Matthias thank you so much for ur comments. I will correct it. – venkatesh kumar Nov 30 '17 at 09:51

3 Answers3

1

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"/>
0

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.

Ying Li
  • 2,500
  • 2
  • 13
  • 37
-1

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"/>