Saturday 2 February 2013

Capture and save Frames using Webcam matlab Code


clc ; % clearing the command window
n = input(' Enter the number of photos to be taken: ');
intervel = input(' Enter the time(seconds) gap between succeessive photos: ');
photosave = input(' Do you want to save the files(y/n): ','s');
disp('Please wait...');
outputFolder = fullfile(cd, 'frames');
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
obj = videoinput('winvideo',1);
preview(obj);
disp('Press Enter to start after webcam initialization.');
pause;
disp('First shot will taken after 1 second');
pause(1);
for i=1:n
img=getsnapshot(obj);
image(img);
if(photosave == 'y')
outputBaseFileName = sprintf('fr%d.png',i);
outputFullFileName = fullfile(outputFolder, outputBaseFileName);
imwrite(img,outputFullFileName,'jpg');
end
pause(intervel);
end
closepreview;

disp('The program successfully taken the photos');
disp('Done.');

2 comments:

  1. itsss really interesting...............can u plzzzzzz mail me d prog for face recognition n alignment using matlab.............ma id is sonalukelaskar@gmail.com

    ReplyDelete
  2. hi m getting this error while executing the above code...plz help
    Error using imwrite (line 463)
    Can't open file "C:\Program Files\MATLAB\R2011b\bin\frames\fr1.jpj" for writing.
    You may not have write permission.

    Error in manzil (line 29)
    imwrite(img,outputFullFileName,'jpg');

    ReplyDelete