{"id":779,"date":"2021-12-03T16:03:35","date_gmt":"2021-12-03T07:03:35","guid":{"rendered":"https:\/\/rfsec.ddns.net\/db\/?p=779"},"modified":"2021-12-03T16:04:48","modified_gmt":"2021-12-03T07:04:48","slug":"%e6%96%87%e5%ad%97%e8%aa%8d%e8%ad%98%e3%81%ae%e6%9d%a1%e4%bb%b6%e8%a8%ad%e5%ae%9a%e3%82%92%e3%82%a4%e3%83%b3%e3%82%bf%e3%83%a9%e3%82%af%e3%83%86%e3%82%a3%e3%83%96%e3%81%ab","status":"publish","type":"post","link":"https:\/\/rfsec.ddns.net\/db\/?p=779","title":{"rendered":"\u6587\u5b57\u8a8d\u8b58\u306e\u6761\u4ef6\u8a2d\u5b9a\u3092\u30a4\u30f3\u30bf\u30e9\u30af\u30c6\u30a3\u30d6\u306b"},"content":{"rendered":"\n<p>streamlit\u3092\u5229\u7528\u3057\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u9078\u629e\u3001\u8a00\u8a9e\u8a2d\u5b9a\u3001\u67a0\u7dda\u524a\u9664\u306eON\/OFF\u3001\uff12\u5024\u5316\u3068\u7dda\u6d88\u53bb\u306e\u95be\u5024\u3092\u30a4\u30f3\u30bf\u30e9\u30af\u30c6\u30a3\u30d6\u306b\u8a2d\u5b9a\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u8868\u793a\u3059\u308b\u753b\u50cf\u306f\u3001\u5143\u753b\u50cf\u3068\uff12\u5024\u5316\u3057\u305f\u753b\u50cf\u3002\u7dda\u524a\u9664\u3092\u9078\u629e\u3059\u308b\u3068\u3001\u524a\u9664\u3059\u308b\u7dda\u3068\u5143\u753b\u50cf\u304b\u3089\u7dda\u3092\u524a\u9664\u3057\u305f\u753b\u50cf\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>OCR\u5b9f\u884c\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3068\u3001pytesseract\u3067\u6587\u5b57\u306e\u8a8d\u8b58\u3092\u884c\u3044\u307e\u3059\u3002\u6587\u5b57\u8a8d\u8b58\u306e\u51e6\u7406\u306b\u306f\u6642\u9593\u304c\u304b\u304b\u308b\u306e\u3067\u3001\u95be\u5024\u306e\u8a2d\u5b9a\u4e2d\u306f\u30c1\u30a7\u30c3\u30af\u3057\u306a\u3044\u307b\u3046\u304c\u826f\u3044\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"690\" height=\"591\" src=\"https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/12\/ocr.png\" alt=\"\" class=\"wp-image-780\" srcset=\"https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/12\/ocr.png 690w, https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/12\/ocr-300x257.png 300w, https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/12\/ocr-624x534.png 624w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u51e6\u7406\u7d50\u679c\u306e\u4e00\u4f8b<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"405\" src=\"https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/12\/ocr2.png\" alt=\"\" class=\"wp-image-781\" srcset=\"https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/12\/ocr2.png 693w, https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/12\/ocr2-300x175.png 300w, https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/12\/ocr2-624x365.png 624w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">python\u306e\u30b3\u30fc\u30c9<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import streamlit as st\nimport 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 glob\n\nfiles=glob.glob(&quot;\/home\/mars\/streamlit\/*png&quot;)\n#print(files)\ndef main():\n    st.title(&#39;\u6587\u5b57\u8a8d\u8b58\u306e\u5b9f\u9a13&#39;)\n    col1, col2 ,col3, col4 = st.columns([3,1,1,1])\n\n    with col1:\n        TGT = st.selectbox(&quot;\u30d5\u30a1\u30a4\u30eb\u306e\u9078\u629e&quot;,files)\n    th2 = st.slider(label=&#39;\uff12\u5024\u5316\u306e\u95be\u5024&#39;,min_value=0, max_value=255, value=100)\n    th1 = st.slider(label=&#39;\u7dda\u6d88\u53bb\u306e\u95be\u5024&#39;,min_value=0, max_value=255, value=100)\n    with col2:\n        LNG =  st.selectbox(&quot;\u8a00\u8a9e\u9078\u629e&quot;,[&#39;jpn&#39;,&#39;eng&#39;,&#39;number&#39;])\n    with col3:\n        KEI = st.checkbox(&#39;\u7dda\u524a\u9664&#39;)\n    with col4:\n        OCR = st.checkbox(&#39;OCR\u5b9f\u884c&#39;)\n\n    img = cv2.imread(TGT)\n    #with pict[0]:\n    st.write(&#39;\u753b\u50cf&#39;,TGT,img.shape)\n    #img = cv2.cvtColor(img, cv2.COLOR_RGBA2RGB)\n    ret, img_thresh = cv2.threshold(img, th2, 255, cv2.THRESH_BINARY)\n    im_h = cv2.hconcat([img, img_thresh])\n    st.image(im_h, caption=&#39;\u5143\u753b\u50cf&#39;)\n    if KEI:\n        img2 = img.copy()\n        img3 = img.copy()\n        gray = cv2.cvtColor(img_thresh, cv2.COLOR_BGR2GRAY)\n        gray_list = np.array(gray)\n        #img2.image(gray_list, caption=&#39;GRAY&#39;,use_column_width=True)\n        gray2 = cv2.bitwise_not(gray)\n        gray2_list = np.array(gray2)\n        lines = cv2.HoughLinesP(gray2, rho=1, theta=np.pi\/360, threshold=th1, minLineLength=80, maxLineGap=5)\n\n        for line in lines:\n            x1, y1, x2, y2 = line[0]\n\n            # \u7dd1\u8272\u306e\u7dda\u3092\u5f15\u304f\n            red_lines_img = cv2.line(img2, (x1,y1), (x2,y2), (0,255,0), 3)\n            red_lines_np=np.array( red_lines_img)\n            #cv2.imwrite(&quot;calendar_mod3.png&quot;, red_lines_img)\n\n            # \u7dda\u3092\u6d88\u3059(\u767d\u3067\u7dda\u3092\u5f15\u304f)\n            no_lines_img = cv2.line(img_thresh, (x1,y1), (x2,y2), (255,255,255), 3)\n            no_lines=np.array( no_lines_img)\n        im_h = cv2.hconcat([red_lines_img, no_lines_img])\n        st.image(im_h,caption=&#39;No lines&#39;)\n    else:\n        no_lines=img_thresh\n\n    if OCR:\n        #txt = pytesseract.image_to_string(no_lines, lang=&quot;eng&quot;,config=&#39;--psm 11&#39;)\n        conf=&#39;-l &#39; + LNG + &#39; --psm6&#39;\n        txt=pytesseract.image_to_string(no_lines, config=conf)\n\n        st.write(txt)\n\nif __name__ == &#39;__main__&#39;:\n    main()\n<\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>streamlit\u3092\u5229\u7528\u3057\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u9078\u629e\u3001\u8a00\u8a9e\u8a2d\u5b9a\u3001\u67a0\u7dda\u524a\u9664\u306eON\/OFF\u3001\uff12\u5024\u5316\u3068\u7dda\u6d88\u53bb\u306e\u95be\u5024\u3092\u30a4\u30f3\u30bf\u30e9\u30af\u30c6\u30a3\u30d6\u306b\u8a2d\u5b9a\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002 \u8868\u793a\u3059\u308b\u753b\u50cf\u306f\u3001\u5143\u753b\u50cf\u3068\uff12\u5024\u5316\u3057\u305f\u753b\u50cf\u3002\u7dda\u524a\u9664\u3092\u9078\u629e\u3059\u308b\u3068\u3001\u524a\u9664\u3059\u308b [&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-779","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\/779","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=779"}],"version-history":[{"count":2,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/779\/revisions"}],"predecessor-version":[{"id":783,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/779\/revisions\/783"}],"wp:attachment":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}