{"id":9106,"date":"2017-09-07T15:00:48","date_gmt":"2017-09-07T06:00:48","guid":{"rendered":"https:\/\/www.ka-net.org\/blog\/?p=9106"},"modified":"2019-11-22T09:50:08","modified_gmt":"2019-11-22T00:50:08","slug":"computer-vision-api%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e7%94%bb%e5%83%8f%e3%81%8b%e3%82%89%e6%96%87%e5%ad%97%e5%88%97%e3%82%92%e5%8f%96%e5%be%97%e3%81%99%e3%82%8bvba%e3%83%9e%e3%82%af%e3%83%ad","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=9106","title":{"rendered":"Computer Vision API\u3092\u4f7f\u3063\u3066\u753b\u50cf\u304b\u3089\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3059\u308bVBA\u30de\u30af\u30ed"},"content":{"rendered":"<p><a href=\"https:\/\/www.ka-net.org\/blog\/?p=9094\" title=\"Cognitive Services(Computer Vision API)\u3092\u4f7f\u3063\u3066\u753b\u50cf\u304b\u3089\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3057\u3066\u307f\u307e\u3057\u305f\u3002 | \u521d\u5fc3\u8005\u5099\u5fd8\u9332\" target=\"_blank\" rel=\"noopener noreferrer\">\u524d\u3005\u56de\u306e\u8a18\u4e8b<\/a>\u3067\u3001Fiddler\u3092\u4f7f\u3063\u3066Microsoft Cognitive Services\u306e<a href=\"https:\/\/azure.microsoft.com\/ja-jp\/services\/cognitive-services\/computer-vision\/\" title=\"Computer Vision - \u753b\u50cf\u51e6\u7406\u304a\u3088\u3073\u753b\u50cf\u5206\u6790 | Microsoft Azure\" target=\"_blank\" rel=\"noopener noreferrer\">Computer Vision API<\/a>\u3092\u547c\u3073\u51fa\u3057\u3066\u307f\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306fVBA\u30de\u30af\u30ed\u304b\u3089API\u3092\u547c\u3073\u51fa\u3057\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h4 class=\"style4a\">VBA\u30b3\u30fc\u30c9<\/h4>\n<p>\u3055\u3063\u305d\u304f\u30b3\u30fc\u30c9\u3067\u3059\u3002<br \/>\n\u5fc5\u8981\u306a\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8URL\u3084API\u30ad\u30fc\u306f\u3001<a href=\"https:\/\/www.ka-net.org\/blog\/?p=9094\" title=\"Cognitive Services(Computer Vision API)\u3092\u4f7f\u3063\u3066\u753b\u50cf\u304b\u3089\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3057\u3066\u307f\u307e\u3057\u305f\u3002 | \u521d\u5fc3\u8005\u5099\u5fd8\u9332\" target=\"_blank\" rel=\"noopener noreferrer\">\u524d\u3005\u56de\u306e\u8a18\u4e8b<\/a>\u3092\u53c2\u8003\u306b\u3057\u3066\u4e8b\u524d\u306b\u53d6\u5f97\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><span style=\"color: #ff0000; font-weight: bold;\">\u203b \u4e0b\u8a18\u30b3\u30fc\u30c9\u306fScriptControl\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u305f\u3081\u300164\u30d3\u30c3\u30c8\u7248Office\u3067\u306f\u52d5\u4f5c\u3057\u307e\u305b\u3093\u3002<\/span><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n \r\nPublic Sub Sample()\r\n  Debug.Print GetOCRTextUsingCognitiveServices(&quot;C:\\Test\\OCR.png&quot;)\r\nEnd Sub\r\n \r\nPrivate Function GetOCRTextUsingCognitiveServices(ByVal TargetFilePath As String, _\r\n                                                  Optional ByVal TargetLanguage As String = &quot;unk&quot;) As String\r\n'CognitiveServices(Computer Vision API)\u3092\u4f7f\u3063\u3066\u753b\u50cf\u304b\u3089\u6587\u5b57\u5217\u3092\u53d6\u5f97\r\n  Dim ret As String\r\n  Dim js As String\r\n  Dim url As String\r\n  Dim dat As Variant\r\n  \r\n  Const apikey = &quot;(API\u30ad\u30fc)&quot;\r\n  Const adTypeBinary = 1\r\n  Const adReadAll = -1\r\n  url = &quot;(\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8URL)&quot;\r\n  If Right(url, 1) &lt;&gt; &quot;\/&quot; Then url = url &amp; &quot;\/&quot;\r\n  \r\n  ret = &quot;&quot; '\u521d\u671f\u5316\r\n  \r\n  '\u30d5\u30a1\u30a4\u30eb\u5224\u5b9a\r\n  With CreateObject(&quot;Scripting.FileSystemObject&quot;)\r\n    If .FileExists(TargetFilePath) = False Then GoTo Fin\r\n    Select Case LCase(.GetExtensionName(TargetFilePath))\r\n      Case &quot;jpg&quot;, &quot;jpeg&quot;, &quot;png&quot;, &quot;gif&quot;, &quot;bmp&quot;\r\n      Case Else: GoTo Fin\r\n    End Select\r\n  End With\r\n  \r\n  '\u30d5\u30a1\u30a4\u30eb\u8aad\u8fbc\r\n  On Error Resume Next\r\n  With CreateObject(&quot;ADODB.Stream&quot;)\r\n    .Open\r\n    .Type = adTypeBinary\r\n    .LoadFromFile TargetFilePath\r\n    dat = .Read(adReadAll)\r\n    .Close\r\n  End With\r\n  If Err.Number &lt;&gt; 0 Then GoTo Fin\r\n  On Error GoTo 0\r\n  \r\n  'Computer Vision API\u547c\u51fa\r\n  With CreateObject(&quot;WinHttp.WinHttpRequest.5.1&quot;)\r\n    .Open &quot;POST&quot;, url &amp; &quot;v1.0\/ocr?language=&quot; &amp; TargetLanguage, False\r\n    .setRequestHeader &quot;Ocp-Apim-Subscription-Key&quot;, apikey\r\n    .setRequestHeader &quot;Content-Type&quot;, &quot;application\/octet-stream&quot;\r\n    .send dat\r\n    Select Case .Status\r\n      Case 200: js = .responseText\r\n      Case Else: GoTo Fin\r\n    End Select\r\n  End With\r\n  If Len(Trim(js)) &gt; 0 Then ret = GetTextFromJSON(js)\r\n  \r\nFin:\r\n  GetOCRTextUsingCognitiveServices = ret\r\nEnd Function\r\n \r\nPrivate Function GetTextFromJSON(ByVal js As String) As String\r\n'JSON\u30c7\u30fc\u30bf\u304b\u3089\u30c6\u30ad\u30b9\u30c8\u53d6\u5f97\r\n  Dim obj As Object\r\n  Dim objRegions As Object\r\n  Dim objRegion As Object\r\n  Dim objLines As Object\r\n  Dim objLine As Object\r\n  Dim objWords As Object\r\n  Dim objWord As Object\r\n  Dim ret As String\r\n  \r\n  ret = &quot;&quot;: js = &quot;(&quot; &amp; js &amp; &quot;)&quot; '\u521d\u671f\u5316\r\n  With CreateObject(&quot;ScriptControl&quot;)\r\n    .Language = &quot;JScript&quot;\r\n    Set obj = .Eval(js)\r\n    Set objRegions = VBA.CallByName(obj, &quot;regions&quot;, VbGet)\r\n    For Each objRegion In objRegions\r\n      If Not objRegion Is Nothing Then\r\n        Set objLines = VBA.CallByName(objRegion, &quot;lines&quot;, VbGet)\r\n        For Each objLine In objLines\r\n          Set objWords = VBA.CallByName(objLine, &quot;words&quot;, VbGet)\r\n          For Each objWord In objWords\r\n            ret = ret &amp; VBA.CallByName(objWord, &quot;text&quot;, VbGet)\r\n          Next\r\n        Next\r\n      End If\r\n    Next\r\n  End With\r\n  GetTextFromJSON = ret\r\nEnd Function<\/pre>\n<p>\u4e0a\u8a18\u30b3\u30fc\u30c9\u3067\u306f\u3001GetOCRTextUsingCognitiveServices\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u7b2c\u4e8c\u5f15\u6570\u3067\u8a00\u8a9e\u3092\u6307\u5b9a\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u6a19\u6e96\u306e\u300c<span style=\"color: #ff0000; font-weight: bold;\">unk<\/span>\u300d\u306b\u3057\u3066\u304a\u3051\u3070\u81ea\u52d5\u5224\u5225\u3055\u308c\u307e\u3059\u304c\u3001\u610f\u56f3\u3057\u305f\u901a\u308a\u306e\u8a00\u8a9e\u3067\u8a8d\u8b58\u3055\u308c\u306a\u3044\u5834\u5408\u306f\u3001<a href=\"https:\/\/westus.dev.cognitive.microsoft.com\/docs\/services\/56f91f2d778daf23d8ec6739\/operations\/56f91f2e778daf14a499e1fc\" title=\"Cognitive Services APIs Reference\" target=\"_blank\" rel=\"noopener noreferrer\">Cognitive Services APIs Reference<\/a>\u3092\u53c2\u8003\u306b\u3001\u8a00\u8a9e\u3092\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h4 class=\"style4a\">\u5b9f\u884c\u7d50\u679c<\/h4>\n<p>\u4e0a\u8a18\u30de\u30af\u30ed\u3092\u5b9f\u884c\u3057\u305f\u7d50\u679c\u306f\u3001\u4e0b\u8a18\u306e\u901a\u308a\u3067\u3057\u305f\u3002<\/p>\n<blockquote><p>\u65e5\u672c\u306b\u304a\u3051\u308b\u300c\u590f(\u306a\u3063)\u300d\u306e\u5b9a\u7fa9\u306f\u3001\u524d\u8ff0\u306e\u4e2d\u56fd\u66a6\u306e\u300cA(xia)\u300d\u306e\u5b9a\u7fa9\u306e\u5f37\u3044\u5f71\u97ff\u3092\u53d7\u3051\u305f\u4e0a\u3001\u8fd1\u4ee3\u306b\u304a\u3044\u3066\u30af\u30ec\u30b3\u30ea\u30aa\u66a6\u306b\u4ed8\u968f\u3059\u308b\u6b27\u7c73\u306e\u6587\u5316\u7684\u5f71\u97ff\u3082\u53d7\u3051\u3066\u8907\u96d1\u306a\u69d8\u76f8\u3092\u5448\u3057\u3066\u3044\u308b\u3002\u4e2d\u56fd\u66a6\u4ee5\u5916\u306e\u66a6\u6cd5\u3092\u77e5\u3089\u306a\u304b\u3063\u305f\u524d\u8fd1\u4ee3\u306e\u6642\u671f\u306b\u306f\u3001\u4e2d\u56fd\u66a6\u306e\u300cA(xia)\u300d\u306e\u5b9a\u7fa9\u3092\u65e5\u672c\u4eba\u3082\u305d\u306e\u307e\u307e\u53d7\u3051\u4eba\u308c\u3055\u308b\u3092\u5f97\u306a\u304b\u3063\u305f\u3002\u3057\u304b\u3057\u3001\u6d77\u6d0b\u6027\u6c17\u5019\u3066\u3042\u308a\u3001\u809d\u5fc3\u306e\u590f\u81f3\u306e\u6642\u671f\u306b\u306f\u6885\u96e8\u306b\u3088\u308a\u65e5\u5c04\u304c\u906e\u3089\u308c\u308b\u65e5\u672c\u3066\u306f\u3001\u524d\u8ff0\u306e\u663c\u9593\u306e\u9577\u3055\u3068\u6c17\u6e29\u306e\u30b9\u30ec\u306f\u4e2d\u56fd\u3088\u308a\u8457\u3057\u304f\u5927\u304d\u304f\u306a\u308b\u3002\u65e5\u672c\u5217\u5cf6\u306b\u304a\u3044\u3066\u306f\u3001\u6c17\u6e29\u306e\u30d2-\u30af\u306f\u7acb\u79cb\u306e\u6642\u671f\u306b\u305a\u308c\u3053\u3080\u305f\u3081\u3001\u6c17\u6e29\u304c\u30d2-\u30af\u306b\u306a\u308b\u9803\u306b\u306f\u3001\u590f\u304c\u7cf8\u51ac\u308f\u3063\u3066\u79cb\u304c\u59cb\u307e\u3063\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u3068\u3044\u3046\u73fe\u8c61\u304c\u751f\u3058\u308b\u3053\u3068\u306b\u306a\u308b\u3002\u3053\u306e\u30f0\u30e3\u30c3\u30d7\u304c\u3001\u73fe\u5728\u3066\u3082\u300c\u66a6\u306e\u4e0a\u3067\u306f\u30fb\u30fb\u590f(\u79cb)\u3066\u3059\u304c\u30fb\u30fb\u30fb(\u6c17\u6e29\u306e\u5b9f\u611f\u306f\u5168\u304f\u9055\u3044\u307e\u3059)\u300d\u3068\u3044\u3046\u30d5\u30ec-\u30b9\u304c\u5929\u6c17\u4e88\u5831\u306a\u3069\u3066\u983b\u7e41\u306b\u7528\u3044\u3089\u308c\u308b\u539f\u56e0\u3068\u306a\u3063\u3066\u3044\u308b\u3002<\/p><\/blockquote>\n<p>\u30c6\u30b9\u30c8\u306b\u4f7f\u7528\u3057\u305f\u306e\u304c\u4e0b\u8a18\u753b\u50cf\u3067\u3001\u5143\u306e\u6587\u306f<a href=\"https:\/\/ja.wikipedia.org\/wiki\/%E5%A4%8F\" title=\"\u590f - Wikipedia\" target=\"_blank\" rel=\"noopener noreferrer\">Wikipedia<\/a>\u304b\u3089\u5f15\u3063\u5f35\u3063\u3066\u304d\u305f\u3082\u306e\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ComputerVisionAPI_02_01.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ComputerVisionAPI_02_01.png\" alt=\"\" width=\"960\" height=\"720\" class=\"alignnone size-full wp-image-9107\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ComputerVisionAPI_02_01.png 960w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ComputerVisionAPI_02_01-300x225.png 300w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ComputerVisionAPI_02_01-768x576.png 768w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/a><\/p>\n<p>\u30c6\u30ad\u30b9\u30c8\u6bd4\u8f03\u30c4\u30fc\u30eb\u3067\u5143\u306e\u6587\u3068\u6bd4\u8f03\u3057\u3066\u307f\u308b\u3068\u3001\u3069\u3053\u304c\u8a8d\u8b58\u3067\u304d\u3066\u3044\u306a\u3044\u306e\u304b\u304c\u3088\u304f\u5206\u304b\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ComputerVisionAPI_02_02.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ComputerVisionAPI_02_02.png\" alt=\"\" width=\"960\" height=\"522\" class=\"alignnone size-full wp-image-9108\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ComputerVisionAPI_02_02.png 960w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ComputerVisionAPI_02_02-300x163.png 300w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ComputerVisionAPI_02_02-768x418.png 768w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/a><\/p>\n<p>\u62ec\u5f27\u3084\u6fc1\u70b9\u306e\u8a8d\u8b58\u304c\u4e0a\u624b\u304f\u3044\u3063\u3066\u3044\u307e\u305b\u3093\u304c\u3001\u3053\u3053\u307e\u3067\u8a8d\u8b58\u3067\u304d\u308c\u3070\u4e0a\u51fa\u6765\u3067\u3059\uff01<br \/>\nVBA\u304b\u3089\u6271\u3044\u3065\u3089\u3044JSON\u5f62\u5f0f\u306e\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u96e3\u70b9\u3067\u3059\u304c\u3001ScriptControl\u3092\u4f7f\u3048\u3070\u6bd4\u8f03\u7684\u7c21\u5358\u306b\u51e6\u7406\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u3002<br \/>\n\u30a2\u30a4\u30c7\u30a2\u6b21\u7b2c\u3067\u6d3b\u7528\u306e\u5834\u304c\u5e83\u304c\u308b\u3068\u601d\u3046\u306e\u3067\u3001\u8208\u5473\u304c\u3042\u308b\u65b9\u306f\u662f\u975e\u304a\u8a66\u3057\u304f\u3060\u3055\u3044\u3002<\/p>\n<div id=\"single_banner_area2\" class=\"clearfix one_banner\">\n<div class=\"single_banner single_banner_left\">\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<!-- \u8a18\u4e8b\u4e2d(\u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u5e83\u544a\u30e6\u30cb\u30c3\u30c8) -->\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block\"\r\n     data-ad-client=\"ca-pub-7306936664602087\"\r\n     data-ad-slot=\"5429724765\"\r\n     data-ad-format=\"auto\"\r\n     data-full-width-responsive=\"true\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\n<\/div>\n<div class=\"single_banner single_banner_right\">\n<a href=\"\" target=\"_blank\"><img decoding=\"async\" src=\"\" alt=\"\" title=\"\" \/><\/a>\n<\/div>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"\u524d\u3005\u56de\u306e\u8a18\u4e8b\u3067\u3001Fiddler\u3092\u4f7f\u3063\u3066Microsoft Cognitive Services\u306eComputer Vision API\u3092\u547c\u3073\u51fa\u3057\u3066\u307f\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306fVBA\u30de\u30af\u30ed\u304b\u3089API\u3092\u547c\u3073\u51fa\u3057\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002 V [&hellip;]","protected":false},"author":1,"featured_media":9108,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"\u6587\u5b57\u8a8d\u8b58\u306f\u5b9f\u7528\u7684\u306a\u30ec\u30d9\u30eb\u3060\u3068\u601d\u3044\u307e\u3059\u3002 [Computer Vision API\u3092\u4f7f\u3063\u3066\u753b\u50cf\u304b\u3089\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3059\u308bVBA\u30de\u30af\u30ed]","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,48,49,58,155],"tags":[],"class_list":["post-9106","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-excel-office","category-word-office","category-powerpoint","category-cognitiveservices"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ComputerVisionAPI_02_02.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-2mS","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/9106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9106"}],"version-history":[{"count":4,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/9106\/revisions"}],"predecessor-version":[{"id":12398,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/9106\/revisions\/12398"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/9108"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}