{"id":812,"date":"2021-12-12T14:02:21","date_gmt":"2021-12-12T05:02:21","guid":{"rendered":"https:\/\/rfsec.ddns.net\/db\/?p=812"},"modified":"2021-12-18T13:51:40","modified_gmt":"2021-12-18T04:51:40","slug":"ocr%e3%82%92%e3%83%9e%e3%83%ab%e3%83%81%e3%83%97%e3%83%ad%e3%82%bb%e3%82%b9%e3%81%a7%e5%87%a6%e7%90%86","status":"publish","type":"post","link":"https:\/\/rfsec.ddns.net\/db\/?p=812","title":{"rendered":"OCR\u3092\u30de\u30eb\u30c1\u30d7\u30ed\u30bb\u30b9\u3067\u51e6\u7406"},"content":{"rendered":"\n<p>\u53c2\u8003\u306b\u3057\u305f\u30b5\u30a4\u30c8<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/ja\/3\/library\/multiprocessing.html\" data-type=\"URL\" data-id=\"https:\/\/docs.python.org\/ja\/3\/library\/multiprocessing.html\" target=\"_blank\">multiprocessing &#8212; \u30d7\u30ed\u30bb\u30b9\u30d9\u30fc\u30b9\u306e\u4e26\u5217\u51e6\u7406<\/a>\u3000\u3092\u53c2\u8003\u306b\u8a66\u3059<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\" data-line=\"\u3000\"><code>from multiprocessing import Pool\n\ndef f(x):\n    return x*x\n\nif __name__ == &#39;__main__&#39;:\n    with Pool(5) as p:\n        print(p.map(f, [1, 2, 3]))<\/code><\/pre><\/div>\n\n\n\n<p>\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3044\u308bOCR\u51e6\u7406\u306e\u30b3\u30fc\u30c9\u3092\u629c\u304d\u3060\u3057\u3066\u95a2\u6570\u5316\u3002\u4e00\u6587\u5b57\u306e\u753b\u50cf\u3092\u5165\u529b(peace)\u3068\u3057\u3066\u3001\u6587\u5b57\u8a8d\u8b58\u3092\u884c\u3044\u3001\u7d50\u679c\u306e\u6570\u5b57\u3092\u8fd4\u3059\u3002\u9ad8\u901f\u5316\u306e\u305f\u3081\u306b\u3001\u4e8b\u524d\u306b\u6570\u5b57\u304c\u5165\u3063\u3066\u3044\u306a\u3044\u3068\u601d\u308f\u308c\u308b\u753b\u50cf\u306b\u3064\u3044\u3066\u306f\u3001OCR\u305b\u305a\u306b\u3001\u30bc\u30ed\u3092\u8fd4\u3059\u3002\u307e\u305f\u3001OCR\u306e\u7d50\u679c\u3001\u6570\u5b57\u4ee5\u5916\u3068\u3057\u3066\u8a8d\u8b58\u3057\u305f\u5834\u5408\u3082\u3001\u30bc\u30ed\u3092\u8fd4\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>def ocr(peace):\n    global p_max\n# \u753b\u50cf\u30a4\u30e1\u30fc\u30b8\u306e\u7dcf\u548c\u304c\u4e8b\u524d\u306b\u8a08\u7b97\u3057\u305fp_max\u3088\u308a\u5c0f\u3055\u3044\u5834\u5408\u306bOCR\u3092\u547c\u3073\u51fa\u3059\n    if np.array(peace).sum()&lt;p_max: \n        conf=&#39;-l eng --psm 6  outputbase digits&#39;\n        txt=pytesseract.image_to_string(peace, config=conf)\n        txt=remove_control_characters(txt)\n        if txt.isdigit():\n            ret=int(txt)\n        else:\n            ret=0\n    else:\n        ret=0\n    return ret<\/code><\/pre><\/div>\n\n\n\n<p><strong>multiprocess\u5c0e\u5165\u524d\u306e\u30b3\u30fc\u30c9<\/strong>\u3002<\/p>\n\n\n\n<p>\u753b\u50cf81\u500b\uff08=9&#215;9)\u3092for \u30eb\u30fc\u30d7\u3067\u4e00\u679a\u3065\u3064OCR\u3092\u5b9f\u884c\u3057\u3066\u3044\u305f\u3002peaces\u306f\u753b\u50cf81\u500b\u306e\u30c7\u30fc\u30bf\u3002peace\u306f\u753b\u50cf1\u500b\u306e\u30c7\u30fc\u30bf<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>my_bar = st.progress(0) # \u6642\u9593\u306e\u7d4c\u904e\u304c\u308f\u304b\u308b\u3088\u3046\u306b\u30d7\u30ed\u30b0\u30ec\u30b9\u30d0\u30fc\u3092\u8a2d\u5b9a\nfor peace in peaces:\n        t = p_size[n]\n        if t&lt;p_max:\n            txt=pytesseract.image_to_string(peace, config=conf)\n            txt=remove_control_characters(txt)\n            try:\n                 ans=int(txt)\n            except:\n                 ans=0\n            \u3000\u3000\u3000st.write(&#39;Error at:&#39;,n,&#39;(&#39;,txt,&#39;)&#39;)\n            else:\n                 ans=0\n            row.append(ans)\n            my_bar.progress(int(100*n\/80))\n            n=n+1\n\nrow2=np.array(row).reshape(-1,9).tolist() #\u3000\u7d50\u679c\u3092 9x9\u306e\u5f62\u306b\nst.success(row2)<\/code><\/pre><\/div>\n\n\n\n<p> <strong>multiprocess\u5c0e\u5165\u5f8c\u306e\u30b3\u30fc\u30c9<\/strong>\u3002 <\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>with Pool(int(CORE)) as p: # CORE\u306f\u30bb\u30ec\u30af\u30bf\u30fc\u3067\u9078\u3093\u3060\u6570 1,2,4,8,10,12,16,32\n     ans=(p.map(ocr, peaces))\n\nrow.append(ans)\nrow2=np.array(row).reshape(-1,9).tolist()\nst.success(row2)<\/code><\/pre><\/div>\n\n\n\n<p><strong>\u7d50\u679c\u3000Pi4 Ubuntu20.04<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ uname -a\nLinux ubuntu 5.4.0-1047-raspi #52-Ubuntu SMP PREEMPT Wed Nov 24 08:16:38 UTC 2021 aarch64 aarch64 aarch64 GNU\/Linux\n------------------------------\nPool\u3000\u7d4c\u904e\u6642\u9593\n1\t\u3000\u300017.721517086029053\n2\t\u3000\u300012.919192552566528\n4\t\u3000\u300012.035958051681519\n8\t\u3000\u300010.886781454086304\n12\t\u300010.22145414352417\n16\t\u300010.279670715332031\n32\t\u300011.4353609085083<\/code><\/pre><\/div>\n\n\n\n<p><strong>rock pi(6 core)<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ uname -a\nLinux rock 4.4.154-110-rockchip-gcef30e88a9f5 #1 SMP Mon Jun 22 07:37:10 UTC 2020 aarch64 aarch64 aarch64 GNU\/Linux\n------------------------------\nPool\u3000\u7d4c\u904e\u6642\u9593\n1\t\u3000\u300010.592926979064941\n2\t\u3000\u30007.96256422996521\n4\t\u3000\u30005.769669532775879\n8\t\u3000\u30005.157710552215576\n12\t\u30005.265762567520142\n16\t\u30005.468385457992554\n32\t\u30006.696927785873413<\/code><\/pre><\/div>\n\n\n\n<p><strong>i7-10700K\/Windows11\/WSL2(8 core 16 thread)<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>$ uname -a\nLinux DESKTOP-P8UNEDG 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64 x86_64 x86_64 GNU\/Linux\n------------------------------\nPool\u3000\u7d4c\u904e\u6642\u9593\n1\t\u3000\u30001.669569969177246\n2\t\u3000\u30000.8932185173034668\n4\t\u3000\u30000.5116889476776123\n8\t\u3000\u30000.4094092845916748\n12\t\u30000.35788488388061523\n16\t\u30000.4156327247619629\n32\t\u30000.38041210174560547\n\n----VirtualBOX\n1: 2.208763360977173\n2: 3.9075162410736084\n4: 3.83050274848938\n\n---WSL2 windows11 \u518d\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5f8c\n1: 1.7535254955291748\n2: 0.9307124614715576\n4: 0.5294575691223145<\/code><\/pre><\/div>\n\n\n\n<p><strong>i7-8750H <strong>Windows10\/WSL2(<\/strong> (6 core 12 thread) <\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>Linux DESKTOP-NI63ODB 5.10.60.1-microsoWindows11\/WSL2(ft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64 x86_64 x86_64 GNU\/Linux\n-----------------------------------\n1: 4.477121353149414\n2: 2.522892475128174\n4: 1.4394028186798096\n8: 1.1422605514526367<\/code><\/pre><\/div>\n\n\n\n<p><strong>Core(TM) i7-3770\/WSL2(4 core 8 thread)<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>Linux mars-PC 4.4.0-19041-Microsoft #1237-Microsoft Sat Sep 11 14:32:00 PST 2021 x86_64 x86_64 x86_64 GNU\/Linux\n----------------------------------\n1: 10.84971809387207\n2: 6.165481805801392\n4: 4.313432216644287\n8: 4.449507713317871<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003\u306b\u3057\u305f\u30b5\u30a4\u30c8 multiprocessing &#8212; \u30d7\u30ed\u30bb\u30b9\u30d9\u30fc\u30b9\u306e\u4e26\u5217\u51e6\u7406\u3000\u3092\u53c2\u8003\u306b\u8a66\u3059 \u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3044\u308bOCR\u51e6\u7406\u306e\u30b3\u30fc\u30c9\u3092\u629c\u304d\u3060\u3057\u3066\u95a2\u6570\u5316\u3002\u4e00\u6587\u5b57\u306e\u753b\u50cf\u3092\u5165\u529b(peace)\u3068\u3057\u3066\u3001\u6587\u5b57\u8a8d\u8b58\u3092\u884c\u3044\u3001\u7d50 [&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":[1],"tags":[],"class_list":["post-812","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"featured_image_src":null,"author_info":{"display_name":"mars","author_link":"https:\/\/rfsec.ddns.net\/db\/?author=1"},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=812"}],"version-history":[{"count":7,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/812\/revisions"}],"predecessor-version":[{"id":838,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/812\/revisions\/838"}],"wp:attachment":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}