击剑动作识别程序 - 选择输入视频文件

欢迎使用击剑动作识别程序V6.2 (作者:冯楠20201888)

本程序使用OpenCV和Python编写,支持识别击剑动作,并输出识别结果。

使用方法:

  1. 选择输入视频文件:
    • 点击 "选择文件" 按钮,选择需要识别动作的视频文件(支持 *.mp4, *.avi 格式)。
  2. 调整参数:
    • 使用滑动条调整识别参数,例如距离阈值和邻居数量。
  3. 运行程序:
    • 点击 "运行" 按钮,开始识别视频中的动作。

识别结果:

  • 程序会将识别结果输出至名为 输入视频文件名_OUT.mp4 的视频文件。

代码示例:

# cap = cv2.VideoCapture('5.mp4')
import tkinter as tk
from tkinter import filedialog

# 修改distance_threshold
def set_distance_threshold(value):
    global distance_threshold
    distance_threshold = int(value)

# 创建窗口
root = tk.Tk()
root.withdraw()

# 显示使用说明信息
info = '欢迎使用击剑动作识别程序V6.2(作者:冯楠20201888)
请选择输入视频文件
支持格式:*.mp4, *.avi
点击确认选择文件'
tk.messagebox.showinfo('使用说明', info)

# 定义选择文件函数
def select_file():
    global input_path
    root3 = tk.Tk()
    root3.title('选择文件')
    input_path = filedialog.askopenfilename(title='选择输入视频文件', filetypes=[('视频文件', '*.mp4;*.avi'), ('所有文件', '*.*')])
    root3.destroy()
    if not input_path:
        tk.messagebox.showerror('错误', '未选择输入视频文件!')
        root3.destroy()
        return
    # 更新标签显示选择的文件路径
    file_label.config(text=input_path)
def closeit():
    root2.destroy()

# 创建窗口2
root2 = tk.Tk()
root2.title('选择文件,调整参数')
root2.geometry('400x600')

# 创建标题
file_titles = tk.Label(root2, text='击剑动作识别程序', font=('宋体', 18))
file_titles.pack(pady=20)
# 创建标签
file_label = tk.Label(root2, text='未选择文件')
file_label.pack(pady=20)
file_label.config(bg='#e9ccd3')

select_button = tk.Button(root2, text='选择文件', command=select_file)
select_button.pack(pady=10)
# 创建标题
file_titles = tk.Label(root2, text='参数调整', font=('微软雅黑', 13))
file_titles.pack(pady=20)
# 创建滑动条
scale = tk.Scale(root2, from_=0, to=200, orient=tk.HORIZONTAL, length=150, label='距离阈值', command=set_distance_threshold)
scale.set(distance_threshold)
scale.pack()



def set_neighbors(val):
    global neighbors
    neighbors = int(val)
# 创建滑动条
scale = tk.Scale(root2, from_=1, to=10, orient=tk.HORIZONTAL, length=150, label='邻居数量', command=set_neighbors)
scale.set(neighbors)
scale.pack()



# 创建按钮

run_button = tk.Button(root2, text='运行', command=closeit)
run_button.pack(pady=20)

# 创建标签
file_name = tk.Label(root2, text=f"作者:冯楠2020188 物联网2班\n指导教师:朱勇\n版本:{version}", font=("Arial", 14))
file_name.pack(pady=20)
# 关闭窗口
root.destroy()
# 运行窗口
root2.attributes('-topmost', True)#窗口在最前
root2.mainloop()


root = tk.Tk()
root.withdraw()
info = f"视频已输出至{input_path}_OUT.mp4"
tk.messagebox.showinfo('处理完成', info)

tkinter标准GUI库在程序中的作用:

  • tkinter标准GUI库是Python自带的一个图形用户界面(GUI)工具包,可以用于创建各种窗口、按钮、标签、文本框等GUI元素,实现交互式的图形界面程序。
  • 在本程序中,使用tkinter库创建了一个窗口,包含选择文件、调整参数、运行等功能的界面,方便用户选择视频文件和调整识别参数。
  • 通过tkinter库的messagebox模块,还可以在程序处理完成后,弹出提示框告知用户处理结果。
击剑动作识别程序 - 选择输入视频文件

原文地址: https://www.cveoy.top/t/topic/gQ0A 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录