How to display skeleton data
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I hope you have a good day...What MATLAB command can be used to display skeletal data in 3D from this matrix? He explained: The first line is related to the data recording time, and the second line is the joint number, and the third, fourth, and fifth lines are related to the x-axis, y-axis, and z-axis of the joint 0. It continues in the same way. How can the moving skeleton be displayed? Wrote? The data form is as follows.time, 0, joint0_x, joint0_y, joint0_z, 1, joint1_x, joint1_y, joint1_z, 2, joint2_x, joint2_y, joint2_z, .I know and have studied the skeleton display code on different sites, but I was confused about my own code. please guide me. tanx so much.
0 Commenti
Risposte (2)
Image Analyst
il 4 Nov 2023
Try this:
data = readmatrix('human2_normal17_SkeletonData1.csv');
% Plot the first 4 joint skeletons.
PlotJointNumber(data, 1)
PlotJointNumber(data, 2)
PlotJointNumber(data, 3)
PlotJointNumber(data, 4)
function PlotJointNumber(data, jointNumber)
% Plot this joint.
column = 4 * jointNumber - 1;
x = data(:, column);
y = data(:, column+1);
z = data(:, column+2);
nexttile
plot3(x, y, z, 'b.-', 'LineWidth', 2)
grid on;
fontSize = 20;
xlabel('x','FontSize',fontSize);
ylabel('y','FontSize',fontSize);
zlabel('z','FontSize',fontSize);
caption = sprintf('Joint #%d', jointNumber);
title(caption,'FontSize',fontSize);
end
4 Commenti
Image Analyst
il 5 Nov 2023
The concept is the same. You just need to read in your data. Then parse it into arrays for x, y, and z. Then use plot3 or plot to plot them.
To learn other fundamental concepts, invest 2 hours of your time here:
William Rose
il 3 Lug 2024
I assume jints 0 to 24 in the CSV file correspond to joints 1 to 25 in the skeleton connection list. Please be consistent.
The two PNG files you provided show 21 points on the skeleton: 5 points along the head and spine, and 4 points each for the left shoulder-arm-hand, right shoulder-arm-hand, left hip-leg-foot, and right hip-leg-foot. Your skeleton connection map has 25 points. Why do the images and the file have different numbers of joints?
The skeleton connection map begins as follows:
SkeletonConnectionMap = [ [4 3]; % Neck
[3 21]; % Head
[21 2]; % Right Leg
[2 1];
[21 9];
[9 10]; % Hip
[10 11];
[11 12]; % Left Leg
[12 24];
[12 25];
and so on. The listing above indicates that joint 21 is part of the head and also part of the right leg. That does not make sense. Also, joint 21 is included twice in the right leg, which does not make sense. Please check the skeleton connection list, and make corrections if needed. Thank you.
1 Commento
William Rose
il 4 Lug 2024
Modificato: William Rose
il 4 Lug 2024
[Edit: Change comment identifying marker 2 (spine) from L1 to T8, and marker 21 from T1 to C7. I think T8 is more consistent than L1 with the mean marker position shown in the plot. And C7 (vertebra prominens) is used more often than T1 in motion capture. It is easier to identify by palpation, on most subjects.
Edit 2: Replace 'load' with 'importdata'; fix some spelling errors (not in the code).]
The reason your data file has 4 more "joints" than the figures is that the data file includes 3 markers on each hand, and the two images you provided have only one marker on each hand. In your data, the markers appear to be approximately at the 1st and 5th metacarpal, and at distal phalanx 3.
I believe the correct skeleton connections are
spine=[4 3 21 2 1]; % vertex, C1, C7, T8, S1
legs=[20 19 18 17 1 13 14 15 16];
% Rtoe,Rankle,Rknee,Rhip,S1,Lhip,Lknee,Lankle,Ltoe
arms=[11 25 24 12 11 10 9 21 5 6 7 8 22 23 7];
% Rwrst,Rmc1,Rdp3,Rmc5,Rwrst,Relbw,Rshdr,T1,Lshdr,Lelbw,Lwrst,Lmc5,Ldp3,Lmc1,Lwrst
When drawing the arms, I use each wrist twice. This plots a loop that outlines each hand.
The code below reads in the data from the csv file. It rearranges the XYZ data into a 3D array, where dimension 1=frame number, dimension 2=X,Y,Z, and dimension 3=joint number. By arranging the data in this format, I can more easily compute the mean location of each marker (mean over all 66 frames) and I can create the plots more easily.
The code below plots the mean locations of each marker and draws lines between appropriate markers. You can modify it to add a for loop that plots the markers frame-by-frame. When you run the script on your computer, you will be able to click and drag to rotate the plot in 3D.
I use the command axis equal so that the plot will be realistically scaled. In other words, this command makes 1 meter look the same length, wherther it is 1 meter of height or width or depth. If you do not specify axis equal, then the scale can be different along diferent axes, and the plot will not look much like a real human.
data=importdata('human2_normal17_SkeletonData1.csv');
time=data(:,1); % vector of times
N=length(time); % number of frames
col0=[3,4,5]; % columns with X,Y,Z for joint 1
columns=[];
for i=0:24, columns=[columns,col0+4*i]; end % columns with X,Y,Z data
joints=data(:,columns); % X,Y,Z data for 25 joints
joints=reshape(joints,[N,3,25]); % 3D array
% joints: dim.1=frame number, dim.2=[X,Y,Z]; dim.3=joint number
spine=[4 3 21 2 1]; % vertex, C1, C7, T8, S1
legs=[20 19 18 17 1 13 14 15 16];
% Rtoe,Rank,Rknee,Rhip,S1,Lhip,Lknee,Lank,Ltoe
arms=[11 25 24 12 11 10 9 21 5 6 7 8 22 23 7];
% Rwrst,Rmc1,Rdp3,Rmc5,Rwrst,Relbw,Rshdr,T1,Lshdr,Lelbw,Lwrst,Lmc5,Ldp3,Lmc1,Lwrst
jointsMean=squeeze(mean(joints));
figure
plot3(jointsMean(1,spine),jointsMean(2,spine),jointsMean(3,spine),'-k+',LineWidth=1.5); hold on
plot3(jointsMean(1,arms),jointsMean(2,arms),jointsMean(3,arms),'-b+',LineWidth=1.5);
plot3(jointsMean(1,legs),jointsMean(2,legs),jointsMean(3,legs),'-m+',LineWidth=1.5);
axis equal; grid on; title('Mean Position')
xlabel('X'); ylabel('Y'); zlabel('Z'); view(-135,20)
Good luck.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!