diff --git a/main_app.py b/main_app.py index 6512fd8..9809c3d 100644 --- a/main_app.py +++ b/main_app.py @@ -42,6 +42,7 @@ def main(): # Define preset video mapping (display name -> filename) preset_videos = { "六字诀": "liuzi.mp4", + "六字诀精简": "liuzi-short.mp4", # Add more preset videos here: # "太极拳": "taiji.mp4", # "八段锦": "baduanjin.mp4", @@ -160,26 +161,36 @@ def main(): st.session_state.show_preview = False else: - # 主控制按钮(大按钮) - main_btn_col1, main_btn_col2, main_btn_col3 = st.columns(3) - - with main_btn_col1: - if st.button("📷 预览摄像头", use_container_width=True, help="先预览摄像头调整位置"): - if app.body_detector is None: - st.error("⚠️ 请先在侧边栏初始化系统") - else: - st.session_state.show_preview = True - st.rerun() - - with main_btn_col2: - if st.button("🚀 直接开始比较", use_container_width=True, help="直接开始动作比较"): - if app.body_detector is None: - st.error("⚠️ 请先在侧边栏初始化系统") - else: - app.start_comparison(video_path) - - with main_btn_col3: - st.markdown("") # 占位 + if 'start_main_comparison' not in st.session_state: + st.session_state.start_main_comparison = False + # 如果不处于比较状态,则显示主控制按钮 + if not st.session_state.start_main_comparison: + main_btn_col1, main_btn_col2, main_btn_col3 = st.columns(3) + + with main_btn_col1: + if st.button("📷 预览摄像头", use_container_width=True, help="先预览摄像头调整位置"): + if app.body_detector is None: + st.error("⚠️ 请先在侧边栏初始化系统") + else: + st.session_state.show_preview = True + st.rerun() + + with main_btn_col2: + if st.button("🚀 直接开始比较", use_container_width=True, help="直接开始动作比较"): + if app.body_detector is None: + st.error("⚠️ 请先在侧边栏初始化系统") + else: + st.session_state.start_main_comparison = True + st.rerun() + + with main_btn_col3: + st.markdown("") # 占位 + + if st.session_state.start_main_comparison: + app.start_comparison(video_path) + # 比较结束后,重置状态,以便下次可以重新显示主按钮 + st.session_state.start_main_comparison = False + st.rerun() # 强制重跑以显示主按钮界面 except Exception as e: st.error(f"❌ 处理视频时出现错误: {str(e)}") diff --git a/motion_app.py b/motion_app.py index d5ff693..981560f 100644 --- a/motion_app.py +++ b/motion_app.py @@ -36,7 +36,7 @@ class MotionComparisonApp: st.session_state.comparison_state = {'is_running': False, 'should_stop': False, 'should_restart': False} def get_display_resolution(self): - modes = {'high': (1280, 800), 'medium': (960, 720), 'low': (640, 480)} + modes = {'high': (1024, 576), 'medium': (960, 720), 'low': (640, 480)} mode = self.display_settings.get('resolution_mode', 'medium') return modes.get(mode, (960, 720)) @@ -74,6 +74,7 @@ class MotionComparisonApp: try: self.webcam_cap = cv2.VideoCapture(0) if self.webcam_cap.isOpened(): + self.webcam_cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')) width, height = self.get_display_resolution() self.webcam_cap.set(cv2.CAP_PROP_FRAME_WIDTH, width) self.webcam_cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)