支持本地视频测试
This commit is contained in:
z66
2025-12-23 17:59:18 +08:00
parent ae9d252255
commit 1a135cdda7
9 changed files with 301 additions and 14 deletions
+15 -1
View File
@@ -1,7 +1,9 @@
# app.py
import streamlit as st
import cv2
from datetime import datetime
from fish_tracker import FishTracker
from history_manager import FishHistoryManager
def main():
@@ -11,12 +13,16 @@ def main():
# 初始化模型(只加载一次)
if 'tracker' not in st.session_state:
st.session_state.tracker = FishTracker()
if 'history' not in st.session_state:
st.session_state.history = FishHistoryManager()
tracker = st.session_state.tracker
history = st.session_state.history
# 视频显示区域
frame_placeholder = st.empty()
alert_placeholder = st.empty()
report_placeholder = st.empty()
# 打开摄像头
cap = cv2.VideoCapture(0)
@@ -35,7 +41,11 @@ def main():
break
# 处理帧
output_frame, alerts = tracker.process_frame(frame)
output_frame, alerts, track_stats = tracker.process_frame(frame)
now = datetime.now()
history.update(track_stats, now)
report_path = history.maybe_generate_report(now)
# 转为 RGB 显示(Streamlit 要求)
rgb_frame = cv2.cvtColor(output_frame, cv2.COLOR_BGR2RGB)
@@ -48,6 +58,10 @@ def main():
else:
alert_placeholder.empty()
# 显示报告生成信息
if report_path:
report_placeholder.success(f"✅ 今日报告已生成:{report_path}")
except KeyboardInterrupt:
pass
finally: