当前位置:   article > 正文

2d关键点可视化 coco转h36m人体关键点

2d关键点可视化 coco转h36m人体关键点

目录

coco转h36m人体关键点

opencv 2d关键点可视化


coco转h36m人体关键点

mhformer中有

  1. def h36m_coco_format(keypoints, scores):
  2. assert len(keypoints.shape) == 4 and len(scores.shape) == 3
  3. h36m_kpts = []
  4. h36m_scores = []
  5. valid_frames = []
  6. for i in range(keypoints.shape[0]):
  7. kpts = keypoints[i]
  8. score = scores[i]
  9. new_score = np.zeros_like(score, dtype=np.float32)
  10. if np.sum(kpts) != 0.:
  11. kpts, valid_frame = coco_h36m(kpts)
  12. h36m_kpts.append(kpts)
  13. valid_frames.append(valid_frame)
  14. new_score[:, h36m_coco_order] = score[:, coco_order]
  15. new_score[:, 0] = np.mean(score[:, [11, 12]], axis=1, dtype=np.float32)
  16. new_score[:, 8] = np.mean(score[:, [5, 6]], axis=1, dtype=np.float32)
  17. new_score[:, 7] = np.mean(new_score[:, [0, 8]], axis=1, dtype=np.float32)
  18. new_score[:, 10] = np.mean(score[:, [1, 2, 3, 4]], axis=1, dtype=np.float32)
  19. h36m_scores.append(new_score)
  20. h36m_kpts = np.asarray(h36m_kpts, dtype=np.float32)
  21. h36m_scores = np.asarray(h36m_scores, dtype=np.float32)
  22. return h36m_kpts, h36m_scores, valid_frames

opencv 2d关键点可视化

  1. import numpy as np
  2. import cv2
  3. import numpy as np
  4. import json
  5. kpt_color_map = {'h': {'id': 0, 'color': [255, 0, 0], 'radius': 3, 'thickness': -1}, 'tail': {'id': 1, 'color': [0, 255, 0], 'radius': 2, 'thickness': -1}}
  6. # 点类别文字
  7. kpt_labelstr = {'font_size': 1, # 字体大小
  8. 'font_thickness': 3, # 字体粗细
  9. 'offset_x': 20, # X 方向,文字偏移距离,向右为正
  10. 'offset_y': 10, # Y 方向,文字偏移距离,向下为正
  11. }
  12. labelme_path = r'E:\data\new_path\635_5225_02-1\input\0000.json'
  13. with open(labelme_path, 'r', encoding='utf-8') as f:
  14. labelme = json.load(f)
  15. img_bgr=cv2.imread(r'E:\data\new_path\635_5225_02-1\input\0000.png')
  16. for each_ann in labelme['shapes']: # 遍历每一个标注
  17. kpt_label = each_ann['label'] # 该点的类别
  18. for point in each_ann['points']:
  19. kpt_xy = point
  20. kpt_x, kpt_y = int(kpt_xy[0]), int(kpt_xy[1])
  21. # 该点的可视化配置
  22. kpt_color = kpt_color_map[kpt_label]['color'] # 颜色
  23. kpt_radius = kpt_color_map[kpt_label]['radius'] # 半径
  24. kpt_thickness = kpt_color_map[kpt_label]['thickness'] # 线宽(-1代表填充)
  25. # 画圆:画该关键点
  26. img_bgr = cv2.circle(img_bgr, (kpt_x, kpt_y), kpt_radius, kpt_color, kpt_thickness)
  27. # 写该点类别文字:图片,文字字符串,文字左上角坐标,字体,字体大小,颜色,字体粗细
  28. img_bgr = cv2.putText(img_bgr, kpt_label, (kpt_x + kpt_labelstr['offset_x'], kpt_y + kpt_labelstr['offset_y']), cv2.FONT_HERSHEY_SIMPLEX, kpt_labelstr['font_size'], kpt_color, kpt_labelstr['font_thickness'])
  29. cv2.imshow('img',img_bgr)
  30. cv2.waitKey(0)

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/article/detail/45058
推荐阅读
相关标签
  

闽ICP备14008679号