feat(app): add new preset video and refine comparison flow
This commit is contained in:
parent
9d42c8c0eb
commit
899c85ab8f
51
main_app.py
51
main_app.py
@ -42,6 +42,7 @@ def main():
|
|||||||
# Define preset video mapping (display name -> filename)
|
# Define preset video mapping (display name -> filename)
|
||||||
preset_videos = {
|
preset_videos = {
|
||||||
"六字诀": "liuzi.mp4",
|
"六字诀": "liuzi.mp4",
|
||||||
|
"六字诀精简": "liuzi-short.mp4",
|
||||||
# Add more preset videos here:
|
# Add more preset videos here:
|
||||||
# "太极拳": "taiji.mp4",
|
# "太极拳": "taiji.mp4",
|
||||||
# "八段锦": "baduanjin.mp4",
|
# "八段锦": "baduanjin.mp4",
|
||||||
@ -160,26 +161,36 @@ def main():
|
|||||||
st.session_state.show_preview = False
|
st.session_state.show_preview = False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# 主控制按钮(大按钮)
|
if 'start_main_comparison' not in st.session_state:
|
||||||
main_btn_col1, main_btn_col2, main_btn_col3 = st.columns(3)
|
st.session_state.start_main_comparison = False
|
||||||
|
# 如果不处于比较状态,则显示主控制按钮
|
||||||
with main_btn_col1:
|
if not st.session_state.start_main_comparison:
|
||||||
if st.button("📷 预览摄像头", use_container_width=True, help="先预览摄像头调整位置"):
|
main_btn_col1, main_btn_col2, main_btn_col3 = st.columns(3)
|
||||||
if app.body_detector is None:
|
|
||||||
st.error("⚠️ 请先在侧边栏初始化系统")
|
with main_btn_col1:
|
||||||
else:
|
if st.button("📷 预览摄像头", use_container_width=True, help="先预览摄像头调整位置"):
|
||||||
st.session_state.show_preview = True
|
if app.body_detector is None:
|
||||||
st.rerun()
|
st.error("⚠️ 请先在侧边栏初始化系统")
|
||||||
|
else:
|
||||||
with main_btn_col2:
|
st.session_state.show_preview = True
|
||||||
if st.button("🚀 直接开始比较", use_container_width=True, help="直接开始动作比较"):
|
st.rerun()
|
||||||
if app.body_detector is None:
|
|
||||||
st.error("⚠️ 请先在侧边栏初始化系统")
|
with main_btn_col2:
|
||||||
else:
|
if st.button("🚀 直接开始比较", use_container_width=True, help="直接开始动作比较"):
|
||||||
app.start_comparison(video_path)
|
if app.body_detector is None:
|
||||||
|
st.error("⚠️ 请先在侧边栏初始化系统")
|
||||||
with main_btn_col3:
|
else:
|
||||||
st.markdown("") # 占位
|
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:
|
except Exception as e:
|
||||||
st.error(f"❌ 处理视频时出现错误: {str(e)}")
|
st.error(f"❌ 处理视频时出现错误: {str(e)}")
|
||||||
|
@ -36,7 +36,7 @@ class MotionComparisonApp:
|
|||||||
st.session_state.comparison_state = {'is_running': False, 'should_stop': False, 'should_restart': False}
|
st.session_state.comparison_state = {'is_running': False, 'should_stop': False, 'should_restart': False}
|
||||||
|
|
||||||
def get_display_resolution(self):
|
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')
|
mode = self.display_settings.get('resolution_mode', 'medium')
|
||||||
return modes.get(mode, (960, 720))
|
return modes.get(mode, (960, 720))
|
||||||
|
|
||||||
@ -74,6 +74,7 @@ class MotionComparisonApp:
|
|||||||
try:
|
try:
|
||||||
self.webcam_cap = cv2.VideoCapture(0)
|
self.webcam_cap = cv2.VideoCapture(0)
|
||||||
if self.webcam_cap.isOpened():
|
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()
|
width, height = self.get_display_resolution()
|
||||||
self.webcam_cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
|
self.webcam_cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
|
||||||
self.webcam_cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
|
self.webcam_cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
|
||||||
|
Loading…
Reference in New Issue
Block a user