Wednesday, November 12, 2008

ACCESS YOUR WEB CAM AND TAKE SNAPSHOTS USING MATLAB

This program helps you to take photos using your web cam.

The photos taken will also saved as JPEG file. The name of this file will be assigned automatically.
The function 'videoinput' is used to create the object (obj). The argument winvideo is the adaptor name.
If your adaptor is not this you can find the adaptor name by executing the command 'imaqhwinfo' on the command window. This will show all installed adaptors in the system. The 'preview' will immediately activates a live image preview window
for the video input object obj. This can be deactivated by using the function 'closepreview'. The 'getsnapshot' isused to take the photograph and it returns the image data array. 'imwrite' is used to save the image file.

Download:


MATLAB Program follows:

%-------------------------------------------------------------------------------------
% Program for taking photographs
% By vipin.p.nair
% 4-Nov-2008
% This program uses the web cam foR taking photos

%*********************************************************
% Algorithom
% 1) Read no of photos
% 2) Read intervel
% 3) initialise video device
% 4) show preview
% 5) loop: x[i]snapshot, if time increment i
% 6) show snaps in differnt figures goto loop
% 7) END

%**********************************************************

clc ; % clearing the command window
num = 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...');

obj = videoinput('winvideo',1);
preview(obj);
disp('You can adjust the video settings using your normal video console and after it press any key to start.');
pause;
disp('First shot will taken after 1 second');

pause(1);
for i=1:num
figure;
img=getsnapshot(obj);
image(img);
if(photosave == 'y')
filephoto= ['photo',int2str(i),'.jpg'];
imwrite(img,filephoto,'jpg');
end

pause(intervel);


end
closepreview;

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

No comments:

Post a Comment