FreiHAND (handposeX-json 格式)数据集-release >> DataBall

news/2025/2/26 23:23:42

FreiHANDhandposeX-json>handposeX-json 格式)数据集-release

注意:

1)为了方便使用,按照 handposeX json 自定义格式存储

2)使用常见依赖库进行调用,降低数据集使用难度。

3)部分数据集获取请加入:DataBall-X数据球(free)

4)完整数据集获取请加入:DataBall-X数据球(vip)

FreiHAND 数据集官方项目地址:https://github.com/lmb-freiburg/freihand

handposeX-json>handposeX-json 格式 项目地址:GitHub - XIAN-HHappy/handpose_x_plus

---------------

一、handposeX json 格式示例

cx,cy,fx,fy为相机内参。

label:左右手标签

joint3d:三维手部21关键点

vertex3d:三维手mesh网格点

{

"author": "XIAN",

"img_name:": "",

"cx": 112.0,

"cy": 112.0,

"fx": 388.9018310596544,

"fy": 388.71231836584275,

"hands": [

{

"label": "right",

"joint3d": [

[

29.402047395706177,

-27.920207008719444,

587.0807766914368

],

······

],

"vertex3d": [

[

10.056010007858276,

29.915300235152245,

-626.9440693855286

],

······

]

}

]

}

---------------

二、脚本运行

cd script/FreiHAND

python read_handposex_json.py

read_handposex_json.py具体实现如下,简洁明了:

#-*-coding:utf-8-*-
# date:2024-02-23
# Author: XIAN
# function: handposeX json 格式读取数据标签
import sys
sys.path.append("./")
import os
import cv2
import json
import numpy as np
import random
'''
function: 绘制二维关键点连线
'''
def draw_joints(img_,hand_,x,y):
    thick = 2
    colors = [(0,215,255),(255,115,55),(5,255,55),(25,15,255),(225,15,55)]
    #
    cv2.line(img_, (int(hand_['0']['x']+x), int(hand_['0']['y']+y)),(int(hand_['1']['x']+x), int(hand_['1']['y']+y)), colors[0], thick)
    cv2.line(img_, (int(hand_['1']['x']+x), int(hand_['1']['y']+y)),(int(hand_['2']['x']+x), int(hand_['2']['y']+y)), colors[0], thick)
    cv2.line(img_, (int(hand_['2']['x']+x), int(hand_['2']['y']+y)),(int(hand_['3']['x']+x), int(hand_['3']['y']+y)), colors[0], thick)
    cv2.line(img_, (int(hand_['3']['x']+x), int(hand_['3']['y']+y)),(int(hand_['4']['x']+x), int(hand_['4']['y']+y)), colors[0], thick)

    cv2.line(img_, (int(hand_['0']['x']+x), int(hand_['0']['y']+y)),(int(hand_['5']['x']+x), int(hand_['5']['y']+y)), colors[1], thick)
    cv2.line(img_, (int(hand_['5']['x']+x), int(hand_['5']['y']+y)),(int(hand_['6']['x']+x), int(hand_['6']['y']+y)), colors[1], thick)
    cv2.line(img_, (int(hand_['6']['x']+x), int(hand_['6']['y']+y)),(int(hand_['7']['x']+x), int(hand_['7']['y']+y)), colors[1], thick)
    cv2.line(img_, (int(hand_['7']['x']+x), int(hand_['7']['y']+y)),(int(hand_['8']['x']+x), int(hand_['8']['y']+y)), colors[1], thick)

    cv2.line(img_, (int(hand_['0']['x']+x), int(hand_['0']['y']+y)),(int(hand_['9']['x']+x), int(hand_['9']['y']+y)), colors[2], thick)
    cv2.line(img_, (int(hand_['9']['x']+x), int(hand_['9']['y']+y)),(int(hand_['10']['x']+x), int(hand_['10']['y']+y)), colors[2], thick)
    cv2.line(img_, (int(hand_['10']['x']+x), int(hand_['10']['y']+y)),(int(hand_['11']['x']+x), int(hand_['11']['y']+y)), colors[2], thick)
    cv2.line(img_, (int(hand_['11']['x']+x), int(hand_['11']['y']+y)),(int(hand_['12']['x']+x), int(hand_['12']['y']+y)), colors[2], thick)

    cv2.line(img_, (int(hand_['0']['x']+x), int(hand_['0']['y']+y)),(int(hand_['13']['x']+x), int(hand_['13']['y']+y)), colors[3], thick)
    cv2.line(img_, (int(hand_['13']['x']+x), int(hand_['13']['y']+y)),(int(hand_['14']['x']+x), int(hand_['14']['y']+y)), colors[3], thick)
    cv2.line(img_, (int(hand_['14']['x']+x), int(hand_['14']['y']+y)),(int(hand_['15']['x']+x), int(hand_['15']['y']+y)), colors[3], thick)
    cv2.line(img_, (int(hand_['15']['x']+x), int(hand_['15']['y']+y)),(int(hand_['16']['x']+x), int(hand_['16']['y']+y)), colors[3], thick)

    cv2.line(img_, (int(hand_['0']['x']+x), int(hand_['0']['y']+y)),(int(hand_['17']['x']+x), int(hand_['17']['y']+y)), colors[4], thick)
    cv2.line(img_, (int(hand_['17']['x']+x), int(hand_['17']['y']+y)),(int(hand_['18']['x']+x), int(hand_['18']['y']+y)), colors[4], thick)
    cv2.line(img_, (int(hand_['18']['x']+x), int(hand_['18']['y']+y)),(int(hand_['19']['x']+x), int(hand_['19']['y']+y)), colors[4], thick)
    cv2.line(img_, (int(hand_['19']['x']+x), int(hand_['19']['y']+y)),(int(hand_['20']['x']+x), int(hand_['20']['y']+y)), colors[4], thick)
'''
function: 21个三维关键点转为二维点,并进行绘制
'''
def Draw_KeyPoints3D(img,Joints_,fx,fy,cx,cy):
    #----------------------------------- 计算 3D到 2D相机的投影
    X = Joints_[:,0]
    Y = Joints_[:,1]
    Z = Joints_[:,2]
    x_p = X / Z
    y_p = Y / Z
    #三维点转为二维点
    x_2d = fx* x_p + cx
    y_2d = fy* y_p + cy
    pts2d_list = {}
    pts2d_ss = []
    for ii in range(x_2d.shape[0]):
        x_,y_ = x_2d[ii],y_2d[ii]
        pts2d_list[str(ii)]={"x":x_,"y":y_}
        cv2.circle(img, (int(x_),int(y_)), 4, (25,155,255), -1)
        cv2.circle(img, (int(x_),int(y_)), 2, (255,0,55), -1)
        pts2d_ss.append((x_,y_))

    draw_joints(img,pts2d_list,0,0)
    pts2d_ss = np.array(pts2d_ss)
    return pts2d_ss

def Draw_Vertex_KeyPoints(img,img_mesh,Vertex,fx_d,fy_d,cx_d,cy_d,triangles_index,RGB_ = (245, 125, 35)):
    #----------------------------------- 计算 Mano 到 相机的投影
    Xdc = -Vertex[:,0].reshape(-1)
    Ydc = -Vertex[:,1].reshape(-1)
    Zdc = -Vertex[:,2].reshape(-1)

    x_mano_p = Xdc / Zdc
    y_mano_p = Ydc / Zdc
    #点云转为二维图

    x_mano = fx_d* x_mano_p + cx_d
    y_mano = fy_d* y_mano_p + cy_d
    manopts_list = []

    mesh_list = []
    color_rr = (random.randint(100,230),random.randint(120,250),random.randint(100,240))
    for ii in range(triangles_index.shape[0]):
        a,b,c = triangles_index[ii]

        x1_,y1_ = x_mano[a].astype(np.int32),y_mano[a].astype(np.int32)
        x2_,y2_ = x_mano[b].astype(np.int32),y_mano[b].astype(np.int32)
        x3_,y3_ = x_mano[c].astype(np.int32),y_mano[c].astype(np.int32)

        area_ = np.array([[int(x1_), int(y1_)], [int(x2_), int(y2_)], [int(x3_),int(y3_)]])
        color_ = (255, 0, 0)
        # cv2.fillPoly(mask_v, [area_], (255))
        cv2.fillPoly(img_mesh, [area_], color_rr)
        mesh_list.append(area_)
    cv2.fillPoly(img, mesh_list, RGB_)
if __name__ == '__main__':
    path_root = "datasets/"
    path_s_image = "{}/image/".format(path_root)
    path_s_label = "{}/label/".format(path_root)

    triangles_index = np.load("../../config/triangles_index.npy").reshape(-1,3)

    out_cnt = 0
    hand_cnt = 0
    for f_ in os.listdir(path_s_image):
        path_img = path_s_image + f_
        path_json = path_s_label + f_.replace(".jpg",".json")

        with open(path_json, 'r', encoding='utf-8') as file:
            data_json = json.load(file)
        hands_json = data_json["hands"]
        cx,cy,fx,fy = data_json["cx"],data_json["cy"],data_json["fx"],data_json["fy"]

        img_ = cv2.imread(path_img)
        img_joint = img_.copy()
        img_mesh = img_.copy()
        img_mask = np.zeros(img_.shape).astype(np.uint8)
        img_mask[:,:,:]=255

        for msg_ in hands_json:

            RGB_ = (245, 55, 133)
            if msg_["label"] == "left":
                RGB_ = (25, 255, 133)
            Joints3D = np.array(msg_["joint3d"])
            Vertex3D = np.array(msg_["vertex3d"])
            pts2d_ss = Draw_KeyPoints3D(img_joint,Joints3D,fx,fy,cx,cy)
            Draw_Vertex_KeyPoints(img_mesh,img_mask,Vertex3D,fx,fy,cx,cy,triangles_index,RGB_ = RGB_)
            hand_cnt += 1

        stk_1 = np.hstack((img_,img_joint))
        stk_2 = np.hstack((img_mesh,img_mask))

        stk_ = np.vstack((stk_1,stk_2))

        cv2.namedWindow("img_stk",0)
        cv2.imshow("img_stk",stk_)
        out_cnt += 1
        print("--------->>>imgs_num : [{}] , hands_num: [{}]".format(out_cnt,hand_cnt))
        key_id = cv2.waitKey(0)
        cv2.imwrite("f1.jpg",stk_)
        if key_id == 27:
            break

助力快速掌握数据集的信息和使用方式。

数据可以如此美好!


http://www.niftyadmin.cn/n/5869266.html

相关文章

第15章-超声波避障功能 HC-SR04超声波测距模块详解STM32超声波测距

原文链接 功能介绍放开头, 使用便捷无需愁 这是全网最详细、性价比最高的STM32实战项目入门教程,通过合理的硬件设计和详细的视频笔记介绍,硬件使用STM32F103主控资料多方便学习,通过3万字笔记、12多个小时视频、20多章节代码手…

网易云音乐分布式KV存储实践与演进

随着网易云音乐业务的快速发展,推荐和搜索场景对分布式KV存储的需求日益增长。本文将深入探讨网易云音乐在分布式KV存储方面的实践和演进,分析其技术选型、架构设计以及未来发展方向。 一、业务背景 网易云音乐的业务场景对分布式KV存储提出了高并发、…

java23种设计模式-命令模式

命令模式(Command Pattern)学习笔记 1. 模式定义 行为型设计模式,将请求封装为对象,使请求的发送者与接收者解耦。支持请求的排队、记录、撤销/重做等操作。 2. 适用场景 ✅ 需要将操作参数化 ✅ 需要支持事务操作&#xff08…

重构清洁想象,石头科技首创五轴仿生机械手打破传统清洁边界

2月25日,主题为“重构清洁想象”的石头科技2025发布会在上海天文馆正式召开。石头科技清洁产品BU总裁钱启杰在会上宣布,石头科技正式成为上海天文馆授权合作伙伴,希望借助航天科技到家庭科技的跨越,进一步简化家庭清洁工作&#x…

升维商哲院高考院:用易经命理为未来导航,开启慧性思维新篇章

(2025年2月19日,中国北京)在人工智能飞速发展、社会变革日新月异的今天,如何帮助青少年更好地规划未来,培养适应未来社会发展的核心素养,成为教育领域的重要课题。近日,名为“升维商哲院高考院”…

如何基于PyTorch做二次开发

基于PyTorch进行二次开发以实现可视化工程,可以从以下几个方面入手:模型结构可视化、训练过程监控、特征可视化等。以下是一些推荐的GitHub项目,这些项目可以帮助你快速搭建一个可视化的工程环境: ### 1. **PyTorch CNN Visualiz…

Visual Studio Code 跨平台安装与配置指南(附官方下载链接)

一、软件定位与核心功能 Visual Studio Code(简称VS Code)是微软开发的开源跨平台代码编辑器,支持超过50种编程语言的智能补全、调试和版本控制功能。2025版本新增AI辅助编程模块,可自动生成单元测试代码和API文档注释。 二、下载…

蓝桥杯刷题-dp-线性dp(守望者的逃离,摆花,线段)

[NOIP 2007 普及组] 守望者的逃离 题目描述 恶魔猎手尤迪安野心勃勃,他背叛了暗夜精灵,率领深藏在海底的娜迦族企图叛变。 守望者在与尤迪安的交锋中遭遇了围杀,被困在一个荒芜的大岛上。 为了杀死守望者,尤迪安开始对这个荒岛…