流程:
提取骨骼信息——繪製骨架線(但不顯示)——存儲骨架線數據爲圖片——對骨架線進行cnn識別——顯示RGB圖像(視頻)並在其上繪製骨架線——將識別結果顯示在上面git
%% 動態識別動做,畫在黑白骨架線上,兩個圖(不用讀取白圖,不會彈) 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;
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);
之前寫的有些冗餘,最後的在個人GitHub上github