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

wen 实用脚本 4

🏀 篮球假动作晃过防守统计脚本

下面是一个实用的Python脚本,用于统计篮球比赛中假动作晃过防守的次数,你可以手动记录事件,也可以结合视频分析使用。

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


📋 基础版脚本(手动记录)

import json
from datetime import datetime
class FakeMoveTracker:
    def __init__(self, player_name):
        self.player_name = player_name
        self.events = []  # 每次成功晃过的记录
        self.attempts = 0 # 假动作总次数
    def record_attempt(self, move_type, success, defender=""):
        """记录一次假动作
        move_type: 假动作类型 (如 '投篮假动作', '突破假动作', '传球假动作')
        success: True/False 是否晃过防守
        """
        self.attempts += 1
        event = {
            "time": datetime.now().strftime("%H:%M:%S"),
            "move_type": move_type,
            "success": success,
            "defender": defender
        }
        self.events.append(event)
        status = "✅ 晃过" if success else "❌ 未成功"
        print(f"[{event['time']}] {move_type} -> {status} (防守: {defender or '未知'})")
    def stats(self):
        """输出统计结果"""
        success_count = sum(1 for e in self.events if e["success"])
        rate = (success_count / self.attempts * 100) if self.attempts else 0
        print("\n" + "="*40)
        print(f"📊 {self.player_name} 假动作统计")
        print("="*40)
        print(f"假动作总次数: {self.attempts}")
        print(f"成功晃过次数: {success_count}")
        print(f"成功率:      {rate:.1f}%")
        # 按类型分类统计
        print("\n📈 各类型明细:")
        types = {}
        for e in self.events:
            t = e["move_type"]
            types.setdefault(t, {"total": 0, "success": 0})
            types[t]["total"] += 1
            if e["success"]:
                types[t]["success"] += 1
        for t, d in types.items():
            r = d["success"] / d["total"] * 100
            print(f"  {t}: {d['success']}/{d['total']} ({r:.0f}%)")
        return success_count
    def save(self, filename="fake_move_stats.json"):
        data = {
            "player": self.player_name,
            "attempts": self.attempts,
            "events": self.events
        }
        with open(filename, "w", encoding="utf-8") as f:
            json.dump(data, f, ensure_ascii=False, indent=2)
        print(f"\n💾 已保存到 {filename}")
# ============ 使用示例 ============
if __name__ == "__main__":
    tracker = FakeMoveTracker("8号球员")
    # 模拟记录比赛中的假动作(可手动输入)
    tracker.record_attempt("投篮假动作", True, "对方3号")
    tracker.record_attempt("突破假动作", True, "对方5号")
    tracker.record_attempt("传球假动作", False, "对方1号")
    tracker.record_attempt("投篮假动作", True, "对方3号")
    tracker.record_attempt("突破假动作", True, "对方5号")
    tracker.stats()
    tracker.save()

输出示例:

[14:23:11] 投篮假动作 -> ✅ 晃过 (防守: 对方3号)
[14:24:05] 突破假动作 -> ✅ 晃过 (防守: 对方5号)
[14:25:30] 传球假动作 -> ❌ 未成功 (防守: 对方1号)
...
========================================
📊 8号球员 假动作统计
========================================
假动作总次数: 5
成功晃过次数: 4
成功率:      80.0%
📈 各类型明细:
  投篮假动作: 2/2 (100%)
  突破假动作: 2/2 (100%)
  传球假动作: 0/1 (0%)

🎬 进阶版:结合视频分析(OpenCV)

如果你有比赛录像,可以用下面的脚本辅助逐帧标记:

import cv2
import json
def analyze_video(video_path, output="annotations.json"):
    cap = cv2.VideoCapture(video_path)
    fps = cap.get(cv2.CAP_PROP_FPS)
    annotations = []
    print("操作说明:")
    print("  [S] 标记成功晃过   [F] 标记未成功   [Q] 退出")
    frame_id = 0
    while True:
        ret, frame = cap.read()
        if not ret:
            break
        frame_id += 1
        # 每帧显示
        cv2.imshow("Video", frame)
        key = cv2.waitKey(0) & 0xFF
        if key == ord('s'):
            annotations.append({
                "frame": frame_id,
                "time_sec": round(frame_id / fps, 2),
                "success": True
            })
            print(f"[{frame_id/fps:.2f}s] ✅ 记录成功晃过")
        elif key == ord('f'):
            annotations.append({
                "frame": frame_id,
                "time_sec": round(frame_id / fps, 2),
                "success": False
            })
            print(f"[{frame_id/fps:.2f}s] ❌ 记录未成功")
        elif key == ord('q'):
            break
    cap.release()
    cv2.destroyAllWindows()
    success = sum(1 for a in annotations if a["success"])
    print(f"\n📊 总计 {len(annotations)} 次假动作,成功 {success} 次")
    with open(output, "w", encoding="utf-8") as f:
        json.dump(annotations, f, ensure_ascii=False, indent=2)
    print(f"💾 保存到 {output}")
# analyze_video("game.mp4")

💡 判定标准建议

为了让统计更客观,建议明确定义"晃过防守"的标准:

判定结果 标准
✅ 成功晃过 防守人重心偏移/失位,进攻方获得明显空间或突破路线
❌ 未成功 防守人未上当,保持防守位置
⚠️ 模糊情况 建议不计入,或记录为"半成功"

🔧 后续可扩展方向

  • 多人统计:把 player_name 改为列表,支持全队统计
  • 数据库存储:把 JSON 换成 SQLite,方便多场比赛累积分析
  • 可视化:用 matplotlib 生成成功率柱状图
  • 导出报表:生成 Excel 表格供教练组查看

需要我帮你改成特定的假动作类型(比如只统计"投篮假动作")、加入图形界面,或者对接某款追踪软件(如 SportsCode / Hudl)吗?告诉我具体场景,我可以定制。

上一篇实用脚本认为边路传中是得分利器吗?

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

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