【基于PaddleHub的跳绳AI计数器】智能计数器

简介: 【基于PaddleHub的跳绳AI计数器】智能计数器

一、【基于PaddleHub的跳绳AI计数器】智能计数介绍


1.背景介绍



疫情以来,小朋友、大朋友们非必要不外出,都老老实实的画地为牢了。跳绳这类比起跑步等户外活动的优势一下子凸显了出来。值此佳节【六一儿童节】到来之际,我给大家弄一个通过手机视频计数的APP方案,具体如下,我们小学生也会做啦:


2.实现思路


  • 1.用户打开手机APP,将手机固定在场地一侧,适当设置手机角度,根据应用的自动语音提示调整身体与手机距离,直到人体完全位于识别框内,即可开始运动。
  • 2.通过PaddleHub的human_pose_estimation_resnet50_mpii模型,进行人体关键点检测。
  • 3.根据检测的数据,计算是否起跳,并计数(此处选择骨盆关键点进行判断,因为跳绳有多种花式,选择其他关键点不一定能记录到),
  • 4.移植该应用到手机app端


另外,【六一】活动大家可以积极相应,具体地址:

精品项目征集方向(一)-青少年主题项目征aistudio.baidu.com/paddle/foru…


二、环境准备


1.PaddleHub安装


!pip install -U pip --user >log.log
!pip install -U paddlehub >log.log
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
parl 1.4.1 requires pyzmq==18.1.1, but you have pyzmq 22.3.0 which is incompatible.
!pip list |grep paddle
paddle2onnx            0.9.5
paddlehub              2.2.0
paddlenlp              2.0.1
paddlepaddle           2.2.2
tb-paddle              0.3.6


2.human_pose_estimation_resnet50_mpii模型安装


  • 模型地址:www.paddlepaddle.org.cn/hubdetail?n…
  • 模型概述:人体骨骼关键点检测(Pose Estimation) 是计算机视觉的基础性算法之一,在诸多计算机视觉任务起到了基础性的作用,如行为识别、人物跟踪、步态识别等相关领域。具体应用主要集中在智能视频监控,病人监护系统,人机交互,虚拟现实,人体动画,智能家居,智能安防,运动员辅助训练等等。 该模型的论文《Simple Baselines for Human Pose Estimation and Tracking》由 MSRA 发表于 ECCV18,使用 MPII 数据集训练完成。
!hub install human_pose_estimation_resnet50_mpii >log.log
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/setuptools/depends.py:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
/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#deprecations
  from 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
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/onnx/mapping.py:27: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  int(TensorProto.STRING): np.dtype(np.object)
[2022-05-03 23:56:11,218] [    INFO] - Successfully installed human_pose_estimation_resnet50_mpii-1.1.1
!hub list|grep human
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/setuptools/depends.py:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
/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#deprecations
  from 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
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/onnx/mapping.py:27: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  int(TensorProto.STRING): np.dtype(np.object)
|human_pose_estimation_res|/home/aistudio/.paddlehub/modules/human_pose_estim|


三、人体关键点检测示例


1.抓取视频


可以通过数据集中的小助手工具,下载抖音、西瓜视频、快手等小视频,特别是可以下载所需要的跳绳视频,具体演示如下:

image.png


2.关键点检测演示


针对下面这张图片做关键点检测,具体如下:

image.png

import cv2
import paddlehub as hub
pose_estimation = hub.Module(name="human_pose_estimation_resnet50_mpii")
image=cv2.imread('data/data143990/1.jpg')
results = pose_estimation.keypoint_detection(images=[image], visualization=True)
[2022-05-03 23:56:14,417] [ WARNING] - The _initialize method in HubModule will soon be deprecated, you can use the __init__() to handle the initialization of the object
W0503 23:56:14.420603    97 analysis_predictor.cc:1350] Deprecated. Please use CreatePredictor instead.
image saved in output_pose/ndarray_time=1651593374766039.jpg
# 打印关键点
print(results[0]['data'])
OrderedDict([('left_ankle', [104, 376]), ('left_knee', [107, 312]), 


查看output_pose 下输出的图片:

image.png


3.寻找转折点


众所周知,跳绳,人体每一帧盆骨点变化的时候算一次,那么可以通过下面方法来计算次数,具体如下:

# -*- coding: utf-8 -*-
# __author__:Livingbody
# 2022/5/2 21:26
import math
from matplotlib import pyplot as plt
import numpy as np
%matplotlib inline
def get_count(y):
    count = 0
    flag = False
    for i in range(len(y)-1):
        if y[i] < y[i + 1] and flag == False:
            continue
        elif y[i] > y[i + 1] and flag == True:
            continue
        else:
            print(i, y[i])
            count = count + 1
            flag = not flag
    return count
def get_count(y):
    count = 0
    flag = False
    for i in range(len(y)-1):
        if y[i] < y[i + 1] and flag == False:
            continue
        elif y[i] > y[i + 1] and flag == True:
            continue
        else:
            print(i, y[i])
            count = count + 1
            flag = not flag
    return count
if __name__ == '__main__':
    x = np.linspace(-10, 10, 500)
    y = np.sin(x * math.pi)
    # print(x, y)
    plt.figure(figsize=(12, 12))
    count = get_count(y)
    plt.title(f"point numbers: {math.floor(count/2)}")
    plt.plot(x, y)
    plt.show()
12 0.9982119222410882
37 -0.9985684620536466
62 0.9988854219322505
87 -0.999162789313664
112 0.9994005532039664
137 -0.9995987041789873
162 0.999757234384681
187 -0.9998761375374373
212 0.9999554089243304
237 -0.9999950454033061
262 0.9999950454033061
287 -0.9999554089243304
312 0.9998761375374373
337 -0.9997572343846811
362 0.9995987041789874
387 -0.9994005532039665
412 0.999162789313664
437 -0.9988854219322507
462 0.9985684620536466
487 -0.9982119222410885
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/cbook/__init__.py:2349: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  if isinstance(obj, collections.Iterator):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/cbook/__init__.py:2366: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  return list(data) if isinstance(data, collections.MappingView) else data

image.png


如上图所示,可以算出该曲线里有10次最高点,该方法可运用到跳绳计数中去。


四、跳绳检测


# -*- coding: utf-8 -*-
# __author__:Livingbody
# 2022/5/2 17:49
import cv2
import paddlehub as hub
if __name__ == "__main__":
    pose_estimation = hub.Module(name="human_pose_estimation_resnet50_mpii")
    flag = False
    count = 0
    flip_list = []
    # 可选择web视频流或者文件
    file_name = 'data/data143990/2.mp4'
    cap = cv2.VideoCapture(file_name)
    fourcc = cv2.VideoWriter_fourcc(*"mp4v")
    # out后期可以合成视频返回
    out = cv2.VideoWriter(
        file_name.replace(".mp4", "_output.mp4"),
        fourcc,
        20.0,
        (int(cap.get(3)), int(cap.get(4))), )
    while cap.isOpened():
        success, image = cap.read()
        if not success:
            break
        image_height, image_width, _ = image.shape
        image.flags.writeable = False
        results = pose_estimation.keypoint_detection(images=[image], visualization=True)
        # debug打印,可关闭
        # print(results)
        # print(results[0]['data'])
        # print(results[0]['data']['pelvis'])
        # print(results[0]['data']['left_hip'])
        # print(results[0]['data']['right_hip'])
        flip = results[0]['data']['pelvis'][1]
        flip_list.append(flip)
        # 如果超过2个点就开始比较
        if len(flip_list) < 2:
            continue
        prev_flip = flip_list[len(flip_list) - 2]
        # 开始进行判断计数
        if flip < prev_flip and flag == False:
            continue
        elif flip > prev_flip and flag == True:
            continue
        else:
            # print(flip)
            count = count + 1
            flag = not flag
        print(int(count/2))

输出示例:

image saved in output_pose/ndarray_time=1651593377511581.jpg
image saved in output_pose/ndarray_time=1651593378354247.jpg
0
image saved in output_pose/ndarray_time=1651593378987333.jpg
1
image saved in output_pose/ndarray_time=1651593379606857.jpg
1
image saved in output_pose/ndarray_time=1651593380213530.jpg
image saved in output_pose/ndarray_time=1651593380818746.jpg
image saved in output_pose/ndarray_time=1651593381474900.jpg
2
image saved in output_pose/ndarray_time=1651593382093679.jpg
2
image saved in output_pose/ndarray_time=1651593382712164.jpg
3
image saved in output_pose/ndarray_time=1651593383325455.jpg
3


五、下步打算


该项目抛砖引玉,供大家参考。


  • 加入可视化,实时显示关键点检测以及跳绳计数结果;
  • 拟采取paddlelite终端部署,或者paddlehub服务器部署调用,结合android客户端、或者电脑加摄像头实现实现方式来验证;
  • 数据下载软件已上传数据集,大家也可以动手试试。


目录
相关文章
|
13天前
|
存储 人工智能 Cloud Native
云栖重磅|从数据到智能:Data+AI驱动的云原生数据库
在9月20日2024云栖大会上,阿里云智能集团副总裁,数据库产品事业部负责人,ACM、CCF、IEEE会士(Fellow)李飞飞发表《从数据到智能:Data+AI驱动的云原生数据库》主题演讲。他表示,数据是生成式AI的核心资产,大模型时代的数据管理系统需具备多模处理和实时分析能力。阿里云瑶池将数据+AI全面融合,构建一站式多模数据管理平台,以数据驱动决策与创新,为用户提供像“搭积木”一样易用、好用、高可用的使用体验。
云栖重磅|从数据到智能:Data+AI驱动的云原生数据库
|
9天前
|
存储 XML 人工智能
深度解读AI在数字档案馆中的创新应用:高效识别与智能档案管理
基于OCR技术的纸质档案电子化方案,通过先进的AI能力平台,实现手写、打印、复古文档等多格式高效识别与智能归档。该方案大幅提升了档案管理效率,确保数据安全与隐私,为档案馆提供全面、智能化的电子化管理解决方案。
97 48
|
12天前
|
人工智能 数据挖掘 数据库
拥抱Data+AI|破解电商7大挑战,DMS+AnalyticDB助力企业智能决策
本文为数据库「拥抱Data+AI」系列连载第1篇,该系列是阿里云瑶池数据库面向各行业Data+AI应用场景,基于真实客户案例&最佳实践,展示Data+AI行业解决方案的连载文章。本篇内容针对电商行业痛点,将深入探讨如何利用数据与AI技术以及数据分析方法论,为电商行业注入新的活力与效能。
拥抱Data+AI|破解电商7大挑战,DMS+AnalyticDB助力企业智能决策
|
12天前
|
人工智能 数据库 决策智能
拥抱Data+AI|如何破解电商7大挑战?DMS+AnalyticDB助力企业智能决策
本文为阿里云瑶池数据库「拥抱Data+AI」系列连载第1篇,聚焦电商行业痛点,探讨如何利用数据与AI技术及分析方法论,为电商注入新活力与效能。文中详细介绍了阿里云Data+AI解决方案,涵盖Zero-ETL、实时在线分析、混合负载资源隔离、长周期数据归档等关键技术,帮助企业应对数据在线重刷、实时分析、成本优化等挑战,实现智能化转型。
拥抱Data+AI|如何破解电商7大挑战?DMS+AnalyticDB助力企业智能决策
|
2天前
|
人工智能 文字识别 运维
AI多模态的5大核心关键技术,让高端制造实现智能化管理
结合大模型应用场景,通过AI技术解析高端制造业的复杂设备与文档数据,自动化地将大型零件、机械图纸、操作手册等文档结构化。核心技术包括版面识别、表格抽取、要素抽取和文档抽取,实现信息的系统化管理和高效查询,大幅提升设备维护和生产管理的效率。
|
2天前
|
机器学习/深度学习 人工智能 安全
AI与旅游业:旅行规划的智能助手
在数字化浪潮中,人工智能(AI)正重塑旅游业。本文探讨了AI如何通过个性化推荐、智能预测与预警、语音交互与虚拟助手、增强现实体验及可持续发展,提升旅行规划的效率、安全性和趣味性,推动旅游业创新与变革。
|
5天前
|
人工智能 自然语言处理 关系型数据库
从数据到智能,一站式带你了解 Data+AI 精选解决方案、特惠权益
从 Data+AI 精选解决方案、特惠权益等,一站式带你了解阿里云瑶池数据库经典的AI产品服务与实践。
|
5天前
|
人工智能 安全 搜索推荐
AI与能源管理:智能电网的未来
本文探讨了AI与智能电网的融合及其对能源管理的深远影响。智能电网利用先进的信息、通信和AI技术,实现电力的自主、智能化、高效管理。AI在精准预测电力需求、实时监测与故障诊断、智能能源调度、个性化能源服务和优化可再生能源利用等方面发挥关键作用,推动能源管理的高效、智能和可持续发展。
|
6天前
|
机器学习/深度学习 人工智能 自然语言处理
AI与法律行业:智能法律咨询
在科技飞速发展的今天,人工智能(AI)正逐渐渗透到法律行业,特别是在智能法律咨询领域。本文探讨了AI在智能法律咨询中的应用现状、优势及挑战,并展望了其未来发展前景。AI技术通过大数据、自然语言处理等手段,提供高效、便捷、低成本且个性化的法律服务,但同时也面临数据隐私、法律伦理等问题。未来,AI将在技术升级、政策推动和融合创新中,为用户提供更加优质、便捷的法律服务。
|
8天前
|
机器学习/深度学习 人工智能 搜索推荐
AI在金融领域的应用:智能投资顾问
【10月更文挑战第31天】随着AI技术的快速发展,智能投资顾问在金融领域的应用越来越广泛。本文介绍了智能投资顾问的定义、工作原理、优势及未来发展趋势,探讨了其在个人财富管理、养老金管理、机构风险管理及量化交易中的典型应用,并分析了面临的挑战与机遇。智能投资顾问以其高效、低成本、个性化和全天候服务的特点,正逐步改变传统投资管理方式。

热门文章

最新文章