我使用Matlab和Kinect传感器开展一个项目。我有从Kinect传感器拍摄照片进行训练的功能。问题是我想用Skeleton将图片保存在数据集中的图片上,如视频中所示。它只保存没有骨架的图片。
我认为错误就在这一行:
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)])
答案 0 :(得分:0)
更改此行:
imwrite(img, fullfile(fileLocation,sprintf('Picture%d.png', nImages)));
用这些:
frame = getframe;
imwrite(frame.cdata, fullfile(fileLocation,sprintf('Picture%d.png', nImages)));
N.B。:我假设您的util_skeletonViewer
是this one。