Power Automate for desktop

[Power Automate Desktop]OCR(Computer Vision)アクションを実行してみました。

先週の金曜日に開催されたRPA勉強会に参加し、PADとAI-OCRのデモを拝見させていただきました。

デモで使われていたのは主に「Tegaki」でしたが、PADには標準でComputer Visionを使ったOCR機能が実行可能な「OCR」アクションが用意されているので、試しに使ってみることにしました。

サブスクリプションキーの取得

上記の通り、OCRアクションはComputer Visionを使用するため、事前にサブスクリプションキーを取得しておく必要があります(要Azureへのアカウント登録)。

  1. Azure Portalを開きます。
  2. Cognitive Services」をクリックします。
  3. 作成」をクリックします。
  4. 「Computer Vision」でキーワード検索し、ヒットした「Computer Vision」をクリックします。
  5. 作成」ボタンをクリックします。
  6. サブスクリプション、リソース グループ、リージョン、名前、価格レベルを指定し、「確認および作成」ボタンをクリックします。今回はテスト目的なので、価格レベルは「Free F0 (20 Calls per minute, 5K Calls per month)」を指定しておきます。
  7. 内容を確認し、「作成」ボタンをクリックします。
  8. デプロイが完了したらリソースに移動します。
  9. キーとエンドポイント」を開くとサブスクリプションキーが表示されるので、コピーしておきます。

OCRアクションで画像から文字列を認識するフロー

サブスクリプションキーが取得できたら、いよいよOCRアクションの実行です。

テスト用画像

テストには下記の画像(原文は「夏 – Wikipedia」より)を使用しました。

フロー全体

1. OCR

コグニティブ → Microsoft → Computer Vision から「OCR」アクションを挿入し、サーバーの場所(リージョン)、サブスクリプションキー、画像、言語、向きの自動検出を指定します。このとき言語として「unk」を指定することで、言語が自動検出されます。

問題が無ければ、下記のようなJSONデータが返ってきます。

{
  "language":"ja",
  "textAngle":0.0,
  "orientation":"Up",
  "regions":[
    {
      "Properties":{
        "boundingBox":"14,12,814,81",
        "lines":[
          {
            "Properties":{
              "boundingBox":"17,12,795,26",
              "words":[
                {
                  "Properties":{
                    "boundingBox":"17,14,18,20",
                    "text":"日"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"38,13,24,21",
                    "text":"本"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"65,14,19,19",
                    "text":"に"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"87,14,22,19",
                    "text":"お"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"112,14,22,20",
                    "text":"け"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"136,15,20,19",
                    "text":"る"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"173,13,8,20",
                    "text":"「"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"183,14,22,20",
                    "text":"夏"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"222,13,7,22",
                    "text":"("
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"231,14,22,20",
                    "text":"な"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"255,17,22,15",
                    "text":"っ"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"279,13,7,22",
                    "text":")"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"303,15,8,20",
                    "text":"」"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"327,16,22,17",
                    "text":"の"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"351,13,22,21",
                    "text":"定"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"375,13,22,21",
                    "text":"義"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"400,14,22,19",
                    "text":"は"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"424,28,5,6",
                    "text":"、"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"447,12,22,22",
                    "text":"前"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"470,13,24,21",
                    "text":"述"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"495,16,22,17",
                    "text":"の"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"520,13,20,21",
                    "text":"中"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"543,14,21,20",
                    "text":"国"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"566,14,24,20",
                    "text":"暦"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"591,16,22,17",
                    "text":"の"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"629,13,8,20",
                    "text":"「"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"639,14,76,24",
                    "text":"A(xia)"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"718,15,8,20",
                    "text":"」"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"742,16,22,17",
                    "text":"の"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"766,13,22,21",
                    "text":"定"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"790,13,22,21",
                    "text":"義"
                  }
                }
              ]
            }
          },
          {
            "Properties":{
              "boundingBox":"15,41,813,23",
              "words":[
                {
                  "Properties":{
                    "boundingBox":"15,45,22,17",
                    "text":"の"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"39,42,22,21",
                    "text":"強"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"64,45,21,16",
                    "text":"い"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"86,43,24,20",
                    "text":"影"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"111,42,22,22",
                    "text":"響"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"135,43,21,19",
                    "text":"を"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"159,42,22,20",
                    "text":"受"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"184,43,22,20",
                    "text":"け"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"207,43,22,20",
                    "text":"た"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"231,43,22,20",
                    "text":"上"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"256,57,5,6",
                    "text":"、"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"278,42,24,21",
                    "text":"近"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"302,42,23,21",
                    "text":"代"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"329,43,19,19",
                    "text":"に"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"351,43,22,19",
                    "text":"お"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"376,45,21,16",
                    "text":"い"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"399,45,21,17",
                    "text":"て"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"422,41,24,22",
                    "text":"ク"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"450,44,19,19",
                    "text":"レ"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"470,42,20,19",
                    "text":"コ"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"498,43,16,19",
                    "text":"リ"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"519,43,22,20",
                    "text":"オ"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"542,43,24,20",
                    "text":"暦"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"569,43,19,19",
                    "text":"に"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"590,41,23,21",
                    "text":"付"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"615,42,22,21",
                    "text":"随"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"640,43,21,19",
                    "text":"す"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"664,44,20,19",
                    "text":"る"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"687,42,22,21",
                    "text":"欧"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"710,43,24,21",
                    "text":"米"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"735,45,22,17",
                    "text":"の"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"759,42,22,21",
                    "text":"文"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"782,42,23,21",
                    "text":"化"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"807,41,21,22",
                    "text":"的"
                  }
                }
              ]
            }
          },
          {
            "Properties":{
              "boundingBox":"14,71,417,22",
              "words":[
                {
                  "Properties":{
                    "boundingBox":"14,72,24,20",
                    "text":"影"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"39,71,22,22",
                    "text":"響"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"64,72,20,19",
                    "text":"も"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"87,71,22,20",
                    "text":"受"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"112,72,22,20",
                    "text":"け"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"135,74,21,17",
                    "text":"て"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"158,71,23,21",
                    "text":"複"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"182,71,23,21",
                    "text":"雑"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"207,72,22,20",
                    "text":"な"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"230,71,23,21",
                    "text":"様"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"254,71,22,21",
                    "text":"相"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"279,72,21,19",
                    "text":"を"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"303,72,22,20",
                    "text":"呈"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"330,73,18,18",
                    "text":"し"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"351,74,21,17",
                    "text":"て"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"376,74,21,16",
                    "text":"い"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"400,73,20,19",
                    "text":"る"
                  }
                },
                {
                  "Properties":{
                    "boundingBox":"424,86,7,6",
                    "text":"。"
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}
2. If

OCRアクションが上手くいった場合のみ =返ってくるステータスコードが200の場合のみ処理を行います。

3. For each

4. 変数の設定

For eachループでtextの値のみを変数に追加していきます。

5. テキストに行を追加

「テキストに行を追加」アクションで改行を挿入します。

6. メッセージを表示

最後に結果をメッセージボックスで表示します。

実行画面

認識結果

結果は下の通りで、なかなかの認識精度です。

日本における「夏(なっ)」の定義は、前述の中国暦の「A(xia)」の定義
の強い影響を受けた上、近代においてクレコリオ暦に付随する欧米の文化的
影響も受けて複雑な様相を呈している。
中国暦以外の暦法を知らなかった前近代の時期には、中国暦の「A(xia)」
の定義を日本人もそのまま受け人れさるを得なかった。しかし、海洋性気候
てあり、肝心の夏至の時期には梅雨により日射が遮られる日本ては、前述の
昼間の長さと気温のスレは中国より著しく大きくなる。日本列島においては、
気温のヒ-クは立秋の時期にずれこむため、気温がヒ-クになる頃には、夏
が糸冬わって秋が始まってしまっているという現象が生じることになる。この
ヰャップが、現在ても「暦の上では・・夏(秋)てすが・・・(気温の実感は全く
違います)」というフレ-スが天気予報などて頻繁に用いられる原因となっ
ている。

今回テストした限りでは、特に躓くことなくOCRアクションを実行できましたが、Cognitive Services APIを使用した経験が無いとアクションの設定(特にサブスクリプションキー)が分かりづらいかもしれません。

また、今回のテストで地味に引っ掛かったのが、変数内で改行を挿入する処理でした。
「変数の設定」アクションで改行を挿入しようにも、EnterやShift + Enterといったキー入力も効きません。

アクションを一度テキストエディタにコピー、下記のように改行を挿入してから再度貼り付けることで改行を挿入できましたが、わざわざコピペするのも面倒だったため、最終的には「テキストに行を追加」アクションを使うことにしました。

SET result TO $'''%result%
'''

2021/6/29 追記:
OCRアクション時の動作をキャプチャーしてみました。

POST https://eastasia.api.cognitive.microsoft.com/vision/v1.0/ocr?language=unk&detectOrientation=true HTTP/1.1
Content-Type: application/octet-stream
Ocp-Apim-Subscription-Key: ********************************
Host: eastasia.api.cognitive.microsoft.com
Content-Length: *****
Expect: 100-continue
Connection: Keep-Alive

アクション名通りCognitive Services APIを呼び出しているようです。
(使用しているのはComputer Vision API (v1.0))

Power Automate DesktopのフローからMicrosoft Graph APIを呼び出してみました。前のページ

Power Automate for desktopのアクション一覧次のページ

関連記事

  1. Office関連

    Computer Vision APIを使って画像から文字列を取得するVBAマクロ

    前々回の記事で、Fiddlerを使ってMicrosoft Cognit…

  2. Power Automate for desktop

    [Power Automate Desktop]Google Driveにファイルをアップロードする…

    前々回の記事でGoogle Drive APIの実行に必要なアクセスト…

  3. Power Automate for desktop

    無料で学ぶPower Automate Desktop

    下記記事にある通り、2021年の3月からPower Automate …

コメント

  • コメント (0)

  • トラックバックは利用できません。

  1. この記事へのコメントはありません。

Time limit is exhausted. Please reload CAPTCHA.

※本ページはプロモーションが含まれています。

Translate

最近の記事

アーカイブ

PAGE TOP