save snapshot image in a variable within a loop!!
7 views (last 30 days)
please need help in this why the data(i) variable in while loop give me an error here I want to take a picture after each 5 second and I need it continuous so I used while(1) ...
vid = videoinput('winvideo',1);
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb');
i = 0;
data(i) = getsnapshot(vid);
Image Analyst on 4 Apr 2017
Get rid of the (i) and have just data, or better yet, a more descriptive filename:
for f = 1 : 1000 % view and save 1000 frames then quit.
thisFrame = getsnapshot(vid);
baseFileName = sprintf('Frame %3.3d.png', f);
fullFileName = fullfile(folder, baseFileName);
More Answers (1)
Joseph Cheng on 4 Apr 2017
Edited: Joseph Cheng on 4 Apr 2017
from what i see get snapshot returns a NxMx(1 for mono 3 for color) and you're trying to stuff it into a 1x1. what you should try is i=1 for start as data(0) isn't how matlab works. and put data as data(:,:,i) for monochrome as you'll be putting a NxM into data's NxMx1 indexes. change the data() into a cell array if you want to store it as an rgb image.