• 姿态分析开源工具箱MMPose使用示例:2d手势估计


          MMPose的介绍及安装参考:https://blog.csdn.net/fengbingchun/article/details/126676309,这里给出2d手势估计的测试代码,论文:《Simple Baselines for Human Pose Estimation and Tracking》:

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

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

          (2).通过MMDetection模块检测手:

    1. def mmdet_hand_detection(device, image):
    2. path = "../../data/model/"
    3. checkpoint = "cascade_rcnn_x101_64x4d_fpn_20e_onehand10k-dac19597_20201030.pth"
    4. url = "https://download.openmmlab.com/mmpose/mmdet_pretrained/cascade_rcnn_x101_64x4d_fpn_20e_onehand10k-dac19597_20201030.pth"
    5. download_checkpoint(path, checkpoint, url)
    6. config = "../../src/mmpose/demo/mmdetection_cfg/cascade_rcnn_x101_64x4d_fpn_1class.py"
    7. model = init_detector(config, path+checkpoint, device)
    8. mmdet_results = inference_detector(model, image)
    9. # print(mmdet_results)
    10. hand_results = process_mmdet_results(mmdet_results)
    11. mat = cv2.imread(image)
    12. for result in hand_results:
    13. print("result:", result)
    14. cv2.rectangle(mat, (int(result['bbox'][0]), int(result['bbox'][1])), (int(result['bbox'][2]), int(result['bbox'][3])), (255, 0, 0), 1)
    15. cv2.imwrite("../../data/result_mmpose_2d_hand_detection.png", mat)
    16. cv2.imshow("show", mat)
    17. cv2.waitKey(0)
    18. return hand_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 = "res50_onehand10k_256x256-e67998f6_20200813.pth"
    7. url = "https://download.openmmlab.com/mmpose/top_down/resnet/res50_onehand10k_256x256-e67998f6_20200813.pth"
    8. download_checkpoint(path, checkpoint, url)

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

    1. config = "../../src/mmpose/configs/hand/2d_kpt_sview_rgb_img/topdown_heatmap/onehand10k/res50_onehand10k_256x256.py"
    2. model = init_pose_model(config, path+checkpoint, device)

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

    1. pose_results, returned_outputs = inference_top_down_pose_model(model, image, hand_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_hand_pose_estimation.png")

          执行结果如下图所示:

     

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

  • 相关阅读:
    Selenium4+Python3系列(十) - Page Object设计模式
    CSS 实现动态显示隐藏(:checked 和 :target 的妙用)
    业务中台(功能编排+领域模型的结合)-spider-node
    面试经典 150 题 2 —(滑动窗口)— 3. 无重复字符的最长子串
    Linux系统安全及应用(1)
    LVS+Keepalived群集
    视频分割合并工具说明
    SQL基础理论篇(六):多表的连接方式
    【JS】Chapter10-Bom 操作
    ChatGPT、GPT-4 Turbo接口调用(stream模式)
  • 原文地址:https://blog.csdn.net/fengbingchun/article/details/126676729