{"id":770,"date":"2021-12-02T15:20:23","date_gmt":"2021-12-02T06:20:23","guid":{"rendered":"https:\/\/rfsec.ddns.net\/db\/?p=770"},"modified":"2021-12-02T20:25:15","modified_gmt":"2021-12-02T11:25:15","slug":"%e6%95%b0%e7%8b%ac%e3%81%ae%e5%95%8f%e9%a1%8c%e3%81%8b%e3%82%89%ef%bc%91%e6%96%87%e5%ad%97%e3%82%92%e5%88%87%e3%82%8a%e5%87%ba%e3%81%99%e3%80%82","status":"publish","type":"post","link":"https:\/\/rfsec.ddns.net\/db\/?p=770","title":{"rendered":"\u6570\u72ec\u306e\u554f\u984c\u304b\u3089\uff11\u6587\u5b57\u3065\u3064\u5207\u308a\u51fa\u3057\u3066\u8a8d\u8b58\u3092\u8a66\u307f\u308b"},"content":{"rendered":"\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import cv2\nfrom PIL import Image           # \u753b\u50cf\u51e6\u7406\u30e9\u30a4\u30d6\u30e9\u30ea\nfrom matplotlib import pyplot as plt # \u30c7\u30fc\u30bf\u30d7\u30ed\u30c3\u30c8\u7528\u30e9\u30a4\u30d6\u30e9\u30ea\nimport numpy as np              # \u30c7\u30fc\u30bf\u5206\u6790\u7528\u30e9\u30a4\u30d6\u30e9\u30ea\nimport os                       # os \u306e\u60c5\u5831\u3092\u6271\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\nimport pytesseract              # tesseract \u306e python \u7528\u30e9\u30a4\u30d6\u30e9\u30ea\nimport unicodedata\nfrom pytesseract import Output\n\ndef remove_control_characters(s):\n    return &quot;&quot;.join(ch for ch in s if unicodedata.category(ch)[0]!=&quot;C&quot;)\n\n# \u4ee5\u4e0b\u306e\u5024\u306f\u6c4e\u7528\u6027\u30ca\u30b7\u3002\ndx,dy=52,52\nox,oy=10,10\ntD,tB=38,38\npz=&#39;100006800500000030000720000942003706703004100805009000476392581251087360098165420&#39; \n\nimg = cv2.imread(&quot;\/home\/mars\/TEST50-2a.png&quot;)\n#cv2.imshow(&#39;sudoku&#39;,img)\nok,ng=0,0\nfor x in range(9):\n    for y in range(9):\n        t=x*dx + ox\n        b=y*dy+oy\n        tt=t-2\n        bb=b-2\n        #cv2.rectangle(img,(t,b),(t+tD,b+tB),(0,0,255))\n        sliced=img[tt:t+tD,bb:b+tB]\n        #sliced=cv2.threshold(tmp, 150, 255, cv2.THRESH_BINARY)\n        im_list = np.array(sliced)\n        img_rgb = cv2.cvtColor(im_list, cv2.COLOR_BGR2RGB)\n        pos=str(x)+&#39;,&#39;+str(y)\n        #txt = pytesseract.image_to_string(im_list,lang=&quot;jpn&quot;,config=&#39;--psm 10 outputbase digits&#39;)\n        txt=pytesseract.image_to_string(sliced, config=&#39;-l eng  --psm 6 outputbase digits&#39;)\n        junk=remove_control_characters(txt)\n        #print(x,y,len(junk))\n        ans=pz[x*9+y]\n        if  len(junk)&lt;1:\n            if ans==&#39;0&#39;:\n                ok=ok+1\n                junk=&#39;O&#39;\n            else:\n                junk=&#39;X&#39;\n                ng=ng+1\n        else:\n            if ans==junk:\n                ok=ok+1\n            else:\n                junk=&#39;X&#39;\n                ng=ng+1\n\n        out=out+junk+&#39;(&#39;+ans+&#39;)&#39;\n        #cv2.imshow(&#39;slice:&#39;+pos,sliced)\n    print(str(x)+&#39;---&gt;&#39;,out,&#39;  correct=&#39;,ok,&#39;  in-correct=&#39;,ng)\n    out=&#39;&#39;\n#cv2.imshow(&#39;slice&#39;,img)\nprint(&#39;Success rate:&#39;,round(100*ok\/81,2),&#39;[%]&#39;)\n\nprint(&#39;done&#39;)<\/code><\/pre><\/div>\n\n\n\n<p><strong>\u6b63\u7b54\u7387\uff1a\uff18\uff16\uff05<\/strong><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>0---&gt; 1(1)O(0)O(0)O(0)O(0)6(6)8(8)O(0)O(0)   correct= 9   in-correct= 0\n1---&gt; X(5)O(0)O(0)O(0)X(0)O(0)O(0)3(3)O(0)   correct= 16   in-correct= 2\n2---&gt; O(0)O(0)O(0)X(7)2(2)O(0)O(0)O(0)O(0)   correct= 24   in-correct= 3\n3---&gt; 9(9)4(4)2(2)O(0)O(0)3(3)X(7)O(0)6(6)   correct= 32   in-correct= 4\n4---&gt; 7(7)O(0)3(3)O(0)O(0)4(4)X(1)O(0)O(0)   correct= 40   in-correct= 5\n5---&gt; 8(8)X(0)5(5)O(0)X(0)9(9)O(0)O(0)O(0)   correct= 47   in-correct= 7\n6---&gt; 4(4)7(7)6(6)3(3)9(9)2(2)5(5)8(8)X(1)   correct= 55   in-correct= 8\n7---&gt; X(2)5(5)X(1)O(0)8(8)7(7)3(3)6(6)O(0)   correct= 62   in-correct= 10\n8---&gt; O(0)9(9)8(8)X(1)6(6)5(5)4(4)2(2)O(0)   correct= 70   in-correct= 11\nSuccess rate: 86.42 [%]\ndone<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"474\" height=\"469\" src=\"https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/12\/TEST50-2a.png\" alt=\"\" class=\"wp-image-771\" srcset=\"https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/12\/TEST50-2a.png 474w, https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/12\/TEST50-2a-300x297.png 300w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u6b63\u7b54\u7387\uff1a\uff18\uff16\uff05<\/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-770","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\/770","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=770"}],"version-history":[{"count":4,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/770\/revisions"}],"predecessor-version":[{"id":778,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/770\/revisions\/778"}],"wp:attachment":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}