NTU RGB+D 骨骼数据读取代码解析

本文将解析一段用于读取 'NTU RGB+D 3D Action Recognition Dataset' 中 .skeleton 文件的 Matlab 代码。 这段代码能够解析骨骼数据并将其存储到一个结构体中,方便后续处理和分析。

代码功能: 读取 .skeleton 文件并提取骨骼信息。

输入参数: - filename: .skeleton 文件的完整路径和文件名。

输出参数: - bodyinfo: 包含每帧骨骼信息的数据结构体。

**代码解析:**matlabfunction bodyinfo = read_skeleton_file(filename)% Reads an .skeleton file from 'NTU RGB+D 3D Action Recognition Dataset'.% % Argrument:% filename: full adress and filename of the .skeleton file.%% For further information please refer to:% NTU RGB+D dataset's webpage: % http://rose1.ntu.edu.sg/Datasets/actionRecognition.asp% NTU RGB+D dataset's github page: % https://github.com/shahroudy/NTURGB-D% CVPR 2016 paper: % Amir Shahroudy, Jun Liu, Tian-Tsong Ng, and Gang Wang, % 'NTU RGB+D: A Large Scale Dataset for 3D Human Activity Analysis', % in IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2016%% For more details about the provided data, please refer to:% https://msdn.microsoft.com/en-us/library/dn799271.aspx% https://msdn.microsoft.com/en-us/library/dn782037.aspx

fileid = fopen(filename); % 打开文件framecount = fscanf(fileid,'%d',1); % 读取帧数

bodyinfo=[]; % 初始化存储骨骼信息的结构体

for f=1:framecount % 遍历每一帧 bodycount = fscanf(fileid,'%d',1); % 读取当前帧的骨骼数量 for b=1:bodycount % 遍历当前帧的每一个骨骼 clear body; body.bodyID = fscanf(fileid,'%ld',1); % 读取骨骼ID arrayint = fscanf(fileid,'%d',6); % 读取6个整数 body.clipedEdges = arrayint(1); % 是否被裁剪 body.handLeftConfidence = arrayint(2); % 左手置信度 body.handLeftState = arrayint(3); % 左手状态 body.handRightConfidence = arrayint(4); % 右手置信度 body.handRightState = arrayint(5); % 右手状态 body.isResticted = arrayint(6); % 是否受限 lean = fscanf(fileid,'%f',2); body.leanX = lean(1); % X轴倾斜 body.leanY = lean(2); % Y轴倾斜 body.trackingState = fscanf(fileid,'%d',1); % 骨骼跟踪状态 body.jointCount = fscanf(fileid,'%d',1); % 读取关节数量 joints=[]; for j=1:body.jointCount % 遍历每个关节 jointinfo = fscanf(fileid,'%f',11); % 读取关节信息 joint=[]; % 3D location of the joint j joint.x = jointinfo(1); joint.y = jointinfo(2); joint.z = jointinfo(3); % 2D location of the joint j in corresponding depth/IR frame joint.depthX = jointinfo(4); joint.depthY = jointinfo(5); % 2D location of the joint j in corresponding RGB frame joint.colorX = jointinfo(6); joint.colorY = jointinfo(7); % The orientation of the joint j joint.orientationW = jointinfo(8); joint.orientationX = jointinfo(9); joint.orientationY = jointinfo(10); joint.orientationZ = jointinfo(11); % The tracking state of the joint j joint.trackingState = fscanf(fileid,'%d',1); body.joints(j)=joint; % 将关节信息添加到骨骼结构体中 end bodyinfo(f).bodies(b)=body; % 将骨骼信息添加到对应帧的结构体中 endendfclose(fileid); % 关闭文件end

代码解释:

  1. 读取文件信息: 代码首先打开 .skeleton 文件,读取总帧数。2. 遍历帧和骨骼: 代码使用嵌套循环遍历每一帧和每一帧中的每一个骨骼。3. 读取骨骼信息: 对于每个骨骼,代码读取其 ID、状态信息(如左右手置信度、倾斜等)、关节数量等。4. 读取关节信息: 代码遍历每个关节,读取其 3D 坐标、2D 深度图坐标、2D RGB 图像坐标、方向和跟踪状态。5. 存储数据: 代码将读取的骨骼和关节信息存储到 bodyinfo 结构体中,方便后续使用。

总结:

这段代码提供了一种有效的方法来读取和解析 NTU RGB+D 数据集中的 .skeleton 文件。 通过理解这段代码,你可以更好地理解数据集的格式,并利用这些数据进行人体动作识别等方面的研究。

NTU RGB+D 骨骼数据读取代码解析

原文地址: https://www.cveoy.top/t/topic/bYZi 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录