2
我使用Matlab和Kinect傳感器處理一個項目。我有功能爲Kinect傳感器拍攝照片進行訓練。問題是我想用Skeleton將圖片保存在視頻中顯示的數據集中。它只保存沒有骨架的圖片。用骷髏保存Kinect,Matlab和圖片
我認爲這是錯誤的地方這個行:
imwrite(img, fullfile(fileLocation,sprintf('Picture%d.png', nImages)));
,而不是IMG,必須是別的東西。
預先感謝您。
我的代碼是:
function Sample(MainFolderName, ObjectFolderName,delay)
if nargin < 3
delay = 0.1;
end
videoC = videoinput('kinect',1);
videoDepth = videoinput('kinect',2);
%% Skeleton info
triggerconfig(videoDepth,'manual');
videoDepth.FramesPerTrigger=1;
videoDepth.Triggerrepeat=inf;
set(getselectedsource(videoDepth),'TrackingMode','Skeleton')
start(videoDepth);
for i=1:100
trigger(videoDepth);
[depthMap,~,depthMetaData]=getdata(videoDepth);
imshow(depthMap,[0 4000]);
end
%%
skeletonJoint=depthMetaData.JointImageIndices(:,:,depthMetaData.IsSkeletonTracked);
imshow(depthMap,[0 4000]);
hold on; plot(skeletonJoint(:,1),skeletonJoint(:,2),'*');
stop(videoDepth);
%% Draw and track skeleton
triggerconfig(videoC,'manual');
videoC.FramesPerTrigger=1;
videoC.Triggerrepeat=inf;
start(videoDepth);
start(videoC);
%% Create folder with label name
fileLocation = fullfile(MainFolderName,ObjectFolderName);
if ~exist(ObjectFolderName,'file')
mkdir(fileLocation)
end
%% Take pictures
nImages = 1;
fig = figure('Name','Pictures for training','NumberTitle','off');
ax = axes('Parent',fig);
try
while ishandle(fig)
pause(delay);
trigger(videoC);
trigger(videoDepth);
% [frameDataColor] = getdata(videoUlaz);
img = getdata(videoC);
% image = frameDataColor(:,:);
[depthMap,~,depthMetaData]=getdata(videoDepth);
if sum(depthMetaData.IsSkeletonTracked)>0
skeletonJoints=depthMetaData.JointImageIndices(:,:,depthMetaData.IsSkeletonTracked);
util_skeletonViewer(skeletonJoints,img,1);
imwrite(img, fullfile(fileLocation,sprintf('Picture%d.png', nImages)));
title(sprintf('Number: %3.0f',nImages))
nImages = nImages+1;
% else
% imshow(img);
end
end
stop(videoC);
stop(videoDepth);
imaqreset;
catch
imaqreset;
end
%% Display Info
nImages = size(ls(fullfile(fileLocation,'*.png')),1);
disp('---------Training images!---------')
disp(['Name: ',ObjectFolderName])
disp(['Nubmer: ',num2str(nImages)])
disp(['Location: ',fullfile(pwd,fileLocation)])
請添加您想要獲得的輸出的示例圖片 –