观赏鱼健康系统v1.0

This commit is contained in:
2025-12-23 09:15:28 +08:00
commit ff6f40c972
6 changed files with 101 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 已忽略包含查询文件的默认文件夹
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="fish_monter" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="fish_monter" project-jdk-type="Python SDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/fish_fish_.iml" filepath="$PROJECT_DIR$/fish_fish_.iml" />
</modules>
</component>
</project>
Generated
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
+58
View File
@@ -0,0 +1,58 @@
# app.py
import streamlit as st
import cv2
from fish_tracker import FishTracker
def main():
st.set_page_config(layout="wide")
st.title("🐟 观赏鱼健康监控系统(笔记本版)")
# 初始化模型(只加载一次)
if 'tracker' not in st.session_state:
st.session_state.tracker = FishTracker()
tracker = st.session_state.tracker
# 视频显示区域
frame_placeholder = st.empty()
alert_placeholder = st.empty()
# 打开摄像头
cap = cv2.VideoCapture(0)
if not cap.isOpened():
st.error("❌ 无法打开摄像头,请检查设备权限。")
return
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
try:
while True:
ret, frame = cap.read()
if not ret:
st.warning("摄像头读取失败")
break
# 处理帧
output_frame, alerts = tracker.process_frame(frame)
# 转为 RGB 显示(Streamlit 要求)
rgb_frame = cv2.cvtColor(output_frame, cv2.COLOR_BGR2RGB)
frame_placeholder.image(rgb_frame, channels="RGB", width="stretch")
# 显示告警
if alerts:
alert_text = "\n\n".join(alerts)
alert_placeholder.warning(alert_text)
else:
alert_placeholder.empty()
except KeyboardInterrupt:
pass
finally:
cap.release()
if __name__ == "__main__":
main()
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="GENERAL_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="fish_monter" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>