使用YOLO进行俯卧撑监测与计数

使用YOLO进行俯卧撑监测与计数

在这篇博客中,我们将探讨如何使用YOLO(You Only Look Once)模型进行俯卧撑的监测与计数。YOLO是一种实时目标检测系统,能够快速识别视频中的物体。在这里,我们将利用YOLO的姿态估计功能来实现对俯卧撑的自动计数。

代码概述请添加图片描述

关键点说明

请添加图片描述

俯卧撑监测与计数的Python代码片段:

import cv2
from ultralytics import solutions

cap = cv2.VideoCapture("path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, 
                                       cv2.CAP_PROP_FRAME_HEIGHT, 
                                       cv2.CAP_PROP_FPS))

# Video writer
video_writer = cv2.VideoWriter("workouts.avi", 
                               cv2.VideoWriter_fourcc(*"mp4v"), 
                               fps, (w, h))

# Init AIGym
gym = solutions.AIGym(
    show=True,  # Display the frame
    kpts=[6, 8, 10],  # keypoints index for monitoring specific exercise
    model="yolo11n-pose.pt",  # Path to the YOLO11 pose estimation model
)

# Process video
while cap.isOpened():
    success, im0 = cap.read()
    if not success:
        break
    im0 = gym.monitor(im0)
    video_writer.write(im0)

cv2.destroyAllWindows()
video_writer.release()

计数要点

1.关键点检测:代码中使用了YOLO的姿态估计模型yolo11n-pose.pt,通过检测人体的关键点(如肩膀、肘部、手腕等)来判断俯卧撑的动作是否完成。
2.动作识别:通过设定关键点的索引(如kpts=[6, 8, 10]),可以监测特定的动作。在俯卧撑中,通常需要监测肩膀、肘部和手腕的相对位置变化。
3.实时监测:代码中使用了cv2.VideoCapture来读取视频文件,并通过AIGym类的monitor方法实时处理每一帧视频。

深蹲检测代码

import cv2

from ultralytics import solutions

cap = cv2.VideoCapture("path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH,
                                       cv2.CAP_PROP_FRAME_HEIGHT,
                                       cv2.CAP_PROP_FPS))

# Video writer
video_writer = cv2.VideoWriter("workouts.avi",
                               cv2.VideoWriter_fourcc(*"mp4v"),
                               fps, (w, h))

# Init AIGym
gym = solutions.AIGym(
    show=True,  # Display the frame
    kpts=[5, 11, 13],  # keypoints index for monitoring specific exercise
    model="yolo11n-pose.pt",  # Path to the YOLO11 pose estimation model
    # line_width=2, # Adjust the line width for bounding boxes
)

# Process video
while cap.isOpened():
    success, im0 = cap.read()
    if not success:
        break
    im0 = gym.monitor(im0)
    video_writer.write(im0)

cv2.destroyAllWindows()
video_writer.release()

应用场景

  1. 健身房监控:可以在健身房中安装摄像头,实时监测会员的运动情况,帮助他们纠正动作并记录运动数据。
    2.家庭健身:对于在家锻炼的人来说,这个系统可以作为一个虚拟教练,帮助他们保持正确的姿势并记录锻炼次数。
    3.运动分析:教练可以使用该系统分析运动员的动作,提供更专业的指导和反馈。

总结

通过使用YOLO进行俯卧撑监测与计数,我们可以实现对运动的自动化监控和分析。这不仅提高了运动的安全性和有效性,还为运动爱好者提供了便利的工具。未来,我们可以进一步优化模型和算法,以支持更多种类的运动监测。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值