Wednesday, July 16, 2008

Video & Image Acquisition using MATLAB

This article is a part of module I had prepare for the Shortcourse on "Machine Vision Application for Oil Palm Grading", at the Faculty of Electrical & Electronics Engineering, Universiti Malaysia Pahang, Kuantan-Pahang. I was appointed by my colleague, Mas Kamarul, as invited instructor for the topic Real Time Interfacing using MATLAB.

In the machine vision system, data acquisition is the first step which programmer should aware. You want to preview object using your camera, capture it, store the captured image in your PC? With simple way, you will get your own preview window of your webcam by following this tutorial.

Equipments:

  1. CCD camera & frame grabber or webcame
  2. PC with MATLAB 7.x
Procedures:
  1. Make sure that you have a functional CCD camera or webcam connected to your PC. Functional means it's driver has been installed in your PC. To see whether your camera can work well or not, you can install a windows standard video capture, named AMCAP.
  2. MATLAB has built-in adaptor to communicate with the acquisition device. To check whether your MATLAB has this support or not, type

>> cam=imaqhwinfo

cam =

InstalledAdaptors: {1x1 cell}
MATLABVersion: [1x12 char]
ToolboxName: [1x25 char]
ToolboxVersion: [1x12 char]

>> cam.InstalledAdaptors

ans =

'winvideo'

For more information about your device, type

>> device_info=imaqhwinfo('winvideo',1)

  1. Type the following code in your editor and run the program

vid=videoinput(‘winvideo’);

preview(vid)


  1. To capture the video, type

im=getsnapshot(vid)

imshow(im)

Check your workspace, now you have RGB image data im.

  1. To store the image data to a .jpg or .gif file, type


imwrite(im,’myimet.jpg’);


Very easy? If you face any problem or you have suggestions, do not hesitate to write in the comments area below.

3 comments:

Unknown said...

hi plz i wanted to ask you how can i do so using w specific time or specific number of frames
plz answer me asap :)
thnx a lot

Anonymous said...

I am doing a project on controlling computer mouse through eye movement and I need a suitable camera for my project. The camera should be capable of tracking the eye movements. Are there any specific cameras that a economical and meet my requirements? Are the Firewire cameras the only choice?

Anonymous said...

Hi, just wanna ask if this feature of matlab can work with CCTV cameras as well? tnx.