网站的备案all,icp备案在哪里查询,雨花区最新情况,免费招聘模板下载【引体向上计数】
本项目使用PaddleHub中的骨骼检测模型human_pose_estimation_resnet50_mpii#xff0c;进行人体运动分析#xff0c;实现对引体向上的自动计数。
1. 项目介绍
人体运动分析是近几年许多领域研究的热点问题。在学科的交叉研究上#xff0c;人体运动分析涉…【引体向上计数】
本项目使用PaddleHub中的骨骼检测模型human_pose_estimation_resnet50_mpii进行人体运动分析实现对引体向上的自动计数。
1. 项目介绍
人体运动分析是近几年许多领域研究的热点问题。在学科的交叉研究上人体运动分析涉及到计算机科学、运动人体科学、环境行为学和材料科学等。随着研究的深入以及计算机视觉、5G通信的飞速发展人体运动分析技术已应用于自动驾驶、影视创作、安防异常事件监测和体育竞技分析、康复等实际场景人体运动分析已成为人工智能领域研究的前沿课题。
在体育课上引体向上是一个常规的运动体育老师有时需要对每位同学做引体向上项目时需要计数那如何利用AI技术进行人体运动分析可以实现引体向上的自动计数从而减轻老师的工作量呢本项目我们就实现AI引体向上计数功能的实现项目效果如下 2.项目分析与解决方案设计
对于引体向上计数任务首先使用录像设备将每个人的动作录制成视频然后对视频进行拆帧拆解成多张图像对每张图像进行人体关键骨骼点检测然后获取每张图像的头部关键点的纵坐标以七张图像为一个单位判断第四张图像的头部关键骨骼关键点的纵坐标是否为七张图像中的最小值f(4)f(x)如果是记录为1如果不是则记录为0最后将记录的值进行累加得到的值便是引体向上的数目最后实现可视化计数便于我们查看结果。这样我们就实现了引体向上计数! 本项目实现基本可以分为7步分别是新建项目与数据导入、人体骨骼关键点模型的安装、模块导入、定义数据、人体骨骼点检测、将计数过程可视化、最后一步实现引体向上计数引体向上计数就可以实现了实现流程如下图所示 了解了项目实现的基本流程接下来我们就按顺序完成每一个模块功能的实现。
3.项目准备
我们要完成此项目该做哪些准备呢 首先是实验实施环境本项目我们使用windows系统nvidia RTX2070 super显卡安装环境
aiofiles23.2.1
aiohttp3.9.1
aiosignal1.3.1
altair5.2.0
annotated-types0.6.0
anyio4.2.0
astor0.8.1
async-timeout4.0.3
attrdict2.0.1
attrs23.2.0
Babel2.14.0
bce-python-sdk0.9.2
beautifulsoup44.12.2
blinker1.7.0
cachetools5.3.2
certifi2023.11.17
charset-normalizer3.3.2
click8.1.7
colorama0.4.6
colorlog6.8.0
contourpy1.1.1
cssselect1.2.0
cssutils2.9.0
cycler0.12.1
Cython3.0.8
datasets2.16.1
decorator5.1.1
dill0.3.4
easydict1.11
et-xmlfile1.1.0
exceptiongroup1.2.0
fastapi0.109.0
ffmpy0.3.1
filelock3.13.1
fire0.5.0
Flask3.0.0
Flask-Babel2.0.0
fonttools4.47.2
frozenlist1.4.1
fsspec2023.10.0
future0.18.3
gradio4.14.0
gradio_client0.8.0
h110.14.0
httpcore1.0.2
httpx0.26.0
huggingface-hub0.20.2
idna3.6
imageio2.33.1
imgaug0.4.0
importlib-metadata7.0.1
importlib-resources6.1.1
itsdangerous2.1.2
jieba0.42.1
Jinja23.1.3
joblib1.3.2
jsonschema4.20.0
jsonschema-specifications2023.12.1
kiwisolver1.4.5
lanms-neo1.0.2
lap0.4.0
lazy_loader0.3
lmdb1.4.1
lxml5.1.0
markdown-it-py3.0.0
MarkupSafe2.1.3
matplotlib3.7.4
mdurl0.1.2
motmetrics1.4.0
multidict6.0.4
multiprocess0.70.12.2
networkx3.1
numpy1.23.5
onnx1.15.0
opencv-contrib-python4.6.0.66
opencv-python4.6.0.66
openpyxl3.1.2
opt-einsum3.3.0
orjson3.9.10
packaging23.2
paddle-bfloat0.1.7
paddle2onnx1.0.6
paddledet2.6.0
paddlefsl1.1.0
paddlehub2.4.0
paddlenlp2.5.2
paddlepaddle-gpu2.4.2.post117
paddleseg2.8.0
pafy0.5.5
pandas2.0.3
pdf2docx0.5.7
pillow10.3.0
pkgutil_resolve_name1.3.10
Polygon33.0.9.1
PPOCRLabel2.1.3
premailer3.10.0
prettytable3.9.0
protobuf3.20.2
psutil5.9.7
py-cpuinfo9.0.0
pyarrow14.0.2
pyarrow-hotfix0.6
pyclipper1.3.0.post5
pycocotools2.0.7
pycryptodome3.20.0
pydantic2.5.3
pydantic_core2.14.6
pydub0.25.1
Pygments2.17.2
PyMuPDF1.20.2
pyparsing3.1.1
PyQt55.15.10
PyQt5-Qt55.15.2
PyQt5-sip12.13.0
python-dateutil2.8.2
python-docx1.1.0
python-multipart0.0.6
pytz2023.3.post1
PyWavelets1.4.1
PyYAML6.0.1
pyzmq25.1.2
rapidfuzz3.6.1
rarfile4.1
referencing0.32.1
requests2.31.0
rich13.7.0
rpds-py0.17.1
safetensors0.4.1
scikit-image0.21.0
scikit-learn1.3.2
scipy1.10.1
seaborn0.13.2
semantic-version2.10.0
sentencepiece0.1.99
seqeval1.2.2
shapely2.0.2
shellingham1.5.4
six1.16.0
sklearn0.0
sniffio1.3.0
soupsieve2.5
starlette0.35.1
termcolor2.4.0
terminaltables3.1.10
threadpoolctl3.2.0
tifffile2023.7.10
tomlkit0.12.0
toolz0.12.0
tqdm4.66.1
typeguard4.1.5
typer0.9.0
typing_extensions4.9.0
tzdata2023.4
ultralytics8.2.30
ultralytics-thop0.2.8
urllib32.1.0
uvicorn0.25.0
visualdl2.4.2
wcwidth0.2.13
websockets11.0.3
Werkzeug3.0.1
xlrd1.2.0
xmltodict0.13.0
xxhash3.4.1
yarl1.9.4
youtube-dl2021.12.17
zipp3.17.0以上是对项目实现环境的要求在此基础上还需要准备一个视频我们将视频命名为引体向上.mp4。 4.代码实现
In [2]
# 导入实验项目需要使用的库
import paddlehub as hub#调用paddlehub中预训练模型的库
import cv2# 能够快速的实现一些图像处理和识别的库
import os#含了很多操作文件和目录的函数的库
import numpy as np#一个由多维数组对象和用于处理数组的例程集合组成的库
from tqdm import tqdm#进度条库可以帮助我们监测代码进度
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/scipy/sparse/sputils.py:16: DeprecationWarning: np.typeDict is a deprecated alias for np.sctypeDict.supported_dtypes [np.typeDict[x] for x in supported_dtypes]
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/scipy/special/orthogonal.py:81: DeprecationWarning: np.int is a deprecated alias for the builtin int. To silence this warning, use int by itself. Doing this will not modify any behavior and is safe. When replacing np.int, you may wish to use e.g. np.int64 or np.int32 to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecationsfrom numpy import (exp, inf, pi, sqrt, floor, sin, cos, around, int,
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/scipy/linalg/__init__.py:217: DeprecationWarning: The module numpy.dual is deprecated. Instead of using dual, use the functions directly from numpy or scipy.from numpy.dual import register_func第1步定义数据
在这一部分需要定义实现引体向上项目需要的数据
定义引体向上视频路径pull_up_path为引体向上.mp4用做引体向上计数视频;定义一个bool值visualiztiontomp4是否将计数结果保存到视频中;定义一个窗口compare_window为3作为每次引体向上计数窗口大小;定义一个视频名称video_name为count_引体向上.mp4用于保存视频的名称。
实现方法如下
In [3]
#定义数据
pull_up_path引体向上.mp4#定义引体向上视频路径
visualizationtomp4 True#是否将结果保存为视频
compare_window3#定义每次引体向上计数的帧数范围
video_name output_count_引体向上.mp4#定义保存视频名称
第2步人体骨骼点检测
人体关键骨骼点检测功能一共分为两步 第一步加载模型human_pose_estimation_resnet50_mpii此时model就变成具备人体关键骨骼点检测功能的“检测器”第二步便是利用其keyponit_detection()函数检测输入图片列表中的所有骨骼点的位置。 第二步将骨骼点检测得到的位置坐标信息储存在result中便于下一个环节使用这里我们将这两步骤封装为point_detection(images)函数参数images为存放图像的列表并将检测结果返回也就是在图片上标出骨骼关键点的位置如下图所示 实现代码如下所示
In [4]
# 定义模型预测函数实现人体关键骨骼点检测
# 图片数据ndarray.shape 为 [H, W, C]
def point_detection(images): # 初始化module调用人体关键点检测模型 model hub.Module(namehuman_pose_estimation_resnet50_mpii) # 预测API识别出人体骨骼关键点result model.keypoint_detection(images,visualizationTrue)return result
第3步计数过程可视化
经过以上操作我们完成了项目环境的准备定义了本项目所用到的数据和获取人体关键骨骼点的函数方法point_detection(images)接下来我们定义一个imagestovideo(images,is_up_list,video_name,fps)函数该函数的作用是将预测的结果可视化并且实现计数功能。
Imagestovideo( )函数中一共包含四个函数
images(list):包含了视频中每一帧的图像is_up_list(list):用于记录每一帧的位置是否完成依次引体向上video_name(str):视频保存路径fps(int):视频的帧率。
具体的实现方法如下
In [5]
# 将计数过程保存成视频
def imagestovideo(images, #(list): 每一帧视频图片is_up_list, #(list): 视频每一帧的位置是否为引体向上完成一次video_name, #(str): 保存视频路径fps):#(int)保存视频帧率size images[0].shape[:2] #获取图片格式大小#定义视频video用于存放处理完的视频video cv2.VideoWriter(video_name, cv2.VideoWriter_fourcc(m, p, 4, v), fps, size[::-1])count 0#定义count用于存放引体向上次数for i in tqdm(range(len(images))):count is_up_list[i] #累加引体向上次数frame images[i]#读取每一张图像#在图像上添加文字用于记录引体向上次数cv2.putText(frame, fpull up count: {count}, (5, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (55,255,155), 2)video.write(frame)#将图像写入视频中video.release()#释放视频对象
第4步实现引体向上计数过程
经过上一步骤我们得到了人体关键骨骼点检测的方法point_detection()和将计数过程可视化的方法imagestovideo()接下里我们具体的实现引体向上计数的过程实现步骤如下
In [6]
def countbyhead_with_mp4(mp4_path,#待处理视频路径video_name,#视频保存名称compare_window5,#计数窗口visualizationtomp4False):#是否可视化计数。第一步我们定义一个列表images用于存放视频中的每一帧图像读取视频并且获取视频的帧率fps具体的实现代码如下images []#定义一个列表用于存放视频中的每一帧图像cap cv2.VideoCapture(mp4_path)#读取已有的视频fps cap.get(cv2.CAP_PROP_FPS)#获取视频的帧率fps,fps9.538461538461538第二步通过while循环读取视频中的每一帧图像并将图片信息保存到images列表当中最后释放视频对象空间具体的实现代码如下while cap.isOpened():#判断视频对象是否成功读取成功读取视频对象返回True#按帧读取视频返回值ret是布尔型正确读取则返回True#读取失败或读取视频结尾则会返回False。#frame为每一帧的图像这里图像是三维矩阵即frame.shape (640,480,3)#读取的图像为BGR格式。ret, frame cap.read() if frame is None:#当读取到空图像时循环终止breakimages.append(frame)#将读取到的每一张图像添加到images列表中cap.release()#释放视频对象第三步对每一张图像进行人体关键骨骼点检测并将结果保存到results中通过for循环获取每张图像的头部关键点的纵坐标信息将每张图像的头部关键点的纵坐标信息存储到heads列表中具体实现代码如下results point_detection(images)#进行人体关键骨骼点检测#获取每张图像的头顶关键点的纵坐标heads [result[data][head_top][1] for result in results]第四步定义is_up_list列表用于记录视频中的每一帧的位置是否完成一次引体向上通过for循环遍历视频中的图像以每七张图像为一个单位进行比较头部关键点的纵坐标大小判断第四张图像的纵坐标是否为这七张图像中的最小值并且保证前三张图像不是计数点如果满足以上要求is_up_list添加1如果不满足则添加0直到循环结束is_up_list中存储了每一帧图像是否完成一次引体向上最后判断是否将计数过程可视化如果实现可视化则调用visualizationtomp4()函数具体实现代码如下is_up_list [0] * compare_window #视频每一帧的位置是否为引体向上完成一次#从3到57依次循环遍历for idx in range(compare_window, len(heads) - compare_window - 1):front_idx idx - compare_window #定义front_idx第一个图像的索引#heads中索引为0到3之间的数转化为数组定义为frontfront np.array(heads[front_idx:idx])#获取真正的索引3317定义为rear_idxrear_idx idx compare_window 1#heads中索引为4到7之间的数转化为数组定义为rearrear np.array(heads[idx1:rear_idx])#将前四张图像的头部关键点纵坐标减去第四张纵坐标# 将大于1的数记为1小于-1的记为-1#将得到的四个数组求和定义为is_greater_than_the_frontis_greater_than_the_front np.sum(np.clip(front - heads[idx], a_min-1, a_max1))#将第四张图像到第七张图像的头部关键点纵坐标减去第四张纵坐标# 将大于1的数记为1小于-1的记为-1将得到的四个数组求和定义为is_greater_than_the_realis_greater_than_the_rear np.sum(np.clip(rear - heads[idx], a_min-1, a_max1))#判断是否同时满足以下三个要求以下条件为是否满足一次引体向上if is_greater_than_the_front 0 and is_greater_than_the_rear 0 and sum(is_up_list[-compare_window:]) 0:is_up_list.append(1)#满足以上条件is_up_list列表末尾添加1else:is_up_list.append(0)#如果不满足以上条件is_up_list列表末尾添加0is_up_list.extend([0] * (compare_window 1))#在is_up_list中添加4个0用于补足视频的帧数if visualizationtomp4:#是否将计数过程保存成视频imagestovideo(images, is_up_list, video_name, fps)#将计数过程保存成视频return results, is_up_list
第5步运行主函数
In [7]
results, is_up_list countbyhead_with_mp4(pull_up_path,video_name, compare_window3,visualizationtomp4visualizationtomp4)
Download https://bj.bcebos.com/paddlehub/paddlehub_dev/human_pose_estimation_resnet50_mpii_1_2_0.zip
[##################################################] 100.00%
Decompress /home/aistudio/.paddlehub/tmp/tmphzw2nbgn/human_pose_estimation_resnet50_mpii_1_2_0.zip
[##################################################] 100.00%[2023-07-21 17:32:55,564] [ INFO] - Successfully installed human_pose_estimation_resnet50_mpii-1.2.0
--- Fused 0 subgraphs into layer_norm op.image saved in output_pose/ndarray_time1689931976012325.jpg
image saved in output_pose/ndarray_time1689931976012369.jpg
image saved in output_pose/ndarray_time1689931976012375.jpg
image saved in output_pose/ndarray_time1689931976012380.jpg
image saved in output_pose/ndarray_time1689931976012384.jpg
image saved in output_pose/ndarray_time1689931976012389.jpg
image saved in output_pose/ndarray_time1689931976012394.jpg
image saved in output_pose/ndarray_time1689931976012400.jpg
image saved in output_pose/ndarray_time1689931976012405.jpg
image saved in output_pose/ndarray_time1689931976012411.jpg
image saved in output_pose/ndarray_time1689931976012416.jpg
image saved in output_pose/ndarray_time1689931976012421.jpg
image saved in output_pose/ndarray_time1689931976012436.jpg
image saved in output_pose/ndarray_time1689931976012441.jpg
image saved in output_pose/ndarray_time1689931976012446.jpg
image saved in output_pose/ndarray_time1689931976012452.jpg
image saved in output_pose/ndarray_time1689931976012456.jpg
image saved in output_pose/ndarray_time1689931976012461.jpg
image saved in output_pose/ndarray_time1689931976012466.jpg
image saved in output_pose/ndarray_time1689931976012472.jpg
image saved in output_pose/ndarray_time1689931976012476.jpg
image saved in output_pose/ndarray_time1689931976012482.jpg
image saved in output_pose/ndarray_time1689931976012487.jpg
image saved in output_pose/ndarray_time1689931976012492.jpg
image saved in output_pose/ndarray_time1689931976012498.jpg
image saved in output_pose/ndarray_time1689931976012502.jpg
image saved in output_pose/ndarray_time1689931976012507.jpg
image saved in output_pose/ndarray_time1689931976012512.jpg
image saved in output_pose/ndarray_time1689931976012517.jpg
image saved in output_pose/ndarray_time1689931976012522.jpg
image saved in output_pose/ndarray_time1689931976012527.jpg
image saved in output_pose/ndarray_time1689931976012532.jpg
image saved in output_pose/ndarray_time1689931976012536.jpg
image saved in output_pose/ndarray_time1689931976012542.jpg
image saved in output_pose/ndarray_time1689931976012546.jpg
image saved in output_pose/ndarray_time1689931976012550.jpg
image saved in output_pose/ndarray_time1689931976012556.jpg
image saved in output_pose/ndarray_time1689931976012561.jpg
image saved in output_pose/ndarray_time1689931976012565.jpg
image saved in output_pose/ndarray_time1689931976012570.jpg
image saved in output_pose/ndarray_time1689931976012575.jpg
image saved in output_pose/ndarray_time1689931976012579.jpg
image saved in output_pose/ndarray_time1689931976012584.jpg
image saved in output_pose/ndarray_time1689931976012589.jpg
image saved in output_pose/ndarray_time1689931976012594.jpg
image saved in output_pose/ndarray_time1689931976012599.jpg
image saved in output_pose/ndarray_time1689931976012604.jpg
image saved in output_pose/ndarray_time1689931976012609.jpg
image saved in output_pose/ndarray_time1689931976012614.jpg
image saved in output_pose/ndarray_time1689931976012619.jpg
image saved in output_pose/ndarray_time1689931976012624.jpg
image saved in output_pose/ndarray_time1689931976012629.jpg
image saved in output_pose/ndarray_time1689931976012634.jpg
image saved in output_pose/ndarray_time1689931976012640.jpg
image saved in output_pose/ndarray_time1689931976012644.jpg
image saved in output_pose/ndarray_time1689931976012648.jpg
image saved in output_pose/ndarray_time1689931976012654.jpg
image saved in output_pose/ndarray_time1689931976012658.jpg
image saved in output_pose/ndarray_time1689931976012662.jpg
image saved in output_pose/ndarray_time1689931976012667.jpg
image saved in output_pose/ndarray_time1689931976012673.jpg
image saved in output_pose/ndarray_time1689931976012678.jpg100%|██████████| 62/62 [00:0000:00, 975.11it/s]
完整代码模型视频例子运行结果视频下载地址
https://download.csdn.net/download/FL1623863129/89760682