2015-12-31 40 views
2

使用攝像頭我拍攝快照並將它們存儲到數組中。代碼是這樣的:使用matlab將陣列變成圖像2014

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圖片,並將它們只有在其他文件夾中存儲爲巴紐。我怎樣才能做到這一點。

+0

看看['imwrite'](http://se.mathworks.com/help/ MATLAB/REF/imwrite.html)。 – mikkola

回答

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 

希望這有助於

+0

謝謝它的工作 –