« DELL vostro 3491 の BIOS 1.11.0 | メイン | Error: The apk for your currently selected variant is not signed. »

Android

デジタル数字認識

 血圧測定できるスマートウォッチから、Bluetooth(ブルートゥース)で 計測値を取り込むのが王道?
 腕時計する習慣もなく、そもそも疑わしい測計値。せっかく家庭用の血圧計(omron HEM-737)があるので、この液晶表示をスキャンするだけなら便利かも。

 調べると Google Cloud Vision API、tess-twoライブラリ などが有名。現時点で Firebase の ML(Machine Learning) Kit が比較的 新しそう。クラウドに依存せず オフライン の スタンドアロン(オンデバイス/on-device) で動作することを確認済。
 公式のガイドが基本、前半の「画像内のテキストを認識する(Recognize Text in Images )」で留めるのがポイント。
https://firebase.google.com/docs/ml-kit/android/recognize-text
 ちなみに「ドキュメントの画像でテキストを認識する(Recognize text in images of documents)」を実装すると、実行時に停止し「Cloud Vision API」を有効にすることが促され、さらに Firebase 無料の spark から従量課金の Blaze プランへ誘導される。
 不完全な Kotolin 断片ソース か 切り分けしにくい大きなデモが多かったので、必要最小構成の実装例。
https://github.com/remixgrjp/OCR1
 Andorid Studio 4.0 の Basic Activity から、Firebase の設定を追加し オンデバイスで画像からテキストを認識する必要最小構成。
 Firebase へのプロジェクト追加のくだりは、多くのサイトで紹介されているとおり。
https://console.firebase.google.com/
 プロジェクトを作成
 ▼
 任意のプロジェクト名を入力
 ▼
 Googleアナリティクスはここでは無効
 ▼

 ▼
 アンドロイド アプリを追加
 ▼
 Android Studio で生成したソース先頭の package名を入力
 ▼
 "google-services.json"を プロジェクト名/app フォルダへダウンロード
 ▼
 プロジェクト名/build.gradle
と、
 プロジェクト名/app/build.gradle
へ追加修正
 ▼

 この時点で、gradle エラー。
In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[19.1.0]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.

Dependency failing: com.google.android.gms:play-services-vision-image-label:18.0.4 -> com.google.android.gms:play-services-vision-common@[19.1.0], but play-services-vision-common version was 19.1.2.

The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the artifact with the issue.
-- Project 'app' depends onto com.google.firebase:firebase-ml-vision@{strictly 24.1.0}
-- Project 'app' depends onto com.google.android.gms:play-services-vision-common@{strictly 19.1.2}
-- Project 'app' depends onto com.google.android.gms:play-services-vision@20.1.2
-- Project 'app' depends onto com.google.firebase:firebase-bom@26.0.0
-- Project 'app' depends onto com.google.firebase:firebase-ml-vision@24.1.0
-- Project 'app' depends onto com.google.android.gms:play-services-vision-image-label@{strictly 18.0.4}
-- Project 'app' depends onto com.google.firebase:firebase-bom@{strictly 26.0.0}
-- Project 'app' depends onto com.google.android.gms:play-services-vision@{strictly 20.1.2}

For extended debugging info execute Gradle from the command line with ./gradlew --info :app:assembleDebug to see the dependency paths to the artifact. This error message came from the google-services Gradle plugin, report issues at https://github.com/google/play-services-plugins and disable by adding "googleServices { disableVersionCheck = true }" to your build.gradle file.
app/build.gradle を追加修正。
implementation 'com.google.firebase:firebase-ml-vision:24.1.0'
だけでは不足のようで
implementation 'com.google.android.gms:play-services-vision:20.1.2'
implementation 'com.google.android.gms:play-services-vision-image-label:18.1.0'
を追加することで解消。
 実行するとログへ認識結果を出力。実機は HTC HTL23 (Android 5.0.2)、Samsung Galaxy S7 edge (Andorid 7.0)、ASUS_X01AD(Android 9)、Pixel4 (Andorid 11)
2020-10-03 01:19:18.100 10324-10324/asia.remix.ocr1 D/MainActivity: ●onSuccess()145
    98
正しく認識!

トラックバック

このエントリーのトラックバックURL:
https://www.remix.asia/cgi/mt/mt-tb.cgi/7706

コメントを投稿

(いままで、ここでコメントしたことがないときは、コメントを表示する前にこのブログのオーナーの承認が必要になることがあります。承認されるまではコメントは表示されません。そのときはしばらく待ってください。)