• 姿态分析开源工具箱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

  • 相关阅读:
    Go 语言入门指南:基础语法和常用特性解析
    Makefile文件详解
    shiro学习之HashedCredentialsMatcher密码匹配过程
    Mysql 中 “必知” 的单行处理函数
    [CMake] CMake 基础命令
    Ubuntu(WSL) 安装最新版本的 GCC
    Nginx学习笔记11——防盗链与http的referer
    NPM私服搭建(verdaccio)
    AI再度升级,IT业一片哀鸿遍野:程序员真的要失业了吗?
    webrtc
  • 原文地址:https://blog.csdn.net/fengbingchun/article/details/126677075