# -*- coding: utf-8 -*-
import streamlit as st
import time
import datetime
import os
import glob
import cv2
import re
import numpy as np
from PIL import Image
from datetime import datetime, date, time
PATH='/home/metro//DATA/'
def comp_b2(A,B):
# 比較明合成処理
# https://nyanpyou.hatenablog.com/entry/2020/03/20/132937
#
gray_img1 = cv2.cvtColor(A, cv2.COLOR_BGR2GRAY)
gray_img2 = cv2.cvtColor(B, cv2.COLOR_BGR2GRAY)
#グレースケールの比較で作成したimg1用のマスク(img1の方が明るい画素を示す)
mask_img1 = np.where(gray_img1>gray_img2, 255, 0).astype(np.uint8)
#img2用のマスク(0と255を入れ替え)(img2の方が明るい画素を示す)
mask_img2 = np.where(mask_img1==255, 0, 255).astype(np.uint8)
#作成したマスクを使って元画像から抜き出し
masked_img1 = cv2.bitwise_and(A, A, mask=mask_img1)
masked_img2 = cv2.bitwise_and(B, B, mask=mask_img2)
img3 = masked_img1 + masked_img2
return img3
def disp(device):
n=0
cap = cv2.VideoCapture(device)
W = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
H = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
W2=int(W/2)
H2=int(H/2)
image_loc = st.empty()
prev=None
while cap.isOpened:
ret, img = cap.read()
if ret:
if W==1920:
img=cv2.resize(img, dsize=(W2, H2))
#time.sleep(0.01)
if prev is None:
prev = img.copy()
else:
E = comp_b2(prev,img)
prev = E
img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
image_loc.image(img)
else:
break
cap.release()
image_loc = st.empty()
img = Image.fromarray(cv2.cvtColor(prev, cv2.COLOR_BGR2RGB))
image_loc.image(img)
#st.button('Replay')
def main():
st.header("流星観測データの表示")
col1, col2, col3 = st.columns([1,1,3])
with col1:
date=st.date_input('DATE')
path=PATH+date.strftime("%Y%m%d")
selected=[]
f_name=[]
TL=[]
if os.path.exists(path):
files=glob.glob(path+'/*avi')
# time filter : m[4] is time field.
if files is not(None):
for opt in files:
m=re.split('[_.]',opt)
TL.append(int(int(m[4])/10000))
TL=list(set(TL)) # sortして重複を削除
# 処理対象の時間帯を選択するセレクトBOXの表示
with col2:
selected_item = st.selectbox('TIME',TL)
selT = int(selected_item)
for opt in files:
m=re.split('[_.]',opt)
if len(m)>=4:
t = int(int(m[4])/10000)
#if not(t>60000 and t<180000):
if t==selT:
selected.append(opt)
if selected is not(None):
for name in selected:
f_name.append(name.rsplit('/',1)[1])
with col3:
option = st.selectbox('FILE to DISPLAY',f_name)
if option is not(None):
disp(path+'/'+option)
else:
st.write('No data exists!')
if __name__ == '__main__':
main()
streamlitで流星観測データを表示
コメントを残す