{"id":10020668,"date":"2025-03-08T12:53:49","date_gmt":"2025-03-08T04:53:49","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020668"},"modified":"2025-03-08T12:53:49","modified_gmt":"2025-03-08T04:53:49","slug":"%e6%9c%ac%e5%9c%b0%e4%bd%bf%e7%94%a8paddleocr%e8%bf%9b%e8%a1%8c%e5%9b%be%e7%89%87%e8%af%86%e5%88%ab%e8%8e%b7%e5%be%97%e6%96%87%e5%ad%97%ef%bc%88%e8%bf%94%e5%9b%9ejson%ef%bc%89","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020668","title":{"rendered":"\u672c\u5730\u4f7f\u7528PaddleOCR\u8fdb\u884c\u56fe\u7247\u8bc6\u522b\u83b7\u5f97\u6587\u5b57\uff08\u8fd4\u56deJSON\uff09"},"content":{"rendered":"<h2>\u4f18\u70b9<\/h2>\n<p>\u2705 \u8bc6\u522b\u7387\u9ad8\uff0c\u652f\u6301\u7e41\u7b80\u4e2d\u6587\u548c\u624b\u5199\u8bc6\u522b<br \/>\u2705 \u652f\u6301\u89d2\u5ea6\u68c0\u6d4b\uff0c\u907f\u514d\u6587\u5b57\u65b9\u5411\u5f71\u54cd\u8bc6\u522b\u6548\u679c<br \/>\u2705 \u8fd8\u80fd\u8bc6\u522b\u8868\u683c\u3001\u7968\u636e\u7b49\u590d\u6742\u573a\u666f<\/p>\n<h2>\u65b9\u6cd5<\/h2>\n<pre><code>pip install paddleocr\npip install paddlepaddle<\/code><\/pre>\n<p>\uff08\u5982\u679c\u4f60\u6709 GPU\uff0c\u53ef\u4ee5\u5b89\u88c5 paddlepaddle-gpu \u4ee5\u52a0\u901f\u8bc6\u522b\uff09<\/p>\n<h2>\u4f7f\u7528\u793a\u4f8b<\/h2>\n<pre><code>from paddleocr import PaddleOCR\n\nocr = PaddleOCR(use_angle_cls=True, lang=&quot;ch&quot;)  # \u4f7f\u7528\u4e2d\u6587\u6a21\u578b\uff0c\u652f\u6301\u89d2\u5ea6\u6821\u6b63\nresult = ocr.ocr(&quot;example.png&quot;, cls=True)  # \u8bc6\u522b\u56fe\u50cf\nfor line in result:\n    print(line)  # \u8f93\u51fa\u8bc6\u522b\u7ed3\u679c<\/code><\/pre>\n<p><strong>\u6307\u5b9aGPU\u52a0\u901f<\/strong><\/p>\n<pre><code>from paddleocr import PaddleOCR\n\n# \u521d\u59cb\u5316 OCR\uff0c\u5f3a\u5236\u4f7f\u7528 GPU\uff08\u5982\u679c\u6709\u591a\u5f20 GPU\uff0c\u53ef\u4ee5\u8bbe\u7f6e use_gpu=0, 1, 2...\uff09\nocr = PaddleOCR(use_angle_cls=True, lang=&quot;ch&quot;, use_gpu=0) \n\n# \u8bfb\u53d6\u56fe\u7247\u5e76\u8bc6\u522b\nresult = ocr.ocr(&quot;example.png&quot;, cls=True)\n\n# \u8f93\u51fa\u8bc6\u522b\u7ed3\u679c\nfor line in result:\n    print(line)<\/code><\/pre>\n<p><strong>\u8fd4\u56deJSON<\/strong><\/p>\n<pre><code>import json\nfrom paddleocr import PaddleOCR\n\n# \u521d\u59cb\u5316 OCR\uff0c\u4f7f\u7528 GPU\nocr = PaddleOCR(use_angle_cls=True, lang=&quot;ch&quot;, use_gpu=0)\n\n# \u8bfb\u53d6\u56fe\u7247\u5e76\u8bc6\u522b\nresult = ocr.ocr(&quot;example.png&quot;, cls=True)\n\n# \u5904\u7406\u7ed3\u679c\uff0c\u63d0\u53d6\u6587\u5b57\u4fe1\u606f\noutput_data = []\nfor line in result:\n    for word_info in line:\n        text = word_info[1][0]  # \u83b7\u53d6\u8bc6\u522b\u7684\u6587\u672c\n        confidence = word_info[1][1]  # \u83b7\u53d6\u7f6e\u4fe1\u5ea6\n        output_data.append({&quot;text&quot;: text, &quot;confidence&quot;: confidence})\n\n# \u8f6c\u6362\u4e3a JSON \u683c\u5f0f\njson_output = json.dumps(output_data, ensure_ascii=False, indent=4)\n\n# \u8f93\u51fa JSON \u7ed3\u679c\nprint(json_output)<\/code><\/pre>\n<p><strong>\u8bc6\u522b\u6548\u679c<\/strong><br \/><img loading=\"lazy\" decoding=\"async\" width=\"475\" height=\"847\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdh0Mi\" alt=\"image.png\" title=\"image.png\"><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000046199561\">https:\/\/segmentfault.com\/a\/1190000046199561<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f18\u70b9 \u2705 \u8bc6\u522b\u7387\u9ad8\uff0c\u652f\u6301\u7e41\u7b80\u4e2d\u6587\u548c\u624b\u5199\u8bc6\u522b\u2705 \u652f\u6301\u89d2\u5ea6\u68c0\u6d4b\uff0c\u907f\u514d\u6587\u5b57\u65b9\u5411\u5f71\u54cd\u8bc6\u522b\u6548\u679c\u2705 \u8fd8\u80fd\u8bc6\u522b\u8868\u683c\u3001\u7968\u636e\u7b49\u590d [&hellip;]<\/p>\n","protected":false},"author":8,"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-10020668","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\/10020668","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\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020668"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020668\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}