{"id":1891,"date":"2021-08-19T22:10:27","date_gmt":"2021-08-19T14:10:27","guid":{"rendered":"http:\/\/cnliutz.uicp.io\/?p=1891"},"modified":"2021-08-19T22:39:22","modified_gmt":"2021-08-19T14:39:22","slug":"%e5%9b%be%e7%89%87%e6%96%87%e4%bb%b6%e3%80%81%e6%88%96%e5%89%aa%e5%88%87%e6%9d%bf%e5%86%85%e5%9b%be%e7%89%87-%e6%96%87%e5%ad%97%e8%af%86%e5%88%abocr","status":"publish","type":"post","link":"http:\/\/g1n29wqq.ipyingshe.net:5347\/?p=1891","title":{"rendered":"\u56fe\u7247\u6216\u526a\u5207\u677f\u5185\u56fe\u7247\u6587\u5b57\u8bc6\u522b-OCR"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><li>\u9ed8\u8ba4\u56fe\u7247\u6587\u4ef6\u540d\uff1a001.JPEG\uff1b\u622a\u56fe\u653e\u5165\u526a\u5207\u677f\u5185\uff0c\u56fe\u7247\u4f1a\u81ea\u52a8\u5b58\u50a8\uff0c\u65e0\u9700\u8f93\u5165\u6587\u4ef6\u540d\u3002<\/li><li>Windows\u56fe\u7247\u9ed8\u8ba4\u5b58\u50a8\u4f4d\u7f6e: c:\\users\\liutz(liutz\u662f\u81ea\u5df1\u7684\u7528\u6237\u540d)<\/li><li>\u5b9e\u9a8c\u73af\u5883win10 20h2 + python3.85   vscode<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>import time\nimport os\n# ENV \uff1apython 3.85 +  win10 20H2 \n# \u5b89\u88c5\u5fc5\u8981\u7684\u5e93 pillow\u3001baidu-aip\u3001keyboard\n# pip install keyboard,pillow  -i http:\/\/pypi.douban.com\/simple\n# pip install baidu-aip\n\nimport keyboard\nfrom PIL import  ImageGrab\nfrom PIL import  Image\nfrom aip import AipOcr\n\n# print(os.getcwd())   # \u9ed8\u8ba4\u5de5\u4f5c\u76ee\u5f55 c:\\users\\liutz\n\n\"\"\" \u4f60\u7684 APPID AK SK \uff1a\u4ee5\u4e0b\u5185\u5bb9:ai.baidu.com--\u901a\u7528OCR\u9875\u9762\u7533\u8bf7\"\"\"\nAPP_ID = '21571517'\nAPI_KEY = 'dGgWcprUfQBHKM5UG2CdSzot'\nSECRET_KEY = '3Gqe5MkzUdONgtppDceUutRGdpF7MVkU'\n\nclient = AipOcr(APP_ID, API_KEY, SECRET_KEY)\n\nkeyboard.wait(hotkey=\"f4\")    # \u6309F4\u952e\uff0c\u7a0b\u5e8f\u7ee7\u7eed\u8fd0\u884c\n# keyboard.wait(hotkey=\"ctrl+c\")\ntime.sleep(0.1) \n\n#\u6307\u5b9a\u5c4f\u5e55\u8303\u56f4\u622a\u56fe\n# size = (100,100,1660,800)\n# img = ImageGrab.grab(size)\n# img.save(\"C:\/Users\/liutz\/Documents\/cut.jpg\")\n# img.show()\n\n# \u8bfb\u53d6\u526a\u5207\u677f\u7684\u56fe\u7247\u5185\u5bb9\uff0c\u5982\u679c\u526a\u5207\u677f\u5185\u662f\u6587\u5b57\uff0c\u663e\u793aclipboard is empty.\nim = ImageGrab.grabclipboard() \nif isinstance(im,Image.Image):\n    print(\"Image:size:{} mode:{}\".format(im.size,im.mode))\n    #im.save(\"C:\/Users\/liutz\/Documents\/grab_grabclipboard.jpg\")\n    # im.save('001.jpg')\n    im = im.convert('RGB')  #\u89e3\u51b3\u4f7f\u7528\u5feb\u6377\u952e win+shift+s \u622a\u56fe \u5b58\u50a8\u56fe\u7247\u51fa\u9519\u95ee\u9898\n    im.save(\"001.jpeg\",format='jpeg')\n    im.show()\nelse:\n    print(\"clipboard is empty.\") \n\n\"\"\" \u8bfb\u53d6\u56fe\u7247 \"\"\"\ndef get_file_content(filePath):\n    with open(filePath, 'rb') as fp:\n        return fp.read()\n\nimage = get_file_content('001.jpeg')\n\n#result = client.accurate(image)  #\u9ad8\u7cbe\u6587\u672c\u8bc6\u522b\ntext = client.basicGeneral(image)\n# print(text)\ntexts= text&#91;\"words_result\"]\ntxt = \"\"\nfor text in texts:\n     print(text&#91;\"words\"])           #\u9010\u884c \u8f93\u51fa\u8bc6\u522b\u7ed3\u679c\n    # txt = txt + text&#91;\"words\"]     #\u8bc6\u522b\u7684\u6587\u672c\uff0c\u8fde\u5728\u4e00\u8d77\u8f93\u51fa\nprint(txt)\n\n\n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9ed8\u8ba4\u56fe\u7247\u6587\u4ef6\u540d\uff1a001.JPEG\uff1b\u622a\u56fe\u653e\u5165\u526a\u5207\u677f\u5185\uff0c\u56fe\u7247\u4f1a\u81ea\u52a8\u5b58\u50a8\uff0c\u65e0\u9700\u8f93\u5165\u6587\u4ef6 <span class=\"readmore\"><a href=\"http:\/\/g1n29wqq.ipyingshe.net:5347\/?p=1891\">Continue Reading<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,10],"tags":[],"class_list":["post-1891","post","type-post","status-publish","format-standard","hentry","category-2","category-python"],"_links":{"self":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/1891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1891"}],"version-history":[{"count":5,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/1891\/revisions"}],"predecessor-version":[{"id":1898,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/1891\/revisions\/1898"}],"wp:attachment":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1891"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}