Saturday, February 18, 2012

Configure OpenCV 2.3.1 on visual studio 2010

Three steps:
1 Install vs 2010
http://jianmin2.pixnet.net/blog/post/25132224-visual-studio-2010-ultimate%E4%B8%8B%E8%BC%89

2 Install opencv 2.3.1
2.1 download opencv 2.3.1 from
http://surfnet.dl.sourceforge.net/project/opencvlibrary/opencv-win/2.3.1/OpenCV-2.3.1-win-superpack.exe
2.2 Download CMake
http://www.cmake.org/cmake/resources/software.html 
2.3 Compile opencv by cmake
See http://blog.xuite.net/jack.ycchuang/jack/42282952. See "用cmake把opencv 改成vs2010要的" part.
2.4 Compile using Visual Studio
Go to opencv->build->INSTALL. It is visual studio project file, double click opening using vs2010, and run it/debug.

3. After the installation of opencv, we need to do configuration on vs2010, so it can find the head files (.h) and the libraries.
The details is below:
http://stackoverflow.com/questions/7011238/opencv-2-3-c-visual-studio-2010
Note that "C:\opencv\build\common\tbb\ia32\vc10" should also be added into "environment variable". Append it to the value of system variable "Path". This is used to add "tbb.dll" to visual studio.

4. Test if the whole configuration is correct
Go to http://dasl.mem.drexel.edu/~noahKuntz/openCVTut1.html and copy the "imageLoad" function to a source file in vs2010, say "main.cpp".
No the directory is cvLoadImage("image_path") function is tricky. "image_path" can either be absolute or relative. If it is absolute, it has to be in the form of "C:\\***\\lena.jpg". If it is the relative directory, the image has to be put in the directory which is the same as "main.cpp", where the project file stores. Also note the image name cannot have suffix, for example, it has to be named as "lena", not "lena.jpg". However, in cvLoadImage() function, the image name has to be "lena.jpg".

If you can see the smile of Lena on the screen, then you got a correct configuration of OpenCV on vs2010. Cheers :-)

No comments:

Post a Comment