2
votes

Using a camera I took snapshots and stored them into array. Code for this is:

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');

Now arrays are stored in pics1 and pics2 but I want to watch them as .png image and store them as .png only in other folder. how can I do that.

1
Take a look at imwrite. - mikkola

1 Answers

1
votes

You can write arrays into a PNG file by using imwrite() function. The following code block shows how it might be used with your code,

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

Hope this helps,