Sunday, September 20, 2009

OpenCV -- 1


For the virtual reality applications, another relevant library is the so-called
OpenCV, which is the abbreviation of Open Source Computer Vision Library. It is an open source available here. This library is written in C and C++, as well it is able to run under Linux, windows and even Mac OS X. The goal of OpenCV is to offer a simple-to-use computer vision infrastructure with high computational efficiency and a strong focus on realtime applications. It can take advantage of multicore processors. This library contains over 500 functions that contains lots of areas in vision, including factory product inspection, medical imaging, security, user interface, camera calibration, stereo vision and robotics. There is another additional library for the general purpose Machine Learning, too. Some common Virtual Reality applications, as Motion Tracking or 3D Pose Estimation can be implemented easily with the help of OpenCV. And here I would like to introduce how to use it under windows visual studio and how to create a openCV project:


1. Open Visual Studio, choose the item: Tools -> Options
2. In the list choose: Projects -> VC++ Directories
3. under "show Directories for" let's first choose "Library files" in the list box, click "Insert New" Icon to insert the lib path(usually after installation, it should be "C:\Program Files\OpenCV\lib")


And for "Include files" add the following paths:
C:\Program Files\OpenCV\cv\include
C:\Program Files\OpenCV\cxcore\include
C:\Program Files\OpenCV\otherlibs\highgui
C:\Program Files\OpenCV\cvaux\include
C:\Program Files\OpenCV\otherlibs\cvcam\include

And for "Source files" add the following paths
C:\Program Files\OpenCV\cv\src
C:\Program Files\OpenCV\cxcore\src
C:\Program Files\OpenCV\cvaux\src
C:\Program Files\OpenCV\otherlibs\highgui
C:\Program Files\OpenCV\otherlibs\cvcam\src\windows

Click the “OK” button, everything for the settings is fine. But during the project implementation, we need some tiny settings, too.

1. Create a new project with:  “File” -> "New" -> "Projects"
2. Choose "Win32 Application" or "Win32 console application"
3. Input the name of project and click "finish".
4. Set: "Project" -> "Properties"
5. choose "Link" tab -> "Input" -> "Additional Dependencies"
6. input the cv.lib, cxcore.lib, highgui.lib, cvaux.lib and cvcam.lib
 

After this is the time to enjoy the openCV!! Here I use a image reading sample code to read my picture, actually this function in Matlab image processing toolbox is very common, here with this example let's look at the first openCV code:

#include "highgui.h"

int main( int argc, char** argv )
{
//IplImage* img = cvLoadImage( "adrian.jpg" );
IplImage* img = cvLoadImage( "zhongshan.jpg" );
cvNamedWindow("Zhongshan", CV_WINDOW_AUTOSIZE );
cvShowImage("Zhongshan", img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow("Zhongshan");
}

And there is a video about the VS settings and creation as well as this sample code:


0 comments: