{"id":10020599,"date":"2025-01-10T17:04:48","date_gmt":"2025-01-10T09:04:48","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020599"},"modified":"2025-01-10T17:04:48","modified_gmt":"2025-01-10T09:04:48","slug":"%e4%bd%bf%e7%94%a8%e8%85%be%e8%ae%af%e4%ba%91%e7%9a%84%e5%85%8d%e8%b4%b9%e9%a2%9d%e5%ba%a6%e8%bf%9b%e8%a1%8cocr%e8%af%86%e5%88%ab%ef%bc%8c%e6%8f%90%e5%8f%96%e5%9b%be%e7%89%87%e4%b8%ad%e7%9a%84","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020599","title":{"rendered":"\u4f7f\u7528\u817e\u8baf\u4e91\u7684\u514d\u8d39\u989d\u5ea6\u8fdb\u884cocr\u8bc6\u522b\uff0c\u63d0\u53d6\u56fe\u7247\u4e2d\u7684\u6587\u5b57\uff08\u6bcf\u4e2a\u6708\u514d\u8d391000\u989d\u5ea6\uff09"},"content":{"rendered":"<h2>\u9700\u6c42\u63cf\u8ff0<\/h2>\n<ul>\n<li>\u6700\u8fd1\u6709\u4e00\u4e2a\u56fe\u7247\u8bc6\u522b\u63d0\u53d6\u6587\u5b57\u7684\u9700\u6c42<\/li>\n<li>\u672c\u6765\u60f3\u4f7f\u7528<a href=\"https:\/\/link.segmentfault.com\/?enc=ROpw3b%2FgVaM4dtZVJx2C1g%3D%3D.pN7YNl%2Bf8n82hIw5XuDHm96l1nkkE3Sr%2FOOooujv6EjCiD38O5JeYXLw9577FW%2Ft\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">tesseract.js<\/a>\u5199<\/li>\n<li>\u540e\u6765\u53d1\u73b0\u8bc6\u522b\u7387\u8fd8\u662f\u4e0d\u592a\u591f\u7528<\/li>\n<li>\u4e8e\u662f\uff0c\u66f4\u6539\u4e3a\u4f7f\u7528\u817e\u8baf\u4e91\u7684\u63a5\u53e3\u670d\u52a1\uff08\u7b14\u8005\u4e00\u76f4\u8d2d\u4e70\u7684\u662f\u817e\u8baf\u4e91\u7684\u670d\u52a1\u5668\uff09<\/li>\n<li>\u672c\u6587\uff0c\u8bb0\u5f55\u4e00\u4e0b\u4f7f\u7528\u7684\u8fc7\u7a0b\uff08\u4e3b\u8981\u662f\u4f7f\u7528node\u542f\u4e00\u4e2a\u670d\u52a1\uff0c\u518d\u53bb\u8c03\u7528\u817e\u8baf\u4e91\u7684\u670d\u52a1\uff09<\/li>\n<\/ul>\n<h2>\u6bcf\u4e2a\u6708\u514d\u8d391000\u989d\u5ea6<\/h2>\n<ul>\n<li><em>\u817e\u8baf\u4e91\uff0c\u8d22\u5927\u6c14\u7c97\uff0c\u6bcf\u4e2a\u6708\u90fd\u67091000\u989d\u5ea6\uff0c\u5982\u4e0b\u56fe\uff1a<\/em><\/li>\n<li>\u817e\u8baf\u4e91\uff0c\u8d22\u5927\u6c14\u7c97\uff0c\u6bcf\u4e2a\u6708\u90fd\u67091000\u989d\u5ea6\uff0c\u5982\u4e0b\u56fe\uff1a<\/li>\n<li><strong>\u817e\u8baf\u4e91\uff0c\u8d22\u5927\u6c14\u7c97\uff0c\u6bcf\u4e2a\u6708\u90fd\u67091000\u989d\u5ea6\uff0c\u5982\u4e0b\u56fe\uff1a<\/strong><\/li>\n<\/ul>\n<p>\u4e2a\u4eba\u8db3\u591f\u7528\u4e86&#8230;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"430\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdhb7f\" alt=\"\" title=\"\"><\/p>\n<h2>\u8bc6\u522b\u6b64\u56fe\u7247\u7684\u7ed3\u679c<\/h2>\n<p><em>\u5047\u8bbe\u6211\u4eec\u6709\u8fd9\u5f20\u56fe\u7247\uff0c\u9700\u8981\u53bb\u8bc6\u522b\u5176\u4e2d\u7684\u6587\u5b57<\/em><\/p>\n<p><img decoding=\"async\" width=\"302\" height=\"191\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdhb7g\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><em>\u8bc6\u522b\u6210\u529f\u7684\u7ed3\u679cjson\u5982\u4e0b\uff1a<\/em><\/p>\n<pre><code class=\"js\">{\n    Angel: 359.989990234375,\n    Angle: 359.989990234375,\n    Language: 'zh',\n    PdfPageSize: 0,\n    RequestId: '5790201d-cd25-402c-b14b-d898242fdd2c',\n    TextDetections: [\n      {\n        AdvancedInfo: '{&quot;Parag&quot;:{&quot;ParagNo&quot;:1}}',\n        Confidence: 100,\n        DetectedText: '\u300a\u767b\u9e73\u96c0\u697c\u300b',\n        ItemPolygon: [Object],\n        Polygon: [Array],\n        WordCoordPoint: [],\n        Words: []\n      },\n      {\n        AdvancedInfo: '{&quot;Parag&quot;:{&quot;ParagNo&quot;:2}}',\n        Confidence: 100,\n        DetectedText: '[\u5510].\u738b\u4e4b\u6da3',\n        ItemPolygon: [Object],\n        Polygon: [Array],\n        WordCoordPoint: [],\n        Words: []\n      },\n      {\n        AdvancedInfo: '{&quot;Parag&quot;:{&quot;ParagNo&quot;:3}}',\n        Confidence: 100,\n        DetectedText: '\u767d\u65e5\u4f9d\u5c71\u5c3d\uff0c\u9ec4\u6cb3\u5165\u6d77\u6d41\u3002',\n        ItemPolygon: [Object],\n        Polygon: [Array],\n        WordCoordPoint: [],\n        Words: []\n      },\n      {\n        AdvancedInfo: '{&quot;Parag&quot;:{&quot;ParagNo&quot;:3}}',\n        Confidence: 100,\n        DetectedText: '\u6b32\u7a77\u5343\u91cc\u76ee\uff0c\u66f4\u4e0a\u4e00\u5c42\u697c\u3002',\n        ItemPolygon: [Object],\n        Polygon: [Array],\n        WordCoordPoint: [],\n        Words: []\n      }\n    ]\n  }<\/code><\/pre>\n<blockquote><p>\u51c6\u786e\u7387\u8fd8\u662f\u4e0d\u9519\u7684\uff0c\u8fd9\u6837\u7684\u8bdd\uff0c\u6211\u4eec\u62ff\u5230\u8bc6\u522b\u540e\u7684\u7ed3\u679c\uff0c\u5c31\u53ef\u4ee5\u8fdb\u884c\u76f8\u5173\u7684\u64cd\u4f5c\u4e86<\/p><\/blockquote>\n<h2>\u4ee3\u7801<\/h2>\n<ul>\n<li>\u4f7f\u7528 <code>npm init --y<\/code> \u521b\u5efa\u4e00\u4e2anode\u9879\u76ee<\/li>\n<li>\u518d\u4e0b\u8f7d\u817e\u8baf\u4e91\u7684\u5305 <code>npm i tencentcloud-sdk-nodejs --save<\/code><\/li>\n<li>\u65b0\u5efa\u4e00\u4e2a<code>index.js<\/code>\u6587\u4ef6<\/li>\n<li>\u590d\u5236\u7c98\u8d34\u4ee5\u4e0b\u4ee3\u7801\uff0c\u5373\u53ef\u4f7f\u7528<\/li>\n<\/ul>\n<pre><code class=\"js\">const fs = require('fs');\nconst path = require('path');\nconst tencentcloud = require(&quot;tencentcloud-sdk-nodejs&quot;)\n\n\/\/ \u5bfc\u5165\u5bf9\u5e94\u4ea7\u54c1\u6a21\u5757\u7684client models\u3002\nconst OcrClient = tencentcloud.ocr.v20181119.Client\n\n\/\/ \u5b9e\u4f8b\u5316\u8981\u8bf7\u6c42\u4ea7\u54c1\u7684client\u5bf9\u8c61\nconst client = new OcrClient({\n    \/\/ \u817e\u8baf\u4e91\u8ba4\u8bc1\u4fe1\u606f\n    credential: {\n        secretId: &quot;xxxyyyzzzId&quot;,\n        secretKey: &quot;xxxyyyzzzKey&quot;,\n    },\n    \/\/ \u4ea7\u54c1\u5730\u57df\n    region: &quot;ap-shanghai&quot;,\n    \/\/ \u53ef\u9009\u914d\u7f6e\u5b9e\u4f8b\n    profile: {\n        signMethod: &quot;TC3-HMAC-SHA256&quot;, \/\/ \u7b7e\u540d\u65b9\u6cd5\n        httpProfile: {\n            reqMethod: &quot;POST&quot;, \/\/ \u8bf7\u6c42\u65b9\u6cd5\n            reqTimeout: 30, \/\/ \u8bf7\u6c42\u8d85\u65f6\u65f6\u95f4\uff0c\u9ed8\u8ba460s\n        },\n    },\n})\n\n\n\/**\n * \u4f20\u53c2\u65b9\u5f0f\u4e00\uff0c\u901a\u8fc7\u56fe\u7247URL\u4f20\u53c2\n * *\/ \n\/\/ const params = {\n\/\/     &quot;ImageUrl&quot;: &quot;http:\/\/ashuai.work\/api\/pic.png&quot;\n\/\/ };\n\n\/**\n * \u4f20\u53c2\u65b9\u5f0f\u4e8c\uff0c\u901a\u8fc7\u56fe\u7247base64\u4f20\u53c2\uff08\u8bfb\u53d6\u672c\u5730\u7684\u56fe\u7247\u6587\u4ef6\uff0c\u5e76\u8f6c\u6210base64\uff09\n * *\/ \nconst data = fs.readFileSync(path.join(__dirname, 'pic.png'));\nconst base64Image = data.toString('base64');\nconst dataUrl = `data:image\/png;base64,${base64Image}`;\n\nconst params = {\n    &quot;ImageBase64&quot;: dataUrl\n}\n\n\/**\n * \u901a\u8fc7client\u5bf9\u8c61\u8c03\u7528\u60f3\u8981\u8bbf\u95ee\u7684\u63a5\u53e3\uff08Action\uff09\uff0c\u9700\u8981\u4f20\u5165\u8bf7\u6c42\u5bf9\u8c61\uff08Params\uff09\u4ee5\u53ca\u54cd\u5e94\u56de\u8c03\u51fd\u6570\n * \u5373\uff1aclient.Action(Params).then(res =&gt; console.log(res), err =&gt; console.error(err))\n * Action \u6709\u591a\u91cd\u7c7b\u578b GeneralBasicOCR\u901a\u7528\u8bc6\u522b  IDCardOCR\u8eab\u4efd\u8bc1\u8bc6\u522b  DriverLicenseOCR\u8bc6\u522b\u7b49\n * *\/ \n\nclient.GeneralBasicOCR(params).then(\n    (data) =&gt; {\n        console.log(data) \/\/ \u62ff\u5230\u8bc6\u522b\u540e\u7684\u6570\u636e\n    },\n    (err) =&gt; {\n        console.error(&quot;error&quot;, err)\n    }\n)<\/code><\/pre>\n<h2>\u6ce8\u610f\u4e8b\u9879<\/h2>\n<h3><code>secretId<\/code> \u548c <code>secretKey<\/code><\/h3>\n<ul>\n<li><code>secretId<\/code> \u548c <code>secretKey<\/code> \u5728 \u63a7\u5236\u53f0\u83b7\u53d6 <code>https:\/\/console.cloud.tencent.com\/cam\/capi<\/code><\/li>\n<li>\u5982\u4e0b\u56fe\u793a<\/li>\n<\/ul>\n<p><img decoding=\"async\" width=\"723\" height=\"397\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdhb7h\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><strong>\u5b8c\u6574github\u4ee3\u7801\uff1a<\/strong>  <a href=\"https:\/\/link.segmentfault.com\/?enc=MSDc3G5YUY4IZoEn8EExng%3D%3D.RWc5X0PuIkgE6zjQ9DE3ZeGLBpg2VXK3a4HzAUV9AY9C7vLrNuDxV%2BZtAxJnFud%2B\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/github.com\/shuirongshuifu\/tx-ocr<\/a><\/p>\n<p>\u817e\u8baf\u4e91\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=WcLxm9K4BxIV6jC5u92ynA%3D%3D.guI%2BJ7LVjFDIlyhHR5MaFwRVvFJ6S8ZZ7TYOp8oL3kYvkDXzszvZ2XYGkcMYWS26MXf2ajLqaKf6NtfMyx10nQ%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/cloud.tencent.com\/document\/product\/866\/35945<\/a><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000046004814\">https:\/\/segmentfault.com\/a\/1190000046004814<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42\u63cf\u8ff0 \u6700\u8fd1\u6709\u4e00\u4e2a\u56fe\u7247\u8bc6\u522b\u63d0\u53d6\u6587\u5b57\u7684\u9700\u6c42 \u672c\u6765\u60f3\u4f7f\u7528tesseract.js\u5199 \u540e\u6765\u53d1\u73b0\u8bc6\u522b\u7387\u8fd8\u662f\u4e0d\u592a\u591f\u7528  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020599","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020599","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020599"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020599\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}