{"id":714,"date":"2021-11-21T10:02:55","date_gmt":"2021-11-21T01:02:55","guid":{"rendered":"https:\/\/rfsec.ddns.net\/db\/?p=714"},"modified":"2021-11-21T10:06:54","modified_gmt":"2021-11-21T01:06:54","slug":"streamlit%e3%81%a7%e6%b5%81%e6%98%9f%e8%a6%b3%e6%b8%ac%e3%83%87%e3%83%bc%e3%82%bf%e3%82%92%e8%a1%a8%e7%a4%ba","status":"publish","type":"post","link":"https:\/\/rfsec.ddns.net\/db\/?p=714","title":{"rendered":"streamlit\u3067\u6d41\u661f\u89b3\u6e2c\u30c7\u30fc\u30bf\u3092\u8868\u793a"},"content":{"rendered":"\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"762\" height=\"1024\" src=\"https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/11\/streamlit3png-762x1024.png\" alt=\"\" class=\"wp-image-715\" srcset=\"https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/11\/streamlit3png-762x1024.png 762w, https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/11\/streamlit3png-223x300.png 223w, https:\/\/rfsec.ddns.net\/db\/wp-content\/uploads\/2021\/11\/streamlit3png.png 1124w\" sizes=\"auto, (max-width: 762px) 100vw, 762px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code># -*- coding: utf-8 -*-\n\nimport streamlit as st\nimport time\nimport datetime\nimport os\nimport glob\nimport cv2\nimport re\nimport numpy as np\nfrom PIL import Image\nfrom datetime import datetime, date, time\n\nPATH=&#39;\/home\/metro\/\/DATA\/&#39;\n\ndef comp_b2(A,B):\n# \u6bd4\u8f03\u660e\u5408\u6210\u51e6\u7406\n# https:\/\/nyanpyou.hatenablog.com\/entry\/2020\/03\/20\/132937\n#\n    gray_img1 = cv2.cvtColor(A, cv2.COLOR_BGR2GRAY)\n    gray_img2 = cv2.cvtColor(B, cv2.COLOR_BGR2GRAY)\n#\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u306e\u6bd4\u8f03\u3067\u4f5c\u6210\u3057\u305fimg1\u7528\u306e\u30de\u30b9\u30af(img1\u306e\u65b9\u304c\u660e\u308b\u3044\u753b\u7d20\u3092\u793a\u3059)\n    mask_img1 = np.where(gray_img1&gt;gray_img2, 255, 0).astype(np.uint8)\n#img2\u7528\u306e\u30de\u30b9\u30af(0\u3068255\u3092\u5165\u308c\u66ff\u3048)(img2\u306e\u65b9\u304c\u660e\u308b\u3044\u753b\u7d20\u3092\u793a\u3059)\n    mask_img2 = np.where(mask_img1==255, 0, 255).astype(np.uint8)\n\n#\u4f5c\u6210\u3057\u305f\u30de\u30b9\u30af\u3092\u4f7f\u3063\u3066\u5143\u753b\u50cf\u304b\u3089\u629c\u304d\u51fa\u3057\n    masked_img1 = cv2.bitwise_and(A, A, mask=mask_img1)\n    masked_img2 = cv2.bitwise_and(B, B, mask=mask_img2)\n\n    img3 = masked_img1 + masked_img2\n    return img3\n\ndef disp(device):\n        n=0\n        cap = cv2.VideoCapture(device)\n        W = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))\n        H = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))\n        W2=int(W\/2)\n        H2=int(H\/2)\n        image_loc = st.empty()\n        prev=None\n        while cap.isOpened:\n            ret, img = cap.read()\n            if ret:\n                if W==1920:\n                    img=cv2.resize(img, dsize=(W2, H2))\n                #time.sleep(0.01)\n                if prev is None:\n                    prev = img.copy()\n                else:\n                    E = comp_b2(prev,img)\n                    prev = E\n                img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))\n                image_loc.image(img)\n            else:\n                break\n\n        cap.release()\n        image_loc = st.empty()\n        img = Image.fromarray(cv2.cvtColor(prev, cv2.COLOR_BGR2RGB))\n        image_loc.image(img)\n    #st.button(&#39;Replay&#39;)\n\ndef main():\n    st.header(&quot;\u6d41\u661f\u89b3\u6e2c\u30c7\u30fc\u30bf\u306e\u8868\u793a&quot;)\n    col1, col2, col3 = st.columns([1,1,3])\n    with col1:\n        date=st.date_input(&#39;DATE&#39;)\n    path=PATH+date.strftime(&quot;%Y%m%d&quot;)\n    selected=[]\n    f_name=[]\n    TL=[]\n    if os.path.exists(path):\n        files=glob.glob(path+&#39;\/*avi&#39;)\n        # time filter : m[4] is time field.\n        if files is not(None):\n            for opt in files:\n                m=re.split(&#39;[_.]&#39;,opt)\n                TL.append(int(int(m[4])\/10000))\n            TL=list(set(TL))                        # sort\u3057\u3066\u91cd\u8907\u3092\u524a\u9664\n            # \u51e6\u7406\u5bfe\u8c61\u306e\u6642\u9593\u5e2f\u3092\u9078\u629e\u3059\u308b\u30bb\u30ec\u30af\u30c8BOX\u306e\u8868\u793a\n            with col2:\n                selected_item = st.selectbox(&#39;TIME&#39;,TL)\n            selT = int(selected_item)\n            for opt in files:\n                m=re.split(&#39;[_.]&#39;,opt)\n                if len(m)&gt;=4:\n                    t = int(int(m[4])\/10000)\n            #if not(t&gt;60000 and t&lt;180000):\n                    if t==selT:\n                        selected.append(opt)\n\n            if selected is not(None):\n                for name in selected:\n                    f_name.append(name.rsplit(&#39;\/&#39;,1)[1])\n                with col3:\n                    option = st.selectbox(&#39;FILE to DISPLAY&#39;,f_name)\n            if option is not(None):\n                disp(path+&#39;\/&#39;+option)\n    else:\n        st.write(&#39;No data exists!&#39;)\n\nif __name__ == &#39;__main__&#39;:\n    main()<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"","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":[2,7],"tags":[],"class_list":["post-714","post","type-post","status-publish","format-standard","hentry","category-camera","category-astronomy"],"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\/714","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=714"}],"version-history":[{"count":2,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/714\/revisions"}],"predecessor-version":[{"id":717,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/714\/revisions\/717"}],"wp:attachment":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}