Update src/streamlit_app.py
Browse files- src/streamlit_app.py +35 -29
src/streamlit_app.py
CHANGED
@@ -101,40 +101,46 @@ def main():
|
|
101 |
|
102 |
with col1:
|
103 |
st.header("カメラビュー (Camera View)")
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
with col2:
|
108 |
st.header("姿勢分析 (Posture Analysis)")
|
109 |
status_placeholder = st.empty()
|
110 |
-
|
111 |
-
# Инициализация камеры с проверкой
|
112 |
-
camera = cv2.VideoCapture(0)
|
113 |
-
if not camera.isOpened():
|
114 |
-
demo_image = np.zeros((480, 640, 3), dtype=np.uint8)
|
115 |
-
FRAME_WINDOW.image(demo_image)
|
116 |
-
status_placeholder.error("エラー: カメラデバイスに接続できません (Error: Camera device not accessible)")
|
117 |
-
return
|
118 |
-
|
119 |
-
while run:
|
120 |
-
ret, frame = camera.read()
|
121 |
-
if not ret or frame is None:
|
122 |
-
st.warning("フレームを取得できません (Failed to capture frame)")
|
123 |
-
break
|
124 |
-
|
125 |
-
try:
|
126 |
-
# Конвертация цветов
|
127 |
-
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
128 |
-
analyzed_frame, posture_status = analyze_posture(frame)
|
129 |
-
FRAME_WINDOW.image(analyzed_frame)
|
130 |
-
status_placeholder.markdown(posture_status)
|
131 |
-
except Exception as e:
|
132 |
-
st.error(f"処理エラー: {str(e)} (Processing error)")
|
133 |
-
break
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
if __name__ == "__main__":
|
140 |
main()
|
|
|
101 |
|
102 |
with col1:
|
103 |
st.header("カメラビュー (Camera View)")
|
104 |
+
|
105 |
+
if st.button("カメラアクセスを許可 (Allow camera access)"):
|
106 |
+
st.session_state.camera_allowed = True
|
107 |
+
|
108 |
+
if not st.session_state.get('camera_allowed', False):
|
109 |
+
st.warning("⚠️ カメラを使用するには許可が必要です (Camera access requires permission)")
|
110 |
+
st.image("demo_pose.jpg") # Заглушка
|
111 |
+
run = False
|
112 |
+
else:
|
113 |
+
run = st.checkbox("カメラを起動 (Enable camera)", value=True)
|
114 |
+
FRAME_WINDOW = st.image([])
|
115 |
|
116 |
with col2:
|
117 |
st.header("姿勢分析 (Posture Analysis)")
|
118 |
status_placeholder = st.empty()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
+
uploaded_file = st.file_uploader("または画像をアップロード (Or upload image)",
|
121 |
+
type=["jpg", "png", "jpeg"])
|
122 |
+
|
123 |
+
if run and st.session_state.camera_allowed:
|
124 |
+
camera = cv2.VideoCapture(0)
|
125 |
+
if not camera.isOpened():
|
126 |
+
st.error("カメラエラー: デバイスに接続できません (Camera error: Device not accessible)")
|
127 |
+
run = False
|
128 |
+
|
129 |
+
while run:
|
130 |
+
ret, frame = camera.read()
|
131 |
+
if ret:
|
132 |
+
analyzed_frame, posture_status = analyze_posture(frame)
|
133 |
+
FRAME_WINDOW.image(analyzed_frame)
|
134 |
+
status_placeholder.markdown(posture_status)
|
135 |
+
time.sleep(0.1)
|
136 |
+
camera.release()
|
137 |
+
|
138 |
+
elif uploaded_file:
|
139 |
+
file_bytes = np.frombuffer(uploaded_file.read(), np.uint8)
|
140 |
+
frame = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
|
141 |
+
analyzed_frame, posture_status = analyze_posture(frame)
|
142 |
+
col1.image(analyzed_frame)
|
143 |
+
status_placeholder.markdown(posture_status)
|
144 |
|
145 |
if __name__ == "__main__":
|
146 |
main()
|