原始代码照着mathworks的一个介绍视频中的程序,码下来的,修完错误之后,终于跑起来了。最初是骨架线比RGB的人小太多了,可能因为用深度图获取的骨架线,而深度图的分辨率只有512×424,RGB有1920×1080?这样,用imresize函数把彩色图也改成512×424,确实能大小一致了,但重合度没有介绍视频中的好。后来又找到一个视频,码完之后效果挺好的,程序如下:
%% 预设
imaqhwinfo
colorVid = videoinput('kinect',1);
depthVid = videoinput('kinect',2);
triggerconfig(depthVid,'manual');
triggerconfig(colorVid,'manual');
depthVid.FramesPerTrigger = 1;
depthVid.TriggerRepeat = inf;
set(getselectedsource(depthVid),'EnableBodyTracking','on');
colorVid.FramesPerTrigger = 1;
colorVid.TriggerRepeat = inf;
%%
start(depthVid);
start(colorVid);
himg = figure;
while ishandle(himg)
trigger(colorVid);
trigger(depthVid);
image = getdata(colorVid);
[depthMap,~,depthMetadata] = getdata(depthVid);
if sum(depthMetadata.IsBodyTracked) > 0
trackedSkeletons = find(depthMetadata.IsBodyTracked);
skeletonJoints = depthMetadata.ColorJointIndices(:, :, trackedSkeletons);
skeletonViewer2(skeletonJoints,image,1);%这里注意一下,img的坐标原点在左上角,而数据坐标原点在左下角?
else
imshow(image);
end
end
%停止时运行这两个
%stop(colorVid);
%stop(depthVid);