HI i want to save the snapshot figure by automatically taken by the laptop webcam .? i don't know how to do auto-save....
then i want to check the image taken by the webcam is blank(black) or a picture

2 Comments

Jan
Jan on 15 Feb 2014
The question is not clear. Please take the chance to edit the text and improve it. Thanks.
thank you :)

Sign in to comment.

 Accepted Answer

Image Analyst
Image Analyst on 15 Feb 2014
Edited: Image Analyst on 16 Feb 2014
rgbImage = getsnapshot(videoObject);
imwrite(rgbImage, fullFileName);
grayImage = rgb2gray(rgbImage);
meanGL = mean2(grayImage);
if meanGL < 20 % or whatever.
warningMessage = sprintf('Something is wrong.\nThe image is too dark.\nThe mean intensity is only %.1f gray levels', meanGL);
uiwait(warndlg(warningMessage));
end

3 Comments

thank you
suryakanth
suryakanth on 16 Feb 2014
Edited: suryakanth on 16 Feb 2014
this is my code
s1 = serial('COM3');
fopen(s1)
fprintf(s1, '*IDN?');
idn = fscanf(s1);
fclose(s1);
if idn == 'a'
vid = videoinput('winvideo',1);
src = getselectedsource(vid);
vid.FramesPerTrigger = 1;
preview(vid);
vid.ReturnedColorspace = 'rgb';
im1=getsnapshot(vid);
preview(vid);
closepreview(vid);
stop(vid);
e=imshow(im1);
else f = errordlg('The phone was not used', 'Recorded status'); end
imwrite(im1, fullFileName);
grayImage = rgb2gray(im1);
meanGL = meann2(grayImage);
if meanGL < 20 % or whatever.
warningMessage = sprintf('Something is wrong.\nThe image is too dark.\nThe
mean intensity is only %.1f gray levels', meanGL);
uiwait(warndlg(warningMessage));
end
this is my code ..but it give an error in the line of
inwrite(im1,fullFileName) ;
and in line of meann2(grayimage)
the error is
Undefined function 'meann2' for input arguments of type 'uint8'.
Error in InProcessing (line 21)
meanGL = meann2(grayImage);
------------------------------------------
Warning: Image is too big to fit on screen; displaying at 67%
> In imuitools\private\initSize at 72
In imshow at 259
In InProcessing at 16
Undefined function or variable 'fullFileName'.
Error in InProcessing (line 19)
imwrite(im1, fullFileName);
Image Analyst
Image Analyst on 16 Feb 2014
Edited: Image Analyst on 16 Feb 2014
Use mean2(grayImage) or mean(grayImage(:)) instead of meann2(). There is no meann2 - that was a typo of mine. And of course you need to create a filename. Use sprintf() and fullfile() to do that.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!