击剑动作识别程序V6.2 - 优化距离阈值设置

本程序旨在识别击剑动作,并提供自定义距离阈值功能。

全局变量:

label = [' '] # 识别输出标签
poses = '' # 视频输出标签
i = 0
t = 30 # 后处理帧数
posess_a = ''
posess_b = ''
a = 1.2 # 辅助拟合精度
# 设置KNN距离阈值,可以通过函数修改
distance_threshold = 121 
neighbors = 2 # 邻居
input_path = ''

程序初始化:

# 初始化MediaPipe的人体姿势模型
mp_drawing = mp.solutions.drawing_utils
mp_pose = mp.solutions.pose

# 选择输入视频文件
import tkinter as tk
from tkinter import filedialog

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

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

# 选择输入视频文件
input_path = filedialog.askopenfilename(title='选择输入视频文件', filetypes=[('视频文件', '*.mp4;*.avi'), ('所有文件', '*.*')])
if not input_path:
    tk.messagebox.showerror('错误', '未选择输入视频文件!')
    exit()

# 关闭窗口
root.destroy()

优化距离阈值设置:

为了方便用户自定义距离阈值,可以使用如下方法:

  1. distance_threshold 定义为全局变量,并设置初始值为 121。

  2. 创建一个函数 update_distance_threshold,用于修改 distance_threshold 的值。

# 定义修改距离阈值函数
def update_distance_threshold(new_value):
    global distance_threshold
    distance_threshold = new_value

调用函数修改距离阈值:

在程序中,可以通过调用 update_distance_threshold 函数,并传入新的值,来修改 distance_threshold

例如,将 distance_threshold 修改为 150:

update_distance_threshold(150)

其他功能:

本程序还包含其他功能,例如识别输出标签、视频输出标签、后处理帧数等。用户可以根据自己的需求调整相关参数。

总结:

本程序提供了一个自定义距离阈值的功能,用户可以根据自己的需求调整参数,以优化动作识别效果。


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

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