1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

光学式文字認識 - Computer Vision

Posted at

はじめに

ComputerVisionAPIの日本語対応がGAしていたので簡単ではありますが、試してみました。

ComputerVisionAPIのデプロイ

AzureのコンソールでComputerVisionを選択しデプロイしていきます

image.png

デプロイ出来たらサブスクリプションキーとエンドポイントをコピーしておきます

image.png

プログラム

プログラム2パターンこちらに置いてあります

  • リモートのURLを指定してOCRするサンプル
  • ローカルの画像を読み込んでOCRするサンプル

動かし方は簡単で、まずは環境変数を2つ設定します

SUBSCRIPTION_KEY=先ほどコピーしたサブスクリプションキー
ENDPOINT=先ほどコピーしたComputerVisionのエンドポイント

gradleでbuildします

gradle build

実行しましょう

gradle run

Azureのサンプルで提供されてるこちらの画像を解析してみました

こんな結果になるはずです。思ったより拾える・・・。

Nutrition Facts Amount Per Serving
Serving size: 1 bar (40g)
Serving Per Package: 4
Total Fat 13g
Saturated Fat 1.5g
Amount Per Serving
Trans Fat 0g
alories 190
Cholesterol Omg
ories from Fat 110
Sodium 20mg
nt Daily Values are based on
Vitamin A 50%
calorie diet

日本語が混じった手書きの文章を解析

今度はこんな画像を解析してみます
image.png

「Vision」「ドキュメント」ってあたりがあやしかったりしますがどうでしょうか

結果はこんな感じ なんか一つ掛け違えるとだだだだ・・・と間違えますね

Computer Vision a l"+2xof
テキスト行
画像
A B C DE

Confidenceもあわせて出してみました

  • 1に近づくほど自信満々ってことです。
  • 「の」の部分はaと間違えてますがわりと自信満々のようです。自分の字に自信がなくなります。
  • 「ドキュメント」っていう部分は0.081なので相当自身がなかったようですね。

Confidenceを使うことでうまくフィルタできそうですね。

Computer	Confidence[0.985] BoundingBox[580.0, 647.0, 1343.0, 671.0, 1339.0, 877.0, 577.0, 873.0]
Vision	Confidence[0.98] BoundingBox[1511.0, 675.0, 2083.0, 685.0, 2077.0, 885.0, 1506.0, 879.0]
a	Confidence[0.963] BoundingBox[2141.0, 686.0, 2264.0, 687.0, 2258.0, 888.0, 2135.0, 886.0]
l"+2xof	Confidence[0.081] BoundingBox[2305.0, 687.0, 3179.0, 690.0, 3170.0, 900.0, 2299.0, 888.0]
テ	Confidence[0.995] BoundingBox[1215.0, 1257.0, 1328.0, 1265.0, 1316.0, 1445.0, 1201.0, 1442.0]
キ	Confidence[0.996] BoundingBox[1373.0, 1268.0, 1496.0, 1276.0, 1485.0, 1450.0, 1361.0, 1446.0]
ス	Confidence[0.996] BoundingBox[1541.0, 1277.0, 1688.0, 1281.0, 1679.0, 1454.0, 1531.0, 1451.0]
ト	Confidence[0.996] BoundingBox[1757.0, 1283.0, 1880.0, 1282.0, 1873.0, 1459.0, 1749.0, 1456.0]
行	Confidence[0.995] BoundingBox[2021.0, 1280.0, 2144.0, 1274.0, 2140.0, 1464.0, 2016.0, 1462.0]
画	Confidence[0.932] BoundingBox[1237.0, 1844.0, 1409.0, 1837.0, 1411.0, 2068.0, 1239.0, 2071.0]
像	Confidence[0.995] BoundingBox[1555.0, 1830.0, 1739.0, 1829.0, 1741.0, 2058.0, 1558.0, 2062.0]
A	Confidence[0.999] BoundingBox[1327.0, 2483.0, 1473.0, 2480.0, 1473.0, 2691.0, 1328.0, 2688.0]
B	Confidence[0.999] BoundingBox[1717.0, 2476.0, 1863.0, 2475.0, 1859.0, 2698.0, 1714.0, 2696.0]
C	Confidence[0.999] BoundingBox[2167.0, 2472.0, 2314.0, 2471.0, 2304.0, 2707.0, 2159.0, 2704.0]
DE	Confidence[0.694] BoundingBox[2497.0, 2471.0, 2974.0, 2472.0, 2956.0, 2716.0, 2485.0, 2711.0]

BoundingBoxは6つの数字がありますが、バージョン3.1までは4つだったのですが、バージョン3.2になって8つになり、その説明がドキュメント上になかったのでどう読めばよいのかわかりませんでした。無念。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?