Using Webcam in MATLAB for Image Acquisition
Wanted to access webcam via MATLAB, read this.
In MATLAB, you can check if the support is available for your camera. MATLAB has built-in adaptors for accessing these devices.
You must check if you have the data acquisition toolbox in your version. that you have installed.
Just get to the MATLAB Start menu > Toolboxes > Data AcquisitionTo get information about installed adapters, type
>> imaqhwinfo
Here, in this case the adaptor is 'winvideo'To get more information about the device, type
>> info=imaqhwinfo('winvideo')
Now let's see how to use the webcam
1) Connect your webcam to the computer through the USB, or use the intergrated laptop camera.
You can preview the video captured by the image by defining an object and associate it with the device.
>> vid = videoinput('winvideo', 1, 'RGB24_320×240');
2) Open Preview window to view video in realtime
>> preview(vid);
2) Open Preview window to view video in realtime
>> preview(vid);
3) Capturing and storing images
1. Capturing an image
To capture an image from the video, define the object vid as described before and use getdata to capture a frame from the video.
>>start(vid);
1. Capturing an image
To capture an image from the video, define the object vid as described before and use getdata to capture a frame from the video.
>>start(vid);
>>im=getdata(vid,1); % im = getsnapshot(vid); alternative use
>>figure,imshow(im);
2. Storing the image
You can store the captured image as a .jpg or .gif file using imwrite function.
>>imwrite(im,'myfirstimage.jpg');
This image will be stored in current work directory folder.
>>figure,imshow(im);
2. Storing the image
You can store the captured image as a .jpg or .gif file using imwrite function.
>>imwrite(im,'myfirstimage.jpg');
This image will be stored in current work directory folder.
Now try yourself, add, and tweak.
Read more...