Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can't use the the Pre-built OpenCV 3.1.0 with Visual Studio 2010. The Windows installation contains binary for VS2013 and VS2015 only.

You have to build OpenCV from source following Installation by Making Your Own Libraries from the Source Files from 1st tutorial.

Suppose you have built a Release version of the library in C:\OpenCV\Build. Using VisualStudio, select the project "Install" and build it... all needed the files will be packaged in C:\OpenCV\Build\install

Define an env var that points to install setx -m OPENCV_ROOT C:\OpenCV\Build\install

OR, if you want, move this folder where you like

mv C:\OpenCV\Build\install C:\yourfolder
setx -m OPENCV_ROOT C:\yourfolder

Configure new projects for OpenCV

  • Compiler > Include dir: $(OPENCV_ROOT)\include
  • Linker >Lib dir: $(OPENCV_ROOT)\$(PLATFORM)\vc10\lib (v12 for VS2013, v14 for VS2105)
  • Linker >Additional Lib Files > add all opencv_*310.lib files available in the Lib dir

Finally you have to make available the OpenCV's DLL to your executables. You have 3 options

  • copy all DLLs from $(OPENCV_ROOT)\$(PLATFORM)\vc10\bin into your executable folder
  • OR copy all DLLs in a folder listed in the %PATH% env var
  • OR add the folder that contains the DLLs to your %PATH% env var

You can't use the the Pre-built OpenCV 3.1.0 with Visual Studio 2010. The Windows installation contains binary for VS2013 and VS2015 only.

EDIT : added some general infos

You have to build OpenCV from source source following Installation by Making Your Own Libraries from the Source Files from 1st tutorial.

Suppose I strongly suggest to build also the OpenCV Install project. image description

If you have built a Release version of the library in C:\OpenCV\Build. Using VisualStudio, select the project "Install" and build it... C:\OpenCV\Build\ than the Install project collects all needed the files will be packaged in C:\OpenCV\Build\install this is your OCV_ROOT path.

Define an env var that points to the install folder setx -m OPENCV_ROOT OCV_ROOT C:\OpenCV\Build\install

OR, if you want, , OR move this the folder where you likewant:

mv C:\OpenCV\Build\install C:\yourfolder
setx -m OPENCV_ROOT OCV_ROOT C:\yourfolder

Configure a new projects project for OpenCV

This is for Visual Studio but the concept is still valid for each IDE. Try to understand 3 basic and general rules:

  1. The compiler needs to know where are the include files
    • Compiler > Include dir: $(OPENCV_ROOT)\include
    • $(OCV_ROOT)\include
  2. The linker needs to know where are the library files and which libraries has to use
    • Linker >Lib dir: $(OPENCV_ROOT)\$(PLATFORM)\vc10\lib (v12 $(OCV_ROOT)\$(PLATFORM)\vc10\lib (vc12 for VS2013, v14 vc14 for VS2105)
    • Linker >Additional Lib Files > add all opencv_*310.libopencv_*(opencv_version).lib files available in the Lib dir

    Finally dir. If you have to make available the OpenCV's DLL to your executables. You have 3 options

    built a debug version of OpenCV the files will be opencv_*(opencv_version)d.lib
  3. The executables need to reach the DLLs
    • copy all DLLs from $(OPENCV_ROOT)\$(PLATFORM)\vc10\bin$(OCV_ROOT)\$(PLATFORM)\vc10\bin into your executable folder
    • OR copy all DLLs in a folder listed in the %PATH% env var
    • OR add the folder that contains the DLLs to your %PATH% env var

Additional tips for your Visual Studio+OpenCV projects

  • Only pure C++ is allowed (I mean no .NET/C#, no managed code like /clr)
  • Use right Runtime Library: Multi-threaded DLL (/MD) for your Release project and Multi-threaded Debug DLL (/MDd) for your Debug project
  • You could create a basic project configured as above and export it as template. Than you can easily create a new project from the template to get an OpenCV ready project
  • You could set all needed configuration into a Visual Studio New Properties file than attach this file to a new project to easily add the OpenCV build rules.