feat(app): add new preset video and refine comparison flow

This commit is contained in:
game-loader 2025-06-22 11:36:55 +08:00
parent 9d42c8c0eb
commit 899c85ab8f
2 changed files with 33 additions and 21 deletions

View File

@ -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,7 +161,10 @@ def main():
st.session_state.show_preview = False
else:
# 主控制按钮(大按钮)
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:
@ -176,11 +180,18 @@ def main():
if app.body_detector is None:
st.error("⚠️ 请先在侧边栏初始化系统")
else:
app.start_comparison(video_path)
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)}")

View File

@ -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)