How to use OpenCV 2.0a in Visual Studio?

OpenCV 2.0 now uses CMake to organize the whole project. By default, it only provides linux library. So we need to compile it first.

Download Cmake for windows and install.

Go to C:\OpenCV2.0, execute the following cmd

 cmake . -G "Visual Studio 9 2008" 

Change "Visual Studio 9 2008" to your default compiler.

Cmake will generate a solution file (containing many projects) for you visual studio. Open it and build with “release”.

Add the following path to Tools–>Options–>Projects–>VC++ Directories–>Include files

C:\OpenCV2.0\include\opencv

Add following path to Tools–>Options–>Projects–>VC++ Directories–>Library files

C:\OpenCV2.0\lib\Release

When create a new project,

add following to “Project–>Properties–>Linker->Input–>Additional dependencies

cv200.lib cxcore200.lib highgui200.lib

Tested on OpenCV 2.0 on Visual Studio 2008

Related Post:

How to configue OpenCV 1.0 in Visual Studio – Reprice

Related Post

  1. nihan
    October 14th, 2009 | 7:18 pm

    Hi,
    can you say what you have mention in “Cmake will generate a solution file (containing many projects) for you visual studio. Open it and build with “release”.
    can you clearly say the step again.

  2. October 14th, 2009 | 8:41 pm

    @nihan:
    Open the solution file and build the entire solution with “release” configuration.

  3. nihan
    October 14th, 2009 | 8:45 pm

    thanx for quick reply, but stil i am having problem. can you explain how to build with release configuration?

  4. October 14th, 2009 | 9:49 pm

    @nihan:
    Visual studio… just use menu->build->build solution. before that, change the option of build on toolbar from “debug” to release (besides the run button). then wait..

    btw, i can not approve comments on wordpress… what’s wrong??

  5. nihan
    October 14th, 2009 | 10:06 pm

    hey sry to ask again and again. i know how to build solution but in opencv installation guide thy said that build OpenCV.sln in Release and Debug configurations. I am having problem in here? how to do that?

  6. October 18th, 2009 | 4:40 am

    [...] http://blog.qevan.com/posts/512.g Possibly related posts: (automatically generated)Rama setu: peoples’ movement [...]

  7. October 18th, 2009 | 4:48 am

    [...] http://blog.qevan.com/posts/512.g Possibly related posts: (automatically generated)Rama setu: peoples’ movement [...]

  8. hhflnny
    December 15th, 2009 | 10:15 am

    为何我用VC6编译的时候,总是有以下错误,还真的不知道如何改能才成功编译,谢谢!
    \OpenCV2.0\3rdparty\flann\algorithms\kdtree_index.h(648) : warning C4512: ‘KDTreeIndex’ : assignment operator could not be generated
    C:\OpenCV2.0\3rdparty\flann\algorithms\kdtree_index.h(60) : see declaration of ‘KDTreeIndex’
    C:\OpenCV2.0\3rdparty\flann\algorithms\kdtree_index.h(358) : error C2275: ‘KDTreeIndex::TreeSt’ : illegal use of this type as an expression
    C:\OpenCV2.0\3rdparty\flann\algorithms\kdtree_index.h(358) : error C2059: syntax error : ‘)’
    C:\OpenCV2.0\3rdparty\flann\algorithms\kdtree_index.h(382) : error C2275: ‘KDTreeIndex::TreeSt’ : illegal use of this type as an expression
    C:\OpenCV2.0\3rdparty\flann\algorithms\kdtree_index.h(382) : error C2059: syntax error : ‘)’
    C:\OpenCV2.0\3rdparty\flann\algorithms\kdtree_index.h(411) : error C2065: ‘min’ : undeclared identifier

  9. karlo
    December 19th, 2009 | 9:00 pm

    hello,
    I have a problem with OpenCV2.0. I buildt the libraries with my Visual Studio 2008 compiler using CMake.
    The application works fine on the same computer.
    But when I use a different computer the application stops with an unknown error after opening an image and using cvResize.
    I put the dlls cvaux200.dll cv200.dll highgui200.dll opencv_ffmpeg200.dll cxts200.dll ml200.dll and cxcore200.dll into the same directory.
    Also I installed Microsoft Visual C++ Redistributable Package(both vcredist_x86, as well as vcredist_x86_sp1, 2008 and 2005), but unfortunately to no use.
    Any idea what else the other computer needs.

    Best regards
    Karlo

  10. December 23rd, 2009 | 1:37 pm

    @karlo:Try to use dependency walker to find what else your application needs.

  11. December 23rd, 2009 | 1:38 pm

    @hhflnny:
    从错误信息里,你也看到了吧, 是3rdparty里的问题. 我没用过3rdparty的东西, 不清楚怎么回事.
    你用vc6的, 我想也许有这个3rdparty的包并不一定支持vc6. (vc6里的一些语法并不规范)

  12. melissa
    December 30th, 2009 | 1:16 pm

    hi, when i try to compile a project, this is the result:

    1>Linking…
    1>LINK : fatal error LNK1104: cannot open file ‘cv200.lib’

    i followed all the steps :’(

  13. December 30th, 2009 | 1:54 pm

    @melissa:
    That’s because the lib file can not be found in your search path. try to add the folder with this lib to your visual studio as I wrote in my post.

  14. melissa
    December 30th, 2009 | 2:14 pm

    hello,
    thanks for the quick reply.

    i’m sorry to ask this, i’m a complete noob in trying this one out. When I followed the step “Build with release”, it says

    14>c:\opencv2.0\include\opencv\cxmisc.h(57) : fatal error C1083: Cannot open include file: ‘omp.h’: No such file or directory

    and in the end of the compilation:

    ========== Build: 0 succeeded, 16 failed, 9 up-to-date, 3 skipped ==========

    is that really okay? :( and btw, I can’t find these three:

    cv200.lib cxcore200.lib highgui200.lib

  15. December 30th, 2009 | 2:22 pm

    @melissa:
    If you didn’t build the opencv2.0 successfully, you can not use it in your app properly. Please finish the build first.
    Did you create the solution file with cmake as the first step in my post?
    I don’t have visual studio and opencv2.0 at hand, can not try it for now. sorry.

  16. melissa
    December 30th, 2009 | 2:29 pm

    oh. :( I waited til the building process is finished. But it always says the same thing. Is there something wrong with my visual c++ 2008 express edition? :(

  17. December 30th, 2009 | 2:35 pm

    @melissa:
    maybe. But no need to be VS2008, 2005 can also work. the 1st priority is to build of opencv2.0 successfully. I tried the build at the time of this post. Also it could be due to change of opencv 2.0.
    I used opencv 2.0 because I need its build-in ffmpeg support (can handle all video format). If you do not need this feature, you can go back to opencv 1.x.

  18. melissa
    December 30th, 2009 | 2:47 pm

    I’m not really sure. But my project is about reading road traffic flow data, and estimating mean speed. I just thought that since OpenCV has a built in hough transform fxn, I’d like to try it.

    If it’s okay, do you have a YM ID?

    Thanks so much

  19. December 31st, 2009 | 4:46 pm

    @Melissa:
    sent your email.

  20. shri
    January 6th, 2010 | 6:41 pm

    This will not work under vs2008 express edition with opencv2.0 even though i followed the instructions.

    when build with cmake no errors was displayed but when complied in vs2008 in release mode lots of errors came

    please any one will post the installation guide for opencv2.0 on vs2008
    thankyou in advance

  21. Zaka
    January 16th, 2010 | 1:08 am

    can you please give these steps using screenshots??
    That will really help us..

  22. January 17th, 2010 | 12:42 pm

    @Zaka, Sorry, not at this moment. I don’t have VS for now. It is not difficult. I believe you can make it.

  23. Zaka
    January 17th, 2010 | 12:53 pm

    Thanks for you quick response, actually i read a pdf in which opencv v4 and visual c++ 6.0 is used, as now opencv 2.0 is available so i am using that with visual c++ 6.0… but i am getting this error (cannot open include file: ‘cxmisc.h’) i have no idea why this is giving this error…
    i read this document…

    http://www.scribd.com/doc/16952621/OpenCV-Installation-and-Getting-Started-Guide

    please help me i am so close…

  24. January 18th, 2010 | 10:07 am

    @zaka,

    That is not v4, but just beta4. Now the latest is 2.0a. Do not get confused. If you do not need new features in 2.0 like multi-format video support and template support, just use 1.0 release which is more stable. And, they have pre-built lib and dll for you. You just need to add the path.
    Follow this post:
    http://blog.qevan.com/posts/466.g
    Good luck~

  25. Elemental
    January 20th, 2010 | 10:13 am

    Hello,

    Thank you for this tutorial, I really found out what I needed to do to work with OpenCV in its 2nd version.

    Good work, keep on it :)

  26. sam
    January 20th, 2010 | 5:41 pm

    my new solution was correctly built, but in run, it gave me this message:
    this application has failed to start beavause highgui200.dll was not found . Reinstall the application may fix this problem
    thanks in advance

  27. January 20th, 2010 | 5:45 pm

    #sam, copy dll files into your running directory.

  28. February 9th, 2010 | 4:24 pm

    Hi there,
    I have similar problems to those above.
    First off I tried the OpenCV website – but as I had problems I asked the internet about my problem and it led me here.

    I have:
    Windows7 (build 7100)
    Visual_Studio_Express_2008,
    OpenCV_2.0a,
    CMake_2.8

    From the OpenCV2.0 directory I ran:
    cmake . -G “Visual Studio 9 2008″

    I opened the generated OpenCV2.0/OpenCV.sln (27 projects).
    I changed to Release build, and changed Include and Directory paths as above.
    I tried building all 27 projects (ALL_BUILD) – this failed. I tried building the individual projects ‘cxcore’ and ‘cv’ by themselves.

    Everything failed with the error:
    c:\opencv2.0\include\opencv\cxmisc.h(57) : fatal error C1083: Cannot open include file: ‘omp.h’: No such file or directory

    After a bit of research it seems like omp.h is part of a processor multi-thread implementation, and can be turned off with cmake (i used the cmake-gui tool to turnoff ENABLE_OPENMP compiler flag and remake the VS solution).

    I then had the new problem:
    LINK : fatal error LNK1104: cannot open file ‘VCOMP.lib’
    which is nowhere on my machine.

    The internet then told me that this lib is usually shipped with Visual_Studio – but not Visual_Studio_Express
    http://software.intel.com/en-us/forums/showthread.php?t=65145

    So I tried the suggested and added ‘vcomp.lib’ to
    project_name > Properties > Linker > Input > Ignore_Specific_Library
    for the projects:
    cxcore, highgui, createsamples, haartraining
    And everything compiled….. now to write some code..

  29. February 9th, 2010 | 4:30 pm

    @Alister, Thanks!
    This is very useful for VS Express users.

  30. prakash
    March 23rd, 2010 | 7:05 pm

    hi
    I want to use cvblobslib
    but not able to use it in visual studio 2008
    pls help

  31. Jonny
    September 14th, 2010 | 2:34 pm

    maybe help:
    install opencv 2.0 to visual c++ 2010 Express, here: http://arie-fardiansyah.blogspot.com/2010/09/install-opencv-20-ke-visual-c-2010.html

    install opencv 2.0 to Dev-C++ 4.9.9.2, here: http://arie-fardiansyah.blogspot.com/2010/09/install-opencv-20-ke-dev-c-4992.html

  32. bilal
    February 16th, 2011 | 5:49 pm

    why to set path every time we make a new program??
    plz help!!

  33. February 17th, 2011 | 3:11 am

    @bilal, That’s very common. You cannot add every lib in your computer to every project. but if you insist, you can add the dir to vc directories, i guess.

  34. May 14th, 2011 | 4:36 am

    I have :
    win 7 ultimate
    opencv-2.1.0
    cmake-2.8
    VS2008 prof

    i follow all opencv steps:
    1) install CMake and configure – generate succesfully
    2)build opencv project succesfully (debug then release)
    3)add to include , libraries and source their directories for debug and release created folders,, through tool–>options–>project and solution–>VC++ directories
    4)linker–>input–>additional dependencies–>i add lib files
    5)configure my system to know openCV through (my computer–>properties–>advanced–>enviromental variables–>path–>edit–>and add C\opencv\build\lib\ release and Debug files,, then restart my computer
    but when running my code i found :
    1>LINK : fatal error LNK1104: cannot open file ‘cv200.lib; cvaux200.lib; highgui200.lib; cxcore200.lib; ml200.lib;opencv_ffmpeg200.lib; cxts200.lib;’

    so really i don’t know why??!!
    thanx alot

  35. May 14th, 2011 | 2:51 pm

    @norhan,

    I cannot try for you because I don’t have windows any more.
    Linking error of lib files not found must be caused by missing path in your project settings.