demo:利用kinect和cnn進行骨架線識別並輸出

流程:
提取骨骼信息——繪製骨架線(但不顯示)——存儲骨架線數據爲圖片——對骨架線進行cnn識別——顯示RGB圖像(視頻)並在其上繪製骨架線——將識別結果顯示在上面git

  • 先設置一堆東西,close all必須有,不然識別過程當中,只有第一次運行ok,之後在第二步骨架線會一直閃窗。
%% 動態識別動做,畫在黑白骨架線上,兩個圖(不用讀取白圖,不會彈)
close all;
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')
%triggerconfig(colorVid,'manual');%可刪?和上面重複了可是我記得我cp上會有問題
%triggerconfig(depthVid,'manual');%可刪?
colorVid.FramesPerTrigger = 1;
colorVid.TriggerRepeat = inf;
  • 加載訓練好的網絡skeletonnet,而後一幀一幀地採集、識別、顯示
nnet = skeletonnet
start(depthVid);
start(colorVid);
image2 = 255.*ones(1080,1920,3,'uint8');

himg = figure(2);
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);
        fh = figure(1);
        set(fh,'Visible','off');
        skeletonViewer2(skeletonJoints,image2,1);
        
        I = getframe(gcf);
        pic = I.cdata;
        picture = imresize(pic,[227,227]);
        label = classify(nnet, picture);
        close;
        
        fl = figure(2);
        set(fl,'Visible','on');
        skeletonViewer2(skeletonJoints,image,1);
        title(char(label)); 
        drawnow; 
    else
        imshow(image);
    end
end
stop(colorVid);
stop(depthVid);

之前寫的有些冗餘,最後的在個人GitHubgithub