Capturing images from webcams using openCV in Ubuntu 11.04

opencv 2.3.1-video-capture-image

opencv 2.3.1-video-capture-image

This is a simple example of capturing live images from webcams using the new installed OpenCV 2.3.1 in the Ubuntu. The relevant information of OpenCV 2.3.1 install can see my previous posts –


Installing openCV in Ubuntu with pandaboard part 1
Installing openCV in Ubuntu with pandaboard part 2
Installing openCV in Ubuntu with pandaboard part 3 – the network proxy
Installing openCV in Ubuntu with pandaboard part 4 – compiling openCV 2.3.1
Installing openCV in Ubuntu with pandaboard part 5 – running openCV 2.3.1 examples, and
Tutorial: A Comprehensive Guide to Installing and Configuring OpenCV 2.3.1 on Ubuntu

This simple example includes lines of source codes using the new OpenCV API, for your convenience.

The source code

#include “opencv2/video/tracking.hpp”
#include “opencv2/imgproc/imgproc.hpp”
#include “opencv2/highgui/highgui.hpp”
#include “opencv2/core/core.hpp”#include
using namespace std;
using namespace cv;int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
{cout<

g++ `pkg-config opencv –cflags` `pkg-config opencv –libs` readwebcam.cpp -o readwebcam

The source file compiling

Save the source file as ‘readwebcam’ for example, go to the directory containing the file.

Open the terminal, and type in the command like:

g++ `pkg-config opencv –cflags` `pkg-config opencv –libs` readwebcam.cpp -o readwebcam

Then run it:

./readwebcam

Here it is! Now let’s start rocking the hand gesture recognition!

Author: Andol Li

A HCI researcher, a digital media lecturer, an information product designer, and a python/php/java coder.

Leave a comment
Due to technical adjustments, the comment function is shortly closed and will be re-openning soon. Thanks.


Copyrights 2006-2017 © All rights reserved
Theme Tree2, re-designed by Andol Li, powered by WordPress and Bootsrap
WWW.ANDOL.ME | 浙ICP备15040508号-1
公安备案图标 浙公网安备33010602004018号
Back to top