姿态分析开源工具箱MMPose使用示例:2d手势估计
Posted fengbingchun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了姿态分析开源工具箱MMPose使用示例:2d手势估计相关的知识,希望对你有一定的参考价值。
MMPose的介绍及安装参考:https://blog.csdn.net/fengbingchun/article/details/126676309,这里给出2d手势估计的测试代码,论文:《Simple Baselines for Human Pose Estimation and Tracking》:
(1).准备测试图像:原始图像来自网络
image_path = "../../data/image/"
image_name = "hand.png"
(2).通过MMDetection模块检测手:
def mmdet_hand_detection(device, image):
path = "../../data/model/"
checkpoint = "cascade_rcnn_x101_64x4d_fpn_20e_onehand10k-dac19597_20201030.pth"
url = "https://download.openmmlab.com/mmpose/mmdet_pretrained/cascade_rcnn_x101_64x4d_fpn_20e_onehand10k-dac19597_20201030.pth"
download_checkpoint(path, checkpoint, url)
config = "../../src/mmpose/demo/mmdetection_cfg/cascade_rcnn_x101_64x4d_fpn_1class.py"
model = init_detector(config, path+checkpoint, device)
mmdet_results = inference_detector(model, image)
# print(mmdet_results)
hand_results = process_mmdet_results(mmdet_results)
mat = cv2.imread(image)
for result in hand_results:
print("result:", result)
cv2.rectangle(mat, (int(result['bbox'][0]), int(result['bbox'][1])), (int(result['bbox'][2]), int(result['bbox'][3])), (255, 0, 0), 1)
cv2.imwrite("../../data/result_mmpose_2d_hand_detection.png", mat)
cv2.imshow("show", mat)
cv2.waitKey(0)
return hand_results
(3).下载手势估计模型:
def download_checkpoint(path, name, url):
if os.path.isfile(path+name) == False:
print("checkpoint(model) file does not exist, now download ...")
subprocess.run(["wget", "-P", path, url])
path = "../../data/model/"
checkpoint = "res50_onehand10k_256x256-e67998f6_20200813.pth"
url = "https://download.openmmlab.com/mmpose/top_down/resnet/res50_onehand10k_256x256-e67998f6_20200813.pth"
download_checkpoint(path, checkpoint, url)
(4).根据配置文件和checkpoint文件构建手势估计模型:
config = "../../src/mmpose/configs/hand/2d_kpt_sview_rgb_img/topdown_heatmap/onehand10k/res50_onehand10k_256x256.py"
model = init_pose_model(config, path+checkpoint, device)
(5).进行手势估计推理,输入包括检测到的手框
pose_results, returned_outputs = inference_top_down_pose_model(model, image, hand_bbox_results, bbox_thr=None, format='xyxy')
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
以上是关于姿态分析开源工具箱MMPose使用示例:2d手势估计的主要内容,如果未能解决你的问题,请参考以下文章