【问题标题】:Google Vision API Text Recognizer is not workingGoogle Vision API 文本识别器无法正常工作
【发布时间】:2018-05-14 04:37:27
【问题描述】:

我使用 Google vision API 从任何对象(如报纸或墙上的文字)中读取文本。我从 Google 开发者网站尝试过相同的示例,但我的文本识别器总是在 IsOperational 函数上返回 false。我在 Blackberry keyone 上进行了测试,也在 Moto x 上进行了测试,运行良好。

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

谁能帮我解决这个问题。提前致谢

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;
}

【问题讨论】:

  • 向我们展示您的代码
  • 所有出现的“Am”都应该是“I”以表示正确的英语。
  • 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; }
  • @Matthias 非常感谢您的 cmets。我会改正的。

标签: android ocr google-vision vision-api


【解决方案1】:

在您的应用清单中添加视觉 api 的元数据

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

【讨论】:

    【解决方案2】:

    [TextRecognizer] (https://developers.google.com/android/reference/com/google/android/gms/vision/text/TextRecognizer) 的 isOperational 方法继承自 Detector 类。该方法在设置后不会立即返回 true。

    来自docs

    “指示检测器是否具有本地可用的所有必需依赖项以便进行检测。

    首次安装应用时,可能需要下载所需文件。如果返回 false,则这些文件尚不可用。通常在应用程序安装时会处理此下载,但这不能保证。在某些情况下,下载可能会延迟。”

    基本上,如果它返回 false,则将其编码为等待并重试。我假设您正在手机上运行测试,您需要给它一些时间来下载所有必需的库,然后该方法才会返回 true。

    【讨论】:

      【解决方案3】:

      你必须把它添加到你的 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"/>
      

      【讨论】:

        猜你喜欢
        • 2018-08-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多