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

目录

coco转h36m人体关键点

[opencv 2d关键点可视化](#opencv 2d关键点可视化)


coco转h36m人体关键点

mhformer中有

python 复制代码
def h36m_coco_format(keypoints, scores):
    assert len(keypoints.shape) == 4 and len(scores.shape) == 3

    h36m_kpts = []
    h36m_scores = []
    valid_frames = []

    for i in range(keypoints.shape[0]):
        kpts = keypoints[i]
        score = scores[i]

        new_score = np.zeros_like(score, dtype=np.float32)

        if np.sum(kpts) != 0.:
            kpts, valid_frame = coco_h36m(kpts)
            h36m_kpts.append(kpts)
            valid_frames.append(valid_frame)

            new_score[:, h36m_coco_order] = score[:, coco_order]
            new_score[:, 0] = np.mean(score[:, [11, 12]], axis=1, dtype=np.float32)
            new_score[:, 8] = np.mean(score[:, [5, 6]], axis=1, dtype=np.float32)
            new_score[:, 7] = np.mean(new_score[:, [0, 8]], axis=1, dtype=np.float32)
            new_score[:, 10] = np.mean(score[:, [1, 2, 3, 4]], axis=1, dtype=np.float32)

            h36m_scores.append(new_score)

    h36m_kpts = np.asarray(h36m_kpts, dtype=np.float32)
    h36m_scores = np.asarray(h36m_scores, dtype=np.float32)

    return h36m_kpts, h36m_scores, valid_frames

opencv 2d关键点可视化

python 复制代码
import numpy as np


import cv2
import numpy as np
import json


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}}

# 点类别文字
kpt_labelstr = {'font_size': 1,  # 字体大小
    'font_thickness': 3,  # 字体粗细
    'offset_x': 20,  # X 方向,文字偏移距离,向右为正
    'offset_y': 10,  # Y 方向,文字偏移距离,向下为正
}

labelme_path = r'E:\data\new_path\635_5225_02-1\input\0000.json'
with open(labelme_path, 'r', encoding='utf-8') as f:
    labelme = json.load(f)

img_bgr=cv2.imread(r'E:\data\new_path\635_5225_02-1\input\0000.png')

for each_ann in labelme['shapes']:  # 遍历每一个标注


    kpt_label = each_ann['label']  # 该点的类别

    for point in each_ann['points']:
        kpt_xy = point
        kpt_x, kpt_y = int(kpt_xy[0]), int(kpt_xy[1])

        # 该点的可视化配置
        kpt_color = kpt_color_map[kpt_label]['color']  # 颜色
        kpt_radius = kpt_color_map[kpt_label]['radius']  # 半径
        kpt_thickness = kpt_color_map[kpt_label]['thickness']  # 线宽(-1代表填充)

        # 画圆:画该关键点
        img_bgr = cv2.circle(img_bgr, (kpt_x, kpt_y), kpt_radius, kpt_color, kpt_thickness)

        # 写该点类别文字:图片,文字字符串,文字左上角坐标,字体,字体大小,颜色,字体粗细
        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'])

cv2.imshow('img',img_bgr)
cv2.waitKey(0)
相关推荐
千宇宙航4 小时前
闲庭信步使用图像验证平台加速FPGA的开发:第十四课——图像二值化的FPGA实现
图像处理·计算机视觉·fpga开发
橡晟4 小时前
深度学习入门:让神经网络变得“深不可测“⚡(二)
人工智能·python·深度学习·机器学习·计算机视觉
墨尘游子4 小时前
神经网络的层与块
人工智能·python·深度学习·机器学习
Leah01054 小时前
什么是神经网络,常用的神经网络,如何训练一个神经网络
人工智能·深度学习·神经网络·ai
PyAIExplorer4 小时前
图像亮度调整的简单实现
人工智能·计算机视觉
Striker_Eureka5 小时前
DiffDet4SAR——首次将扩散模型用于SAR图像目标检测,来自2024 GRSL(ESI高被引1%论文)
人工智能·目标检测
Rvelamen6 小时前
LLM-SECURITY-PROMPTS大模型提示词攻击测评基准
人工智能·python·安全
AI technophile6 小时前
OpenCV计算机视觉实战(15)——霍夫变换详解
人工智能·opencv·计算机视觉
JNU freshman7 小时前
计算机视觉 之 数字图像处理基础(一)
人工智能·计算机视觉
千宇宙航7 小时前
闲庭信步使用图像验证平台加速FPGA的开发:第十五课——基于sobel算子边缘检测的FPGA实现
图像处理·计算机视觉·fpga开发