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

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值