Real time skeleton tracking using kinect v2

14 views (last 30 days)
I'm trying to use this code using kinect v2 to get real time skeleton tracking. I'm using matlab R2018a.
clear; close all;clc
imaqreset;
depthVid = videoinput('kinect',2);
triggerconfig (depthVid,'manual');
framesPerTrig = 1;
depthVid.FramesPerTrigger = framesPerTrig;
depthVid.TriggerRepeat = inf;
prop = getselectedsource(depthVid);
prop.EnableBodyTracking = 'on';
start(depthVid)
himg = figure;
while ishandle(himg);
trigger(depthVid)
[frameDataDepth, timeDataDepth, metaDataDepth] = getdata(depthVid)
if sum(metaDataDepth.IsBodyTracked) > 0
skeletonJoints = metaDataDepth.JointPositions(:,:,metaDataDepth.IsBodyTracked)
try
delete(h)
end
h = plot(skeletonJoints(:,1), skeletonJoints(:,2),'.','MarkerSize',15); % Plota no imshow as juntas
axis([-2.1 2.1 -2.1 2.1])
end
end
This code does work, but it has a big delay, when i used:
tic
trigger(depthVid)
toc
The elapsed time is 1.002209 seconds
The trigger made my code runing slow, how can i fix it? Is there a way to reduce trigger time? The FPS are very slow.
Notice that the elapsed time to trigger is big (1sec) just when i enable body tracking (i need to use it, since i want to get real time skeleton tracking). When i tried without using body tracking property the trigger time was arround 0.003 seconds, the idial for the application.
Thank you!
  4 Comments
prasanth s
prasanth s on 19 Jan 2023
Edited: prasanth s on 19 Jan 2023
can you attach the input video 'depthVid'?
Alessandra Martinez
Alessandra Martinez on 19 Jan 2023
I don't have a saved input video. I'm trying to make it real time, however the RGB image isn't synched with the plotted skeleton. I'm using imshow() though.
I could attach the code I'm working with.

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!