Video & Image Acquisition using MATLAB

By | July 16, 2008

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.


  1. CCD camera & frame grabber or webcame
  2. PC with MATLAB 7.x


  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: {1×1 cell}
MATLABVersion: [1×12 char]
ToolboxName: [1×25 char]
ToolboxVersion: [1×12 char]

>> cam.InstalledAdaptors

ans =


For more information about your device, type

>> device_info=imaqhwinfo(‘winvideo’,1)

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



  1. To capture the video, type



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

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


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

Leave a Reply

Your email address will not be published. Required fields are marked *