{"id":185513,"date":"2023-07-21T22:25:55","date_gmt":"2023-07-21T14:25:55","guid":{"rendered":"http:\/\/www.idc.net\/help\/185513\/"},"modified":"2023-07-21T22:25:55","modified_gmt":"2023-07-21T14:25:55","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91%e5%b0%8f%e7%a8%8b%e5%ba%8f%e6%95%99%e7%a8%8b%ef%bc%9a%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f-ocr%c2%b7printedtext","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/185513\/","title":{"rendered":"\u540e\u6d6a\u4e91\u5c0f\u7a0b\u5e8f\u6559\u7a0b\uff1a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f OCR\u00b7printedText"},"content":{"rendered":"<h2>ocr.printedText<\/h2>\n<blockquote><p>\n  \u672c\u63a5\u53e3\u5e94\u5728\u670d\u52a1\u5668\u7aef\u8c03\u7528\uff0c\u8be6\u7ec6\u8bf4\u660e\u53c2\u89c1 \u670d\u52a1\u7aefAPI\u3002\n<\/p><\/blockquote>\n<blockquote><p>\n  \u672c\u63a5\u53e3\u652f\u6301 \u4e91\u8c03\u7528\u3002\u9700\u5f00\u53d1\u8005\u5de5\u5177\u7248\u672c &gt;=&nbsp;1.02.1904090\uff08\u6700\u65b0 \u7a33\u5b9a\u7248\u4e0b\u8f7d\uff09<br \/>\n <br \/>wx-server-sdk&nbsp;&gt;=&nbsp;0.4.0\n<\/p><\/blockquote>\n<p>\u672c\u63a5\u53e3\u63d0\u4f9b\u57fa\u4e8e\u5c0f\u7a0b\u5e8f\u7684\u901a\u7528\u5370\u5237\u4f53 OCR \u8bc6\u522b<\/p>\n<p>\u8c03\u7528\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li>HTTPS \u8c03\u7528<\/li>\n<li>\u4e91\u8c03\u7528<\/li>\n<\/ul>\n<h2>HTTPS \u8c03\u7528<\/h2>\n<h3>\u8bf7\u6c42\u5730\u5740<\/h3>\n<pre><code>POST https:\/\/api.weixin.qq.com\/cv\/ocr\/comm?img_url=ENCODE_URL&amp;access_token=ACCESS_TOCKEN\n<\/code><\/pre>\n<h3>\u8bf7\u6c42\u53c2\u6570<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u9ed8\u8ba4\u503c<\/th>\n<th>\u5fc5\u586b<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>access_token<\/td>\n<td>string<\/td>\n<td><\/td>\n<td>\u662f<\/td>\n<td>\u63a5\u53e3\u8c03\u7528\u51ed\u8bc1<\/td>\n<\/tr>\n<tr>\n<td>img_url<\/td>\n<td>string<\/td>\n<td><\/td>\n<td>\u662f<\/td>\n<td>\u8981\u68c0\u6d4b\u7684\u56fe\u7247 url\uff0c\u4f20\u8fd9\u4e2a\u5219\u4e0d\u7528\u4f20 img \u53c2\u6570\u3002<\/td>\n<\/tr>\n<tr>\n<td>img<\/td>\n<td>FormData<\/td>\n<td><\/td>\n<td>\u662f<\/td>\n<td>form-data \u4e2d\u5a92\u4f53\u6587\u4ef6\u6807\u8bc6\uff0c\u6709filename\u3001filelength\u3001content-type\u7b49\u4fe1\u606f\uff0c\u4f20\u8fd9\u4e2a\u5219\u4e0d\u7528\u4f20 img_url\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u8fd4\u56de\u503c<\/h3>\n<h3>Object<\/h3>\n<p>\u8fd4\u56de\u7684 JSON \u6570\u636e\u5305<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>errcode<\/td>\n<td>string<\/td>\n<td>\u9519\u8bef\u7801<\/td>\n<\/tr>\n<tr>\n<td>errmsg<\/td>\n<td>string<\/td>\n<td>\u9519\u8bef\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td>items<\/td>\n<td>string<\/td>\n<td>\u8bc6\u522b\u7ed3\u679c<\/td>\n<\/tr>\n<tr>\n<td>img_size<\/td>\n<td>string<\/td>\n<td>\u56fe\u7247\u5927\u5c0f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u4f7f\u7528\u8bf4\u660e<\/h3>\n<p>\u63a5\u53e3\u9650\u5236&nbsp;\u5185\u6d4b\u671f\u95f4\u5df2\u8ba4\u8bc1\u7684\u8ba2\u9605\u53f7\u3001\u670d\u52a1\u53f7\u3001\u4f01\u4e1a\u53f7\u3001\u5c0f\u7a0b\u5e8f\u53ef\u76f4\u63a5\u8c03\u7528\uff0c\u6b21\u6570\u9650\u5236\u4e3a500\u6b21\/\u5929\u3002<\/p>\n<p>\u4f7f\u7528 Tips&nbsp;\u6b64\u63a5\u53e3\u4e3a\u540e\u53f0\u63a5\u53e3\uff0c\u53ef\u57fa\u4e8e\u81ea\u6709\u4e1a\u52a1\u627f\u8f7d\u60c5\u51b5\uff0c\u642d\u914d\u5c0f\u7a0b\u5e8f\u7684\u62cd\u7167\u3001\u76f8\u518c\u9009\u7167\u7b49\u4e00\u8d77\u4f7f\u7528\uff0c\u5373\u53ef\u5b8c\u6210\u8eab\u4efd\u8bc1\u7167\u7247\u7684\u91c7\u96c6\u3001\u4e0a\u4f20\u3001\u8bc6\u522b\u3001\u4fe1\u606f\u8fd4\u56de\u7b49\u6d41\u7a0b\uff0c\u7528\u4e8e\u9700\u8981\u57fa\u4e8e\u8eab\u4efd\u8bc1\u3001\u94f6\u884c\u5361\u7b49\u5b9e\u4f53\u5361\u6216\u8bc1\uff0c\u91c7\u96c6\u7167\u7247\u6216\u6587\u5b57\u4fe1\u606f\u7b49\u7684\u4e1a\u52a1\u573a\u666f\u3002<\/p>\n<p>\u56fe\u7247\u8bf4\u660e&nbsp;\u6587\u4ef6\u5927\u5c0f\u9650\u5236\uff1a\u5c0f\u4e8e2M<\/p>\n<p>\u56fe\u7247\u652f\u6301\u4f7f\u7528img\u53c2\u6570\u5b9e\u65f6\u4e0a\u4f20\uff0c\u4e5f\u652f\u6301\u4f7f\u7528img_url\u53c2\u6570\u4f20\u9001\u56fe\u7247\u5730\u5740\uff0c\u7531\u5fae\u4fe1\u540e\u53f0\u4e0b\u8f7d\u56fe\u7247\u8fdb\u884c\u8bc6\u522b\u3002 \u901a\u7528\u5370\u5237\u4f53OCR\u9002\u7528\u4e8e\u5c4f\u5e55\u622a\u56fe\u3001\u5370\u5237\u4f53\u7167\u7247\u7b49\u573a\u666f<\/p>\n<h3>\u8bf7\u6c42\u6570\u636e\u793a\u4f8b<\/h3>\n<p>\u793a\u4f8b1\uff1a<\/p>\n<pre><code>curl http:\/\/api.weixin.qq.com\/cv\/ocr\/comm?img_url=ENCODE_URL&amp;access_token=ACCESS_TOCKEN\n<\/code><\/pre>\n<p>\u793a\u4f8b2\uff1a<\/p>\n<pre><code>curl -F \u2018img=@test.jpg\u2019\u201chttp:\/\/api.weixin.qq.com\/cv\/ocr\/comm?access_token=ACCESS_TOCKEN\u201d\n<\/code><\/pre>\n<h3>\u8fd4\u56de\u6570\u636e\u793a\u4f8b<\/h3>\n<pre><code>{\n    \"errcode\": 0,\n    \"errmsg\": \"ok\",\n    \"items\": [ \/\/\u8bc6\u522b\u7ed3\u679c\n        {\n            \"text\": \"\u817e\u8baf\",\n            \"pos\": {\n                \"left_top\": {\n                    \"x\": 575,\n                    \"y\": 519\n                },\n                \"right_top\": {\n                    \"x\": 744,\n                    \"y\": 519\n                },\n                \"right_bottom\": {\n                    \"x\": 744,\n                    \"y\": 532\n                },\n                \"left_bottom\": {\n                    \"x\": 573,\n                    \"y\": 532\n                }\n            }\n        },\n        {\n            \"text\": \"\u5fae\u4fe1\u56e2\u961f\",\n            \"pos\": {\n                \"left_top\": {\n                    \"x\": 670,\n                    \"y\": 516\n                },\n                \"right_top\": {\n                    \"x\": 762,\n                    \"y\": 517\n                },\n                \"right_bottom\": {\n                    \"x\": 762,\n                    \"y\": 532\n                },\n                \"left_bottom\": {\n                    \"x\": 670,\n                    \"y\": 531\n                }\n            }\n        }\n    ],\n    \"img_size\": { \/\/\u56fe\u7247\u5927\u5c0f\n        \"w\": 1280,\n        \"h\": 720\n    }\n}\n<\/code><\/pre>\n<h2>\u4e91\u8c03\u7528<\/h2>\n<blockquote><p> \u4e91\u8c03\u7528\u662f\u5c0f\u7a0b\u5e8f\u00b7\u4e91\u5f00\u53d1\u63d0\u4f9b\u7684\u5728\u4e91\u51fd\u6570\u4e2d\u8c03\u7528\u5fae\u4fe1\u5f00\u653e\u63a5\u53e3\u7684\u80fd\u529b\uff0c\u9700\u8981\u5728\u4e91\u51fd\u6570\u4e2d\u901a\u8fc7&nbsp;wx-server-sdk&nbsp;\u4f7f\u7528\u3002\n<\/p><\/blockquote>\n<h3>\u63a5\u53e3\u65b9\u6cd5<\/h3>\n<pre><code>openapi.ocr.printedText\n<\/code><\/pre>\n<blockquote><p>\n  \u9700\u5728&nbsp;config.json&nbsp;\u4e2d\u914d\u7f6e&nbsp;ocr.printedText&nbsp;API \u7684\u6743\u9650\uff0c \u8be6\u60c5\n<\/p><\/blockquote>\n<h3>\u8bf7\u6c42\u53c2\u6570<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u9ed8\u8ba4\u503c<\/th>\n<th>\u5fc5\u586b<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>imgUrl<\/td>\n<td>string<\/td>\n<td><\/td>\n<td>\u662f<\/td>\n<td>\u8981\u68c0\u6d4b\u7684\u56fe\u7247 url\uff0c\u4f20\u8fd9\u4e2a\u5219\u4e0d\u7528\u4f20 img \u53c2\u6570\u3002<\/td>\n<\/tr>\n<tr>\n<td>img<\/td>\n<td>FormData<\/td>\n<td><\/td>\n<td>\u662f<\/td>\n<td>form-data \u4e2d\u5a92\u4f53\u6587\u4ef6\u6807\u8bc6\uff0c\u6709filename\u3001filelength\u3001content-type\u7b49\u4fe1\u606f\uff0c\u4f20\u8fd9\u4e2a\u5219\u4e0d\u7528\u4f20 img_url\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>img \u7684\u7ed3\u6784<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u9ed8\u8ba4\u503c<\/th>\n<th>\u5fc5\u586b<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>contentType<\/td>\n<td>string<\/td>\n<td><\/td>\n<td>\u662f<\/td>\n<td>\u6570\u636e\u7c7b\u578b\uff0c\u4f20\u5165 MIME Type<\/td>\n<\/tr>\n<tr>\n<td>value<\/td>\n<td>Buffer<\/td>\n<td><\/td>\n<td>\u662f<\/td>\n<td>\u6587\u4ef6 Buffer<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u8fd4\u56de\u503c<\/h3>\n<h3>Object<\/h3>\n<p>\u8fd4\u56de\u7684 JSON \u6570\u636e\u5305<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>errCode<\/td>\n<td>string<\/td>\n<td>\u9519\u8bef\u7801<\/td>\n<\/tr>\n<tr>\n<td>errMsg<\/td>\n<td>string<\/td>\n<td>\u9519\u8bef\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td>items<\/td>\n<td>string<\/td>\n<td>\u8bc6\u522b\u7ed3\u679c<\/td>\n<\/tr>\n<tr>\n<td>imgSize<\/td>\n<td>string<\/td>\n<td>\u56fe\u7247\u5927\u5c0f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u5f02\u5e38<\/h3>\n<h3>Object<\/h3>\n<p>\u629b\u51fa\u7684\u5f02\u5e38<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>errCode<\/td>\n<td>string<\/td>\n<td>\u9519\u8bef\u7801<\/td>\n<\/tr>\n<tr>\n<td>errMsg<\/td>\n<td>string<\/td>\n<td>\u9519\u8bef\u4fe1\u606f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>errCode \u7684\u5408\u6cd5\u503c<\/p>\n<table>\n<thead>\n<tr>\n<th>\u503c<\/th>\n<th>\u8bf4\u660e<\/th>\n<th>\u6700\u4f4e\u7248\u672c<\/th>\n<\/tr>\n<\/thead>\n<tbody><\/tbody>\n<\/table>\n<h3>\u4f7f\u7528\u8bf4\u660e<\/h3>\n<p>\u63a5\u53e3\u9650\u5236&nbsp;\u5185\u6d4b\u671f\u95f4\u5df2\u8ba4\u8bc1\u7684\u8ba2\u9605\u53f7\u3001\u670d\u52a1\u53f7\u3001\u4f01\u4e1a\u53f7\u3001\u5c0f\u7a0b\u5e8f\u53ef\u76f4\u63a5\u8c03\u7528\uff0c\u6b21\u6570\u9650\u5236\u4e3a500\u6b21\/\u5929\u3002<\/p>\n<p>\u4f7f\u7528 Tips&nbsp;\u6b64\u63a5\u53e3\u4e3a\u540e\u53f0\u63a5\u53e3\uff0c\u53ef\u57fa\u4e8e\u81ea\u6709\u4e1a\u52a1\u627f\u8f7d\u60c5\u51b5\uff0c\u642d\u914d\u5c0f\u7a0b\u5e8f\u7684\u62cd\u7167\u3001\u76f8\u518c\u9009\u7167\u7b49\u4e00\u8d77\u4f7f\u7528\uff0c\u5373\u53ef\u5b8c\u6210\u8eab\u4efd\u8bc1\u7167\u7247\u7684\u91c7\u96c6\u3001\u4e0a\u4f20\u3001\u8bc6\u522b\u3001\u4fe1\u606f\u8fd4\u56de\u7b49\u6d41\u7a0b\uff0c\u7528\u4e8e\u9700\u8981\u57fa\u4e8e\u8eab\u4efd\u8bc1\u3001\u94f6\u884c\u5361\u7b49\u5b9e\u4f53\u5361\u6216\u8bc1\uff0c\u91c7\u96c6\u7167\u7247\u6216\u6587\u5b57\u4fe1\u606f\u7b49\u7684\u4e1a\u52a1\u573a\u666f\u3002<\/p>\n<p>\u56fe\u7247\u8bf4\u660e&nbsp;\u6587\u4ef6\u5927\u5c0f\u9650\u5236\uff1a\u5c0f\u4e8e2M<\/p>\n<p>\u56fe\u7247\u652f\u6301\u4f7f\u7528img\u53c2\u6570\u5b9e\u65f6\u4e0a\u4f20\uff0c\u4e5f\u652f\u6301\u4f7f\u7528img_url\u53c2\u6570\u4f20\u9001\u56fe\u7247\u5730\u5740\uff0c\u7531\u5fae\u4fe1\u540e\u53f0\u4e0b\u8f7d\u56fe\u7247\u8fdb\u884c\u8bc6\u522b\u3002 \u901a\u7528\u5370\u5237\u4f53OCR\u9002\u7528\u4e8e\u5c4f\u5e55\u622a\u56fe\u3001\u5370\u5237\u4f53\u7167\u7247\u7b49\u573a\u666f<\/p>\n<h3>\u8bf7\u6c42\u6570\u636e\u793a\u4f8b<\/h3>\n<pre><code>const cloud = require('wx-server-sdk')\ncloud.init()\nexports.main = async (event, context) =&gt; {\n  try {\n    const result = await cloud.openapi.ocr.printedText({\n        type: 'photo',\n        imgUrl: 'ENCODE_URL'\n      })\n    return result\n  } catch (err) {\n    return err\n  }\n}\n<\/code><\/pre>\n<p>\u6216<\/p>\n<pre><code>\/\/ cloud = require('wx-server-sdk')\n\/\/ ...\n\/\/ \u65b9\u6cd5\u8fd4\u56de Promise\ncloud.openapi.ocr.printedText({\n  type: 'photo',\n  img: {\n    contentType: 'image\/png',\n    value: Buffer\n  }\n})\n<\/code><\/pre>\n<h3>\u8fd4\u56de\u6570\u636e\u793a\u4f8b<\/h3>\n<pre><code>{\n    \"errcode\": 0,\n    \"errmsg\": \"ok\",\n    \"items\": [ \/\/\u8bc6\u522b\u7ed3\u679c\n        {\n            \"text\": \"\u817e\u8baf\",\n            \"pos\": {\n                \"left_top\": {\n                    \"x\": 575,\n                    \"y\": 519\n                },\n                \"right_top\": {\n                    \"x\": 744,\n                    \"y\": 519\n                },\n                \"right_bottom\": {\n                    \"x\": 744,\n                    \"y\": 532\n                },\n                \"left_bottom\": {\n                    \"x\": 573,\n                    \"y\": 532\n                }\n            }\n        },\n        {\n            \"text\": \"\u5fae\u4fe1\u56e2\u961f\",\n            \"pos\": {\n                \"left_top\": {\n                    \"x\": 670,\n                    \"y\": 516\n                },\n                \"right_top\": {\n                    \"x\": 762,\n                    \"y\": 517\n                },\n                \"right_bottom\": {\n                    \"x\": 762,\n                    \"y\": 532\n                },\n                \"left_bottom\": {\n                    \"x\": 670,\n                    \"y\": 531\n                }\n            }\n        }\n    ],\n    \"img_size\": { \/\/\u56fe\u7247\u5927\u5c0f\n        \"w\": 1280,\n        \"h\": 720\n    }\n}<\/code><\/pre>\n<p> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>ocr.printedText \u672c\u63a5\u53e3\u5e94\u5728\u670d\u52a1\u5668\u7aef\u8c03\u7528\uff0c\u8be6\u7ec6\u8bf4\u660e\u53c2\u89c1 \u670d\u52a1\u7aefAPI\u3002 \u672c\u63a5\u53e3\u652f\u6301 \u4e91\u8c03\u7528\u3002\u9700\u5f00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182398],"tags":[],"class_list":["post-185513","post","type-post","status-publish","format-standard","hentry","category-mini-program"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/185513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=185513"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/185513\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=185513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=185513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=185513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}