Getting an image into octave from a local camera

The image-acquisition package of octave-forge will be used for this purpose. So, first of all, you need to install and load this package in octave. You also need to install build dependencies for the package, these are – ‘libv4l-dev’ and ‘libfltk1.3-dev’ or ‘libfltk1.1-dev’.

octave> pkg install -forge image-acquisition
octave:> pkg load image-acquisition

After loading this package, you can further proceed to capture an image from web cam or from any other connected camera.

The function below will open the v4l2 device and output the result-

octave:> obj = videoinput("v4l2", "/dev/video0")
obj = videoinput for v4l2
     device               = /dev/video0
     driver               = uvcvideo
     card                 = UVC Camera (046d:0825)
     VideoInput           = 0
     VideoResolution      = 320 x 240 px
     VideoFormat          = YUYV

Now, follow the given steps-

>> get(obj);  // To check properties available for used device
>> set(obj, "VideoFormat", "RGB3");  // To convert video format from RGB24 to RGB3
>> set(obj, "VideoResolution", [320 240]);  // To get the list of available video resolutions
>> preview(obj)  // To start preview
Hit CTRL+C to exit


>> set(obj, "VideoResolution", [640 480]); // Use higher resolution
>> start(obj, 2) // Start streaming with two buffers
>> img = getsnapshot(obj); // To get an image from the buffers, view and save it
>> image(img) // To show
>> img = getsnapshot(obj);
>> image(img)
>> imwrite(img, "e.png") // To write
   warning: your version of GraphicsMagick limits images to 16 bits per pixel
   warning: called from
   imformats>default_formats at line 256 column 11
   imformats at line 79 column 3
   imwrite at line 99 column 7
>> [img, seq, t] = getsnapshot(obj);
>> seq
   seq = 178

>> t
   t = 
      scalar structure containing the fields:
      tv_sec = 56491 tv_usec = 320175

>> stop(obj) // To stop streaming

We can also set the brightness of video. Use the following to do so-

octave:> get(obj, "brightness")  //To get the current brightness value
ans =  100

octave:> set(obj, "brightness")  //Query possible range for brightness
ans =
 scalar structure containing the fields:
   min = 0
   max =  255
   step =  1
   default =  128

octave:> set(obj, "brightness", 100)  //Set a new value for brightness



You can perform many other image-processing functions on this too.


Published by


I am the one who discover myself daily through reading, writing, interacting with people and expressing my thoughts to inspire them if I would be able to bring a little change to the society through my work. I write blogs, participate in various social activities and want to be a Professional Speaker. Currently, I am pursuing my post graduation in Computer Applications from Guru Nanak Dev Engineering College, Ludhiana and I’m very much active in many technical & social communities.

3 thoughts on “Getting an image into octave from a local camera”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s