当前位置: 首页 > news >正文

姿态分析开源工具箱MMPose使用示例:人体姿势估计

      MMPose的介绍及安装参考:https://blog.csdn.net/fengbingchun/article/details/126676309,这里给出人体姿势估计的测试代码,论文:《Deep high-resolution representation learning for human pose estimation》:

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

image_path = "../../data/image/"
image_name = "human.png"

      (2).通过MMDetection模块检测人体框:注,为了去除伪人体框,这里设置了一个阈值,只有大于此阈值的框才作为后面的人体姿势估计

def mmdet_human_detection(device, image, threshold=0.9):
	path = "../../data/model/"
	checkpoint = "faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth"
	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"
	download_checkpoint(path, checkpoint, url)

	config = "../../src/mmpose/demo/mmdetection_cfg/faster_rcnn_r50_fpn_coco.py"
	model = init_detector(config, path+checkpoint, device)

	mmdet_results = inference_detector(model, image)
	# print(mmdet_results)

	human_results = process_mmdet_results(mmdet_results)
	# print(human_results)

	filter_results = []
	mat = cv2.imread(image)
	for result in human_results:
		print("result:", result)
		if result['bbox'][4] > threshold:
			filter_results.append(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_human_detection.png", mat)
	cv2.imshow("show", mat)
	cv2.waitKey(0)

	return filter_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 = "hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth"
url = "https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth"
download_checkpoint(path, checkpoint, url)

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

config = "../../src/mmpose/configs/body/2d_kpt_sview_rgb_img/topdown_heatmap/coco/hrnet_w48_coco_256x192.py"
model = init_pose_model(config, path+checkpoint, device)

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

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

      执行结果如下图所示: 

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

相关文章:

  • 如何安装虚拟机
  • ICP问题 SVD方法推导(Markdown版)
  • java基于ssm+vue+elementui的水果生鲜销售购物商城
  • kafka知识点总结
  • 【vue3】06. 跟着官网学习vue3
  • 任务十一 BERT
  • MyBatis实现多层级collection嵌套查询
  • Containerd【轻量级容器管理工具】
  • 计算机毕业设计ssm+vue基本微信小程序的图书馆座位管理系统
  • 腾讯核心高级架构师汇总Java全栈知识点笔记,“吃透”后成功上岸!
  • 169.多数元素
  • webpack拓展篇(六十七):webpack5 新特性解析
  • CF515E Drazil and Park【思维+线段树】
  • CodeForces 1717E【线性筛】
  • Java程序猿搬砖笔记(九)
  • __proto__ 和 prototype的关系
  • 【笔记】你不知道的JS读书笔记——Promise
  • 10个确保微服务与容器安全的最佳实践
  • Angular Elements 及其运作原理
  • CSS选择器——伪元素选择器之处理父元素高度及外边距溢出
  • E-HPC支持多队列管理和自动伸缩
  • go append函数以及写入
  • IE报vuex requires a Promise polyfill in this browser问题解决
  • JavaScript 基本功--面试宝典
  • Java精华积累:初学者都应该搞懂的问题
  • js 实现textarea输入字数提示
  • JS+CSS实现数字滚动
  • js数组之filter
  • Laravel5.4 Queues队列学习
  • leetcode46 Permutation 排列组合
  • Netty 框架总结「ChannelHandler 及 EventLoop」
  • PAT A1017 优先队列
  • python学习笔记 - ThreadLocal
  • SAP云平台里Global Account和Sub Account的关系
  • supervisor 永不挂掉的进程 安装以及使用
  • win10下安装mysql5.7
  • 关于Android中设置闹钟的相对比较完善的解决方案
  • 爬虫进阶 -- 神级程序员:让你的爬虫就像人类的用户行为!
  • 如何合理的规划jvm性能调优
  • 深度学习入门:10门免费线上课程推荐
  • 使用权重正则化较少模型过拟合
  • ​业务双活的数据切换思路设计(下)
  • #define与typedef区别
  • #pragma multi_compile #pragma shader_feature
  • $Django python中使用redis, django中使用(封装了),redis开启事务(管道)
  • (2)MFC+openGL单文档框架glFrame
  • (2)nginx 安装、启停
  • (2020)Java后端开发----(面试题和笔试题)
  • (6)添加vue-cookie
  • (ZT) 理解系统底层的概念是多么重要(by趋势科技邹飞)
  • (附源码)基于SSM多源异构数据关联技术构建智能校园-计算机毕设 64366
  • (十)c52学习之旅-定时器实验
  • (四) Graphivz 颜色选择
  • (四)Android布局类型(线性布局LinearLayout)
  • (转) Android中ViewStub组件使用