前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MMSkeleton 快速开始,使用 WebCam 测试

MMSkeleton 快速开始,使用 WebCam 测试

作者头像
GoCoding
发布2021-05-06 14:40:21
1.2K0
发布2021-05-06 14:40:21
举报
文章被收录于专栏:GoCoding

本文将引导快速使用 MMSkeleton ,介绍用摄像头测试实时姿态估计。

  • MMSkeleton: https://github.com/open-mmlab/mmskeleton

安装

首先安装 MMDetection ,可见 MMDetection 使用

然后安装 MMSkeleton ,

代码语言:javascript
复制
# 启用 Python 虚拟环境
conda activate open-mmlab

# 下载 MMSkeleton
git clone https://github.com/open-mmlab/mmskeleton.git
cd mmskeleton

# 安装 MMSkeleton
python setup.py develop

# 安装 nms op for person estimation
cd mmskeleton/ops/nms/
python setup_linux.py develop
cd ../../../

现有模型,视频测试

配置

configs/pose_estimation/pose_demo.yaml:

代码语言:javascript
复制
processor_cfg:
  video_file: resource/data_example/ta_chi.mp4
  detection_cfg:
    model_cfg: ../mmdetection/configs/cascade_rcnn/cascade_rcnn_r50_fpn_1x_coco.py
    checkpoint_file: ../mmdetection/checkpoints/cascade_rcnn_r50_fpn_1x_coco_20200316-3dc56deb.pth
    bbox_thre: 0.8

选用的检测模型,如下:

  • Cascade R-CNN, R-50-FPN, 1x
    • config: https://github.com/open-mmlab/mmdetection/tree/master/configs/cascade_rcnn/cascade_rcnn_r50_fpn_1x_coco.py
    • model: http://download.openmmlab.com/mmdetection/v2.0/cascade_rcnn/cascade_rcnn_r50_fpn_1x_coco/cascade_rcnn_r50_fpn_1x_coco_20200316-3dc56deb.pth

运行

代码语言:javascript
复制
# verify that mmskeleton and mmdetection installed correctly
# python mmskl.py pose_demo [--gpus $GPUS]
python mmskl.py pose_demo --gpus 1

结果将会存到 work_dir/pose_demo/ta_chi.mp4

现有模型,WebCam 测试

配置

configs/apis/pose_estimator.cascade_rcnn+hrnet.yaml:

代码语言:javascript
复制
detection_cfg:
  model_cfg: mmdetection/configs/cascade_rcnn/cascade_rcnn_r50_fpn_1x_coco.py
  checkpoint_file: mmdetection/checkpoints/cascade_rcnn_r50_fpn_1x_coco_20200316-3dc56deb.pth
  bbox_thre: 0.8
estimation_cfg:
  model_cfg: mmskeleton/configs/pose_estimation/hrnet/pose_hrnet_w32_256x192_test.yaml
  checkpoint_file: mmskeleton://pose_estimation/pose_hrnet_w32_256x192
  data_cfg:
    image_size:
      - 192
      - 256
    pixel_std: 200
    image_mean:
      - 0.485
      - 0.456
      - 0.406
    image_std:
      - 0.229
      - 0.224
      - 0.225
    post_process: true

确认 detection_cfg estimation_cfg 的路径正确。

写码

编写 webcam.py,主要代码如下:

  • webcam.py: https://github.com/ikuokuo/start-deep-learning/blob/master/research/MMSkeleton/webcam.py
代码语言:javascript
复制
def main():
  args = parse_args()

  win_name = args.win_name
  cv.namedWindow(win_name, cv.WINDOW_NORMAL)

  with Camera(args.cam_idx, args.cam_width, args.cam_height, args.cam_fps) as cam:
    cfg = mmcv.Config.fromfile(args.cfg_file)
    detection_cfg = cfg["detection_cfg"]

    print("Loading model ...")
    model = init_pose_estimator(**cfg, device=0)
    print("Loading model done")

    for frame in cam.reads():
      res = inference_pose_estimator(model, frame)

      res_image = pose_demo.render(
          frame, res["joint_preds"], res["person_bbox"],
          detection_cfg.bbox_thre)

      cv.imshow(win_name, res_image)

      key = cv.waitKey(1) & 0xFF
      if key == 27 or key == ord("q"):
        break

  cv.destroyAllWindows()

运行

代码语言:javascript
复制
$ python webcam.py \
--cam_idx 2 --cam_width 640 --cam_height 480 --cam_fps 10 \
--cfg_file configs/apis/pose_estimator.cascade_rcnn+hrnet.yaml
Args
  win_name: webcam
  cam_idx: 2
  cam_width: 640
  cam_height: 480
  cam_fps: 10
  cfg_file: configs/apis/pose_estimator.cascade_rcnn+hrnet.yaml
CAM: 640.0x480.0 10.0
Loading model ...
Loading model done

效果,

摄像头参数,可见该文文末的 WebCam 摄像头使用

更多

  • Awesome Human Pose Estimation https://github.com/wangzheallen/awesome-human-pose-estimation
  • Awesome Skeleton based Action Recognition https://github.com/niais/Awesome-Skeleton-based-Action-Recognition
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-01-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 GoCoding 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 安装
  • 现有模型,视频测试
    • 配置
      • 运行
      • 现有模型,WebCam 测试
        • 配置
          • 写码
            • 运行
            • 更多
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档