实用脚本统计假动作晃过防守几次?

wen 实用脚本 1

统计“假动作晃过防守”次数 — 实用脚本方案

你这个问题缺少具体场景(哪个游戏/视频/传感器数据?),我先给出通用可落地的思路 + Python 脚本模板,你可以按实际数据源替换。

实用脚本统计假动作晃过防守几次?


从篮球/足球视频统计(最常用)

用姿态识别 + 防守人距离变化判断“晃过”。

"""
统计假动作晃过防守次数
依赖: pip install opencv-python mediapipe numpy
思路:
1. 检测进攻球员和防守球员关键点
2. 假动作 = 进攻方重心/肩部快速反向移动后立即变向
3. 晃过 = 假动作后防守人重心偏移 > 阈值 且 进攻方突破方向与假动作相反
"""
import cv2, mediapipe as mp, numpy as np
mp_pose = mp.solutions.pose
pose = mp_pose.Pose(min_detection_confidence=0.5)
def get_keypoints(frame):
    res = pose.process(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
    if not res.pose_landmarks: return None
    lm = res.pose_landmarks.landmark
    return {
        'L_shoulder': np.array([lm[11].x, lm[11].y]),
        'R_shoulder': np.array([lm[12].x, lm[12].y]),
        'L_hip':      np.array([lm[23].x, lm[23].y]),
        'R_hip':      np.array([lm[24].x, lm[24].y]),
        'L_ankle':    np.array([lm[27].x, lm[27].y]),
        'R_ankle':    np.array([lm[28].x, lm[28].y]),
    }
def torso_center(kp):
    return (kp['L_shoulder']+kp['R_shoulder']+kp['L_hip']+kp['R_hip'])/4
# 参数(按视频调)
FEINT_SPEED_TH = 0.03      # 单帧重心位移阈值(归一化坐标)
REVERSE_WINDOW = 8         # 反向判定窗口(帧)
BEAT_DIST_TH   = 0.15      # 晃开距离阈值
cap = cv2.VideoCapture("game.mp4")
prev = None
history = []          # 存重心轨迹
feint_frames = []     # 假动作起始帧
count = 0
frame_idx = 0
while True:
    ok, frame = cap.read()
    if not ok: break
    kp = get_keypoints(frame)
    if kp is None:
        frame_idx += 1; continue
    c = torso_center(kp)
    history.append(c)
    if prev is not None:
        v = c - prev
        # 检测“快速移动后反向”= 假动作
        if len(history) > REVERSE_WINDOW:
            v_old = history[-REVERSE_WINDOW] - history[-REVERSE_WINDOW-1]
            if np.linalg.norm(v) > FEINT_SPEED_TH and np.dot(v, v_old) < 0:
                feint_frames.append(frame_idx)
    # 简化:假动作后 N 帧内若防守人(假设另一条pose)重心偏移>阈值 → 记1次
    # 实际需同时跟踪防守球员,此处留接口
    prev = c
    frame_idx += 1
cap.release()
print(f"假动作次数: {len(feint_frames)}")
print(f"预计晃过次数: {sum(1 for f in feint_frames if f+REVERSE_WINDOW < frame_idx)}")

局限:单人 pose 只能判“假动作”,判“晃过”需双人跟踪 + 防守人重心偏移,生产环境建议用 YOLO+ByteTrack 跟踪两名球员。


从游戏回放/操作日志统计(NBA 2K、FIFA 等)

如果游戏有 API 或可解析日志:

import json
from collections import defaultdict
def count_crossover_success(log_path):
    """日志需含: {t, action, defender_reacted, defender_offset}"""
    events = [json.loads(l) for l in open(log_path)]
    feints, success = 0, 0
    pending = None
    for e in events:
        if e['action'] in ('crossover','hesitation','spin'):
            feints += 1
            pending = e['t']
        elif pending and e['t'] - pending < 1.0:  # 1秒内防守反应
            if e.get('defender_offset', 0) > 0.3:  # 重心偏移>0.3m
                success += 1
                pending = None
    return feints, success
f, s = count_crossover_success("replay.log")
print(f"假动作 {f} 次,晃过 {s} 次,成功率 {s/max(f,1):.1%}")

传感器数据(IMU / 动捕)

对加速度/角速度做峰值检测:

import numpy as np
from scipy.signal import find_peaks
def count_feints(accel, gyro, fps=100):
    # 假动作特征:横向加速度尖峰 + 角速度反号
    lat = accel[:, 0]
    peaks, _ = find_peaks(np.abs(lat), height=3.0, distance=int(0.5*fps))
    feints = 0
    for p in peaks:
        win = gyro[max(0,p-fps//5):p+fps//5, 2]  # 偏航角速度
        if len(win) > 2 and np.sign(win).max() != np.sign(win).min():
            feints += 1
    return feints
# 示例
N=1000
accel = np.random.randn(N,3); gyro = np.random.randn(N,3)
print("假动作次数:", count_feints(accel, gyro))

关键判定逻辑(通用)

概念 判定条件
假动作 进攻方重心/球快速向 A 方向移动,随后 ≤0.5s 内反向(角速度符号反转)
晃过 假动作后防守方重心偏移 > 阈值(或距离拉开 > 0.5m)且未回位
成功率高 同一回合内 假动作 → 晃过 的配对

请你补充一下场景,我可以给更精确的脚本:

  1. 数据源:视频 / 游戏日志 / IMU / 手动标注 CSV?
  2. 运动类型:篮球 / 足球 / 拳击 / 其他?
  3. “晃过”定义:防守人失位?进攻方过人成功?得分?
  4. 是否有防守球员数据(双人跟踪)?

告诉我其中 1-2 点,我可以把上面的模板改成可直接跑你的数据的完整脚本。

上一篇实用脚本如何评估点球大战心理素质?

下一篇当前分类已是最新一篇

抱歉,评论功能暂时关闭!

友情链接攻略窝 · 礼包窝 · 配置窝 · 换算窝 · 算法窝 · 查文窝 · 手册窝 · 问答窝 · 全文搜 · 手册库
相关站点礼包窝 · 查文窝