MATLAB: How do you take a picture automatically that is connected to your computer through USB, using MATLAB code

image processingwebcam

I need my code to signal the camera to take a picture once an object is placed in the frame and then store the image in MATLAB.
[Merged information from duplicate question]
The model of the camera I want to access that is connected through USB is a "Windows Life Cam". I need this camera to take picture. My code is only pulling up the Web Cam that is permantly installed on the computer (that comes with the machine). Here is what I have:
vid = videoinput('winvideo', 2);
start(vid);
im = getdata(vid,2);
figure, imshow(im);
imwrite(im, 'myfirstimage.jpg');
Thanks.

Best Answer

Did you try the getsnapshot() function? Or did you run imaqtool to see what functions you need to run (there's more than just getsnapshot()).