Update src/streamlit_app.py
Browse files- src/streamlit_app.py +19 -21
src/streamlit_app.py
CHANGED
@@ -96,47 +96,45 @@ def check_posture(landmarks, image_shape):
|
|
96 |
def main():
|
97 |
st.set_page_config(layout="wide")
|
98 |
st.title("📷 姿勢分析アプリ (Posture Analyzer)")
|
99 |
-
st.write("このアプリはリアルタイムで姿勢を分析します (This app analyzes your posture in real time)")
|
100 |
|
101 |
-
# Create two columns
|
102 |
col1, col2 = st.columns([2, 1])
|
103 |
|
104 |
with col1:
|
105 |
st.header("カメラビュー (Camera View)")
|
106 |
-
run = st.checkbox("
|
107 |
FRAME_WINDOW = st.image([])
|
108 |
|
109 |
with col2:
|
110 |
st.header("姿勢分析 (Posture Analysis)")
|
111 |
status_placeholder = st.empty()
|
112 |
-
if not run:
|
113 |
-
status_placeholder.markdown("""
|
114 |
-
**カメラからのデータを待っています (Waiting for camera data)...**
|
115 |
-
|
116 |
-
姿勢分析のためにウェブカメラをオンにしてください (Please enable webcam for posture analysis)
|
117 |
-
""")
|
118 |
|
|
|
119 |
camera = cv2.VideoCapture(0)
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
while run:
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
FRAME_WINDOW.image(analyzed_frame)
|
132 |
-
|
133 |
-
with col2:
|
134 |
status_placeholder.markdown(posture_status)
|
|
|
|
|
|
|
135 |
|
136 |
time.sleep(0.1)
|
137 |
|
138 |
camera.release()
|
139 |
-
cv2.destroyAllWindows()
|
140 |
|
141 |
if __name__ == "__main__":
|
142 |
main()
|
|
|
96 |
def main():
|
97 |
st.set_page_config(layout="wide")
|
98 |
st.title("📷 姿勢分析アプリ (Posture Analyzer)")
|
|
|
99 |
|
|
|
100 |
col1, col2 = st.columns([2, 1])
|
101 |
|
102 |
with col1:
|
103 |
st.header("カメラビュー (Camera View)")
|
104 |
+
run = st.checkbox("カメラを起動 (Enable camera)", value=True)
|
105 |
FRAME_WINDOW = st.image([])
|
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 |
time.sleep(0.1)
|
136 |
|
137 |
camera.release()
|
|
|
138 |
|
139 |
if __name__ == "__main__":
|
140 |
main()
|