Wednesday, February 2, 2011

OpenCV on Visual Studio 2008

Hi Guys. In this post I explain:

  • Configuring OpenCV 2.1 on Visual Studio 2008.
  • A sample OpenCV 2.1 program to run on Visual Studio.
Click here for Configuring OpenCV 2.2 on Linux

Btw, My other programs in OpenCV will be posted here.

I see lot of you facing problems in configuring OpenCV 2.1 for Visual Studio on Windows OS. In this post I seek to explain the way it is to be configured.

Step1: Download
Download OpenCV from
Present version is 2.2, but I show here working with OpenCV 2.1 (configuring OpenCV 2.2 will be the same if you follow this procedure).

Step2: Install OpenCV
Double click to install the downloaded file. I am sure nobody needs help on this. It usually is installed in C:\ as "C:\OpenCV2.1"

Steps 3 to 14: Configure OpenCV with Visual Studio 2008

Step3: Open Visual Studio 2008. I am assuming you have already installed Visual Studio with VIsual C++ editor. Select New->Project

Step4: Give the name of the project, the name i've given is "OpenCam". Make sure that it is a "Win32 Console Application" program.

Step5: Right click on the Project in Solution Explorer and select properties.

Step6: Now we configure the Visual Studio to include the headers that come with OpenCV 2.1. Go to Configuration Properties->C/C++->General->Additional Include Directories and select to add new directories.

Step 7: Open the OpenCV installation directory, browse through the folders "C:\OpenCV2.1\include\opencv" and copy the address to the path. Basically, what we are doing here is to browse into the OpenCV  C/C++ headers folder (look for ".h" files). Paste it into the Visual Studio window already opened (into additional include directories). It will look something as show below. Press OK.

Step8:  Now we configure the Visual Studio to look for libraries installed (OpenCV libraries).Go to Linker->input->Additional Dependencies and click to add new libraries.

Step 9: Open the OpenCV installation directory, browse through the folders "C:\OpenCV2.1\lib" and copy the address to the path. Basically, what we are doing here is to browse into the OpenCV C/C++ libraries folder (look for ".lib" files). Paste it into the Visual Studio window already opened (into additional dependencies).

Step 10: Add the libraries "cv210.lib", "cvaux210.lib", "cxcore210.lib", "highgui210.lib" into the additional dependencies.Please make sure that you give complete path to the above mentioned ".lib" files. It SHOULD look something as below. 

Step 11: Press OK. If you do not have a program of your own to run by copying the following, else proceed to Step 12.

Step 12: Now its time to build the solution. Go to Build->Build Solution.

Step 13: If everything is right (it will be if you are following the exact steps that I'm following here) something like this should show up in the output window.

Step 14: Now its time to run the program. Click on run and BING! Its there. You should be able to see yourselves (if you are running the program and assuming you have a webcam of your own attached to your computer).

Basically what we've done is give "exact path" to the include directories folder and "excat path" to the ".lib" files that are to be included to run the program and it works.

Cheers. Check out the other OpenCV articles over here.


  1. i had done the same thing..but its showing errors..wat to doo??

  2. Hi
    is not visible the two include; highgui.h and cv.h

  3. If you are using OpenCV 2.2, headers will be under

    C:\Program Files\OpenCV2.2\include\opencv


    C:\Program Files\OpenCV2.2\include\

    So yo need to add both folders above in STEP 6.

    If you are using OpenCV 2.1, headers will be under:


    So you need to add the above folder in STEP6.

  4. Also add the following libraries in 2.2







  5. Hi,
    I'm usin OpenCV2.1 under Win7 and a HP 3100 HD WebCam set to 720p.
    I compile your example without any error, but when i run the program, a black screen appear. If I move the mouse into the black screen the pointer change in a white cross.
    Do you have any idea because the image do not appear?

  6. the above code is the program. It would be a issue with the OS/Drivers rather than the program. Try closing all other programs and then try the above methods

  7. Thanks for the post, solved my problem of setting OpenCV 2.1 with Visual Studio 2008.

  8. Hi, Im jyothi,

    i have tried to execute the above code and followed all steps properly....but im getting output but not my img..just blank gray windoe..
    even my web cam is on im not getting my webcam seeing me.

  9. It might probably be due to improper image capturing. You can try different parameter values in CvCapture* capture = cvCaptureFromCAM(1); instead of "1". Try -1, 0, 2, etc. I think -1 points to next available camera. Also check if your Webcam works with a different software(logitech, etc).

  10. its giving error
    2>------ Skipped Build: Project: pro1PS, Configuration: Debug Win32 ------
    2>Project not selected to build for this solution configuration

    please help

  11. hey
    i have tried the entire procedure and I am constantly getting this error:
    fatal error C1083: Cannot open include file: 'C:\OpenCv2.1\include\cv.h': No such file or directory.
    I have set the environment variable also. Please do reply.Getting really stuck

  12. Hey, I've done exactly what you have done, but I am getting errors.
    I am using openCV2.1 and vb 2008 c++

    the errors are :
    error C2006: '#include' : expected a filename, found 'newline'
    fatal error C1083: Cannot open include file: '': No such file or directory

    Could you please help me

  13. It was a formatting error on the website. Please look at the code now. I'll soon be re-posting this with latest OpenCV version on latest version of Visual Studio.

  14. I am using Visual studio 2008 and OpenCV 2.1 it is showing 1>LINK : fatal error LNK1104: cannot open file 'C:\OpenCV2.1\lib.obj' on your demo program

  15. I think its an issue with your Path settings that I mentioned in my post above. Please make sure that the files exist that you are pointing to.

  16. hi, i add all dll file but when i run the file, it saying highgui210.dll file is missing.

    its crazy cas i add all the lin file according to u r ins-traction whic is step no 10.