使用相机我拍摄快照并将其存储到数组中。代码是:
vid1 = videoinput('winvideo',1,'RGB24_640x480');
vid2 = videoinput('winvideo',2,'RGB24_640x480');
start(vid1);
start(vid2);
preview(vid1);
preview(vid2);
pics1 = cell(1,10)
pics2 = cell(1,10)
for i = 1: 10
pause(5);
pics1{i} = getsnapshot(vid1);
pics2{i} = getsnapshot(vid1);
end
closepreview(vid1);
closepreview(vid2);
clear ('vid1');
clear ('vid2');
现在数组存储在pics1和pics2中,但我希望将它们视为.png图像,并将它们仅作为.png存储在其他文件夹中。我怎样才能做到这一点。
答案 0 :(得分:1)
您可以使用imwrite()函数将数组写入PNG文件。以下代码块显示了它如何与您的代码一起使用,
pics1 = cell(1,10);
for i = 1:10
pause(5);
pics1{i} = getsnapshot(vid1);
end
for i = 1:10
FileName = sprintf( 'pic%d.png',i) ;
fullFileName = fullfile( FileName);
imwrite(pics1{i}, fullFileName);
end
希望这有帮助,