LoginSignup
0
1

More than 5 years have passed since last update.

Microsoft Computer Vision API OCR の使い方

Posted at

次のページを参考にしました。
Use OCR to detext text in an image

次のドイツ語の画像を処理してみます。
test_de.png

Ocp-Apim-Subscription-Key と url は変更して下さい。

deutsch.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
import  requests 
import  json

ocr_url = 'https://westus.api.cognitive.microsoft.com/vision/v1.0/ocr'
headers  = {'Ocp-Apim-Subscription-Key': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'}
params   = {'language': 'de', 'detectOrientation ': 'true'}
data     = {'url': 'https://example.com/test_de.png'}
response = requests.post(ocr_url, headers=headers, params=params, json=data)
response.raise_for_status()

analysis = response.json()

print(analysis)

実行方法
bash
./deutsh.py > tmp01.json
sed "s/'/\"/g" < tmp01.json > tmp02.json
jq . tmp02.json | grep text

実行結果

  "textAngle": 0,
              "text": "Vor"
              "text": "einem"
              "text": "großen"
              "text": "Walde"
              "text": "wohnte"
              "text": "ein"
              "text": "armer"
              "text": "Holzhacker"
              "text": "mit"
              "text": "seiner"
              "text": "Frau"
              "text": "und"
              "text": "seinen"
              "text": "zwei"
              "text": "Kindern;"
              "text": "das"
              "text": "Bübchen"
              "text": "hieß"
              "text": "Hänsel"
              "text": "und"
              "text": "das"
              "text": "Mädchen"
              "text": "Gretel."
0
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
0
1