• 姿态分析开源工具箱MMPose使用示例:人体姿势估计


          MMPose的介绍及安装参考:https://blog.csdn.net/fengbingchun/article/details/126676309,这里给出人体姿势估计的测试代码,论文:《Deep high-resolution representation learning for human pose estimation》:

          (1).准备测试图像:原始图像来自网络

    1. image_path = "../../data/image/"
    2. image_name = "human.png"

          (2).通过MMDetection模块检测人体框:注,为了去除伪人体框,这里设置了一个阈值,只有大于此阈值的框才作为后面的人体姿势估计

    1. def mmdet_human_detection(device, image, threshold=0.9):
    2. path = "../../data/model/"
    3. checkpoint = "faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth"
    4. url = "https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth"
    5. download_checkpoint(path, checkpoint, url)
    6. config = "../../src/mmpose/demo/mmdetection_cfg/faster_rcnn_r50_fpn_coco.py"
    7. model = init_detector(config, path+checkpoint, device)
    8. mmdet_results = inference_detector(model, image)
    9. # print(mmdet_results)
    10. human_results = process_mmdet_results(mmdet_results)
    11. # print(human_results)
    12. filter_results = []
    13. mat = cv2.imread(image)
    14. for result in human_results:
    15. print("result:", result)
    16. if result['bbox'][4] > threshold:
    17. filter_results.append(result)
    18. cv2.rectangle(mat, (int(result['bbox'][0]), int(result['bbox'][1])), (int(result['bbox'][2]), int(result['bbox'][3])), (255, 0, 0), 1)
    19. cv2.imwrite("../../data/result_mmpose_2d_human_detection.png", mat)
    20. cv2.imshow("show", mat)
    21. cv2.waitKey(0)
    22. return filter_results

     

          (3).下载人体姿势估计模型: 

    1. def download_checkpoint(path, name, url):
    2. if os.path.isfile(path+name) == False:
    3. print("checkpoint(model) file does not exist, now download ...")
    4. subprocess.run(["wget", "-P", path, url])
    5. path = "../../data/model/"
    6. checkpoint = "hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth"
    7. url = "https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth"
    8. download_checkpoint(path, checkpoint, url)

          (4).根据配置文件和checkpoint文件构建人体估计模型:

    1. config = "../../src/mmpose/configs/body/2d_kpt_sview_rgb_img/topdown_heatmap/coco/hrnet_w48_coco_256x192.py"
    2. model = init_pose_model(config, path+checkpoint, device)

          (5).进行人体姿势估计推理,输入包括检测到的人体框:

    1. pose_results, returned_outputs = inference_top_down_pose_model(model, image, human_bbox_results, bbox_thr=None, format='xyxy')
    2. print(pose_results)

          (6).显示及保存结果:

    vis_pose_result(model, image, pose_results, radius=1, thickness=1, show=True, out_file="../../data/result_mmpose_2d_human_pose_estimation.png")

          执行结果如下图所示: 

          GitHub: https://github.com/fengbingchun/PyTorch_Test

  • 相关阅读:
    踩雷react-useRef钩子函数
    PNG怎么转成PDF格式?这两种方法一定要尝试一下
    从零开始搭建一个组件库(二)
    2023年云南省职业院校技能大赛中职组“网络安全”赛项样题
    go的日志库logrus
    基于ssm+vue员工工资管理系统
    【附源码】Python计算机毕业设计天润律师事务所管理系统
    【JVM】java中char,boolean,short,byte在存储时会自动转换成int类型的原理
    Jenkins学习笔记5
    技术干货 | MindSpore AI科学计算系列(四):AlphaFold2分析
  • 原文地址:https://blog.csdn.net/fengbingchun/article/details/126677075