Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Guide for installing and compiling OpenCV with CMake

After spending many hour doing trial and error in order to compile OpenCV with Eigen, TBB I made a simple text installation guide.

If you want to add to this or make corrections feel free.

A) Get OpenCV source code Open Folder called opencv Fork from github: https://github.com/Itseez/opencv , into subfolder sources Open folder next to sources called build

Now you have:
    opencv--build
          |-sources

Note: You can download the source directly as a zip file or clone it using git, tortoiseGit, svn or tortoise SVN. I cloned the file using TortoiseGit and renamed the file opencv to sources

How to clone using git at command line?
Open a command line window
cd to d:
mkdir opencv
type: git clone https://github.com/Itseez/opencv.git

You should get the following message:
Cloning into 'opencv'...

Soon you will have OpenCV source code in subfolder named "d:\opencv\opencv"
Move the contents of 'd:\opencv\opencv' to 'd:\opencv\sources'

B) Download TBB Under build open subfolder common and put Itels tbb into it

C) Download Eigen and also put it under build/common

Make sure you put the entire "EIGEN" directory under common. It should include at least "eigen" and "unsupported"

D) Download CMake

E) Define as system variables CVROOT = d:\opencv\build\ TBBROOT = %CVROOT%\common\tbb\bin\intel64\ (or instead of intel64 use ia32 if you only have x86 processor)

How to check if you entered the path correctly? AFTER entering path and ONLY AFTER entering and applying all your changes open a DOS cmd window. 
Type %CVROOT% at the command line
If you get the following message:

'd:\OpenCV\opencv_v1\' is not recognized as an internal or external command,
operable program or batch file.

You have entered the path correctly and now it is a system variable

F) Add to Path, the following: 1) C:\Program Files (x86)\CMake 2.8\bin 2) %CVROOT%\build\x64\vc12\
3) %CVROOT%\build\common\tbb\bin\intel64\vc12\

Note: use V12 for Visual studio 2013. If you are using an earlier version for example Visual Studio 2010 instead of vc12 use vc10.
How to know which number is the right one for you? Take a look at project configuration properties->General->Platform Toolset

How to check if you entered the Paths correctly?
Type Path at the command line. You should see the Paths you just added in the list

G) Open Cmake gui

Enter the following at:
Where is the Source code: $(CVROOT)/sources
Where to build the binaries: $(CVROOT)/Build

H) Configure Cmake Click on configure and you will be asked to specify the compiler. For Visual Studio 2013 specify Visual Studio 12 win64 Make sure to choose "Use native compilers"

-Click finish
-Check the “BUILD_EXAMPLES” option (in the "BUILD" group). 
-Check the “WITH_TBB” option (in the "BUILD" group). 
-Set EIGEN_INCLUDE_PATH as "d:/opencv/build/common"
-Mark in WITH -WITH_EIGEN and -WITH_TBB
-In TBB group set
    -TBB_INCLUDE_DIRS : D:/opencv/build/common/tbb/include/
    -TBB_LIB_DIR : D:/opencv/build/common/tbb/lib/intel64/vc12

Click on generate after a successful configure. Pay attention to errors and warnings you get from configure
click to hide/show revision 2
Fixed types and added section I)

Guide for installing and compiling OpenCV with CMakeCMake and Visual Studio 2013

After spending many hour doing trial and error in order to compile OpenCV with Eigen, TBB I made a simple text installation guide.

If you want to add to this or make corrections feel free.

A) Get OpenCV source code Open Folder called opencv Fork from github: https://github.com/Itseez/opencv , into subfolder sources Open folder next to sources called build

Now you have:
    opencv--build
          |-sources

Note: You can download the source directly as a zip file or clone it using git, tortoiseGit, svn or tortoise SVN. I cloned the file using TortoiseGit and renamed the file opencv to sources

How to clone using git at command line?
Open a command line window
cd to d:
mkdir opencv
type: git clone https://github.com/Itseez/opencv.git

You should get the following message:
Cloning into 'opencv'...

Soon you will have OpenCV source code in subfolder named "d:\opencv\opencv"
Move the contents of 'd:\opencv\opencv' to 'd:\opencv\sources'

B) Download TBB Under build open subfolder common and put Itels tbb into it

C) Download Eigen and also put it under build/common

Make sure you put the entire "EIGEN" directory under common. It should include at least "eigen" and "unsupported"

D) Download CMake

E) Define as system variables CVROOT = d:\opencv\build\ TBBROOT = %CVROOT%\common\tbb\bin\intel64\ (or instead of intel64 use ia32 if you only have a x86 processor)

How to check if you entered the path correctly? AFTER entering path and ONLY AFTER entering and applying all your changes open a DOS cmd window. 
Type %CVROOT% at the command line
If you get the following message:

'd:\OpenCV\opencv_v1\' 'd:\opencv\' is not recognized as an internal or external command,
operable program or batch file.

You have entered the path correctly and now it is a system variable

F) Add to Path, the following: 1) C:\Program Files (x86)\CMake 2.8\bin 2) %CVROOT%\build\x64\vc12\
3) %CVROOT%\build\common\tbb\bin\intel64\vc12\

Note: use V12 for Visual studio 2013. If you are using an earlier version for example Visual Studio 2010 instead of vc12 use vc10.
How to know which number is the right one for you? Take a look at project configuration properties->General->Platform Toolset

How to check if you entered the Paths correctly?
Type Path at the command line. You should see the Paths you just added in the list

G) Open Cmake gui

Enter the following at:
Where is the Source code: $(CVROOT)/sources
d:/opencv/sources
Where to build the binaries: $(CVROOT)/Build
d:/opencv/Build

H) Configure Cmake Click on configure and you will be asked to specify the compiler. For Visual Studio 2013 specify Visual Studio 12 win64 Make sure to choose "Use native compilers"

-Click finish
-Check the “BUILD_EXAMPLES” option (in the "BUILD" group). 
-Check the “WITH_TBB” option (in the "BUILD" group). 
-Set EIGEN_INCLUDE_PATH as "d:/opencv/build/common"
-Mark in WITH -WITH_EIGEN and -WITH_TBB
-In TBB group set
    -TBB_INCLUDE_DIRS : D:/opencv/build/common/tbb/include/
    -TBB_LIB_DIR : D:/opencv/build/common/tbb/lib/intel64/vc12

Click on generate after a successful configure. Pay attention to errors and warnings you get from configure

I) Open OpenCV.sln and compile in release and debug mode

Guide for installing and compiling OpenCV with CMake and Visual Studio 2013

After spending many hour doing trial and error in order to compile OpenCV with Eigen, TBB I made a simple text installation guide.

If you want to add to this or make corrections feel free.

A) Get OpenCV source code Open Folder called opencv Fork from github: https://github.com/Itseez/opencv , into subfolder sources Open folder next to sources called build

Now you have:
    opencv--build
          |-sources

Note: You can download the source directly as a zip file or clone it using git, tortoiseGit, svn or tortoise SVN. I cloned the file using TortoiseGit and renamed the file opencv to sources

How to clone using git at command line?
Open a command line window
cd to d:
mkdir opencv
type: git clone https://github.com/Itseez/opencv.git

You should get the following message:
Cloning into 'opencv'...

Soon you will have OpenCV source code in subfolder named "d:\opencv\opencv"
Move the contents of 'd:\opencv\opencv' to 'd:\opencv\sources'

B) Download TBB Under build open subfolder common and put Itels tbb into it

C) Download Eigen and also put it under build/common

Make sure you put the entire "EIGEN" directory under common. It should include at least "eigen" and "unsupported"

D) Download CMake

E) Define as system variables CVROOT = d:\opencv\build\ TBBROOT = %CVROOT%\common\tbb\bin\intel64\ (or instead of intel64 use ia32 if you only have a x86 processor)

How to check if you entered the path correctly? AFTER entering path and ONLY AFTER entering and applying all your changes open a DOS cmd window. 
Type %CVROOT% at the command line
If you get the following message:

'd:\opencv\' is not recognized as an internal or external command,
operable program or batch file.

You have entered the path correctly and now it is a system variable

F) Add to Path, the following: 1) C:\Program Files (x86)\CMake 2.8\bin 2) %CVROOT%\build\x64\vc12\
3) %CVROOT%\build\common\tbb\bin\intel64\vc12\

Note: use V12 for Visual studio 2013. If you are using an earlier version for example Visual Studio 2010 instead of vc12 use vc10.
How to know which number is the right one for you? Take a look at project configuration properties->General->Platform Toolset

How to check if you entered the Paths correctly?
Type Path at the command line. You should see the Paths you just added in the list

G) Open Cmake gui

Enter the following at:
Where is the Source code: d:/opencv/sources
Where to build the binaries: d:/opencv/Build

H) Configure Cmake Click on configure and you will be asked to specify the compiler. For Visual Studio 2013 specify Visual Studio 12 win64 Make sure to choose "Use native compilers"

-Click finish
-Check the “BUILD_EXAMPLES” option (in the "BUILD" group). 
-Check the “WITH_TBB” option (in the "BUILD" group). 
-Set EIGEN_INCLUDE_PATH as "d:/opencv/build/common"
-Mark in WITH -WITH_EIGEN and -WITH_TBB
-In TBB group set
    -TBB_INCLUDE_DIRS : D:/opencv/build/common/tbb/include/
    -TBB_LIB_DIR : D:/opencv/build/common/tbb/lib/intel64/vc12

Click on generate after a successful configure. Pay attention to errors and warnings you get from configure

I) Open OpenCV.sln and compile in release and debug mode

I would like to give credit to following link which inspired this Guide

click to hide/show revision 4
Removing recommendation to check BUILD_TBB in BUILD group. This is only a valid option if you are compiling for ARM

Guide for installing and compiling OpenCV with CMake and Visual Studio 2013

After spending many hour doing trial and error in order to compile OpenCV with Eigen, TBB I made a simple text installation guide.

If you want to add to this or make corrections feel free.

A) Get OpenCV source code Open Folder called opencv Fork from github: https://github.com/Itseez/opencv , into subfolder sources Open folder next to sources called build

Now you have:
    opencv--build
          |-sources

Note: You can download the source directly as a zip file or clone it using git, tortoiseGit, svn or tortoise SVN. I cloned the file using TortoiseGit and renamed the file opencv to sources

How to clone using git at command line?
Open a command line window
cd to d:
mkdir opencv
type: git clone https://github.com/Itseez/opencv.git

You should get the following message:
Cloning into 'opencv'...

Soon you will have OpenCV source code in subfolder named "d:\opencv\opencv"
Move the contents of 'd:\opencv\opencv' to 'd:\opencv\sources'

B) Download TBB Under build open subfolder common and put Itels tbb into it

C) Download Eigen and also put it under build/common

Make sure you put the entire "EIGEN" directory under common. It should include at least "eigen" and "unsupported"

D) Download CMake

E) Define as system variables CVROOT = d:\opencv\build\ TBBROOT = %CVROOT%\common\tbb\bin\intel64\ (or instead of intel64 use ia32 if you only have a x86 processor)

How to check if you entered the path correctly? AFTER entering path and ONLY AFTER entering and applying all your changes open a DOS cmd window. 
Type %CVROOT% at the command line
If you get the following message:

'd:\opencv\' is not recognized as an internal or external command,
operable program or batch file.

You have entered the path correctly and now it is a system variable

F) Add to Path, the following: 1) C:\Program Files (x86)\CMake 2.8\bin 2) %CVROOT%\build\x64\vc12\
3) %CVROOT%\build\common\tbb\bin\intel64\vc12\

Note: use V12 for Visual studio 2013. If you are using an earlier version for example Visual Studio 2010 instead of vc12 use vc10.
How to know which number is the right one for you? Take a look at project configuration properties->General->Platform Toolset

How to check if you entered the Paths correctly?
Type Path at the command line. You should see the Paths you just added in the list

G) Open Cmake gui

Enter the following at:
Where is the Source code: d:/opencv/sources
Where to build the binaries: d:/opencv/Build

H) Configure Cmake Click on configure and you will be asked to specify the compiler. For Visual Studio 2013 specify Visual Studio 12 win64 Make sure to choose "Use native compilers"

-Click finish
-Check the “BUILD_EXAMPLES” option (in the "BUILD" group). 
-Check the “WITH_TBB” option (in the "BUILD" group). 
-Set EIGEN_INCLUDE_PATH as "d:/opencv/build/common"
-Mark in WITH WITH, -WITH_EIGEN and -WITH_TBB
-In TBB group set
    -TBB_INCLUDE_DIRS : D:/opencv/build/common/tbb/include/
    -TBB_LIB_DIR : D:/opencv/build/common/tbb/lib/intel64/vc12

Click on generate after a successful configure. Pay attention to errors and warnings you get from configure

I) Open OpenCV.sln and compile in release and debug mode

I would like to give credit to following link which inspired this Guide

click to hide/show revision 5
Correcting Errors and adding more information

Guide for installing and compiling OpenCV with CMake and Visual Studio 2013

After spending many hour doing trial and error in order to compile OpenCV with Eigen, TBB I made a simple text installation guide.

If you want to add to this or make corrections feel free.

A) Get OpenCV source code Open Folder called opencv Fork from github: https://github.com/Itseez/opencv , into subfolder sources Open folder next to sources called build

Now you have:
    opencv--build
          |-sources
'-sources

Note: You can download the source directly as a zip file or clone it using git, tortoiseGit, svn or tortoise SVN. I cloned the file using TortoiseGit and renamed the file opencv to sources

How to clone using git at command line?
Open a command line window
cd to d:
mkdir opencv
type: git clone https://github.com/Itseez/opencv.git

You should get the following message:
Cloning into 'opencv'...

Soon you will have OpenCV source code in subfolder named "d:\opencv\opencv"
'd:\opencv\opencv'
Move the contents of 'd:\opencv\opencv' to 'd:\opencv\sources'

Here is really [good tutorial](http://answers.opencv.org/question/16726/first-steps-to-github-need-some-help-adding/) on using Git to clone source code from Github

B) Download TBB Under build open subfolder common and put Itels Itel's tbb into it

C) Download Eigen and also put it under build/common

Make sure you put the entire "EIGEN" "Eigen" directory under common. It should include at least "eigen" and "unsupported"

D) Download CMake

E) Define as system variables CVROOT variable OPENCV64_DIR = d:\opencv\build\ TBBROOT = %CVROOT%\common\tbb\bin\intel64\ (or instead of intel64 use ia32 if you only have a x86 processor)d:/opencv/build/

How to check if you entered the path correctly? AFTER entering path and ONLY AFTER entering and applying all your changes open a DOS cmd window. 
Type %CVROOT% %OPENCV64_DIR% at the command line
If you get the following message:

'd:\opencv\' 'd:/opencv/build/' is not recognized as an internal or external command,
command, operable program or batch file.

You have entered the path correctly and now it is a system variable

F) Add to Path, the following: 1) C:\Program Files (x86)\CMake 2.8\bin 2.8\bin; 2) %CVROOT%\build\x64\vc12\
%OPENCV64_DIR%bin\Debug\; 3) %CVROOT%\build\common\tbb\bin\intel64\vc12\%OPENCV64_DIR%bin\Release\; 4) %OPENCV64_DIR%common\tbb\bin\intel64\vc12\;

Note: use Use V12 for Visual studio 2013. If you are using an earlier version for example Visual Studio 2010 instead of vc12 use vc10.
How to know which number is the right one for you? Take a look at project configuration properties->General->Platform Toolset

How to check if you entered the Paths correctly?
Type Path at the command line. You should see the Paths you just added in the list

G) Open Cmake gui

Enter the following at:
Where is the Source code: d:/opencv/sources
Where to build the binaries: d:/opencv/Build
d:/opencv/build

H) Configure Cmake Cmake

Click on configure and you will be asked to specify the compiler. For You can use Native compilers but expect no guarantees of success. Rather specify the compiler. The recommend option for x64 architecture regardless of whether you have Intel or AMD microprocessor is to use AMD64. Yes this is confusing but AMD64 is only called that since AMD made a x64 processor first.

-Define native compiler as: c:\Program Files (x86)\Microsoft Visual Studio 2013 specify Visual Studio 12 win64
    Make sure to choose "Use native compilers"

-Click finish
12.0\VC\bin\amd64\cl.exe
-Check the “BUILD_EXAMPLES” option (in the "BUILD" group). 
-Check the “WITH_TBB” option (in the "WITH" group). 
-Set EIGEN_INCLUDE_PATH as "d:/opencv/build/common"
"d:/opencv/build/common/eigen" (eigen must include a) Eigen b) unsupported)
-Mark in WITH, WITH -WITH_EIGEN and -WITH_TBB
-In TBB group set
    -TBB_INCLUDE_DIRS : D:/opencv/build/common/tbb/include/
    -TBB_LIB_DIR : D:/opencv/build/common/tbb/lib/intel64/vc12
-ENABLE->ENABLE_AVX This is optional. Try it at your own risk. I have not tested it yet

Note that sometimes you will have to configure incrementally. Meaning that not all of the options will be available on first try. They might show up marked in red and then you have to pay attention to them. Keep on going until you no longer have red lines in the CMake GUI.

Click on generate after a successful configure. Pay attention to errors and warnings you get from configure

I) Open OpenCV.sln and compile in release and debug mode

I would like to give credit to following Note: Once you define the compiler is his impossible to to make changes. UNLESS you delete the ENTIRE build directory. This is the only option that worked for me.

This link which inspired this guide and has useful illustrations. Though some of the details are incorrect so beware.

I also recommend reading the following Installation Guide on how to use Cmake for Visual studio by @StevenPuttemans

Guide for installing and compiling OpenCV with CMake and Visual Studio 2013

After spending many hour doing trial and error in order to compile OpenCV with Eigen, TBB I made a simple text installation guide.

If you want to add to this or make corrections feel free.

A) Get OpenCV source code Open Folder called opencv Fork from github: https://github.com/Itseez/opencv , into subfolder sources Open folder next to sources called build

Now you have:
    opencv--build
          '-sources

Note: You can download the source directly as a zip file or clone it using git, tortoiseGit, svn or tortoise SVN. I cloned the file using TortoiseGit and renamed the file opencv to sources

How to clone using git at command line?
Open a command line window
cd to d:
mkdir opencv
type: git clone https://github.com/Itseez/opencv.git

You should get the following message:
Cloning into 'opencv'...

Soon you will have OpenCV source code in subfolder named 'd:\opencv\opencv'
Move the contents of 'd:\opencv\opencv' to 'd:\opencv\sources'
 

Here is a really [good tutorial](http://answers.opencv.org/question/16726/first-steps-to-github-need-some-help-adding/) good tutorial on using Git to clone source code from Github Github

B) Download TBB Under build open subfolder common and put Itel's tbb into it

C) Download Eigen and also put it under build/common

Make sure you put the entire "Eigen" directory under common. It should include at least "eigen" and "unsupported"

D) Download CMake

E) Define as system variable OPENCV64_DIR = d:/opencv/build/

How to check if you entered the path correctly? AFTER entering path and ONLY AFTER entering and applying all your changes open a DOS cmd window. 
Type %OPENCV64_DIR% at the command line
If you get the following message:

'd:/opencv/build/' is not recognized as an internal or external command, operable program or batch file.

You have entered the path correctly and now it is a system variable

F) Add to Path, the following: 1) C:\Program Files (x86)\CMake 2.8\bin; 2) %OPENCV64_DIR%bin\Debug\; 3) %OPENCV64_DIR%bin\Release\; 4) %OPENCV64_DIR%common\tbb\bin\intel64\vc12\;

Note: Use V12 for Visual studio 2013. If you are using an earlier version for example Visual Studio 2010 instead of vc12 use vc10.
How to know which number is the right one for you? Take a look at project configuration properties->General->Platform Toolset

How to check if you entered the Paths correctly?
Type Path at the command line. You should see the Paths you just added in the list

G) Open Cmake gui

Enter the following at:
Where is the Source code: d:/opencv/sources
Where to build the binaries: d:/opencv/build

H) Configure Cmake

Click on configure and you will be asked to specify the compiler. You can use Native compilers but expect no guarantees of success. Rather specify the compiler. The recommend option for x64 architecture regardless of whether you have Intel or AMD microprocessor is to use AMD64. Yes this is confusing but AMD64 is only called that since AMD made a x64 processor first.

-Define native compiler as: c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\cl.exe
-Check the “BUILD_EXAMPLES” option (in the "BUILD" group). 
-Check the “WITH_TBB” option (in the "WITH" group). 
-Set EIGEN_INCLUDE_PATH as "d:/opencv/build/common/eigen" (eigen must include a) Eigen b) unsupported)
-Mark in WITH -WITH_EIGEN and -WITH_TBB
-In TBB group set
    -TBB_INCLUDE_DIRS : D:/opencv/build/common/tbb/include/
    -TBB_LIB_DIR : D:/opencv/build/common/tbb/lib/intel64/vc12
-ENABLE->ENABLE_AVX This is optional. Try it at your own risk. I have not tested it yet

Note that sometimes you will have to configure incrementally. Meaning that not all of the options will be available on first try. They might show up marked in red and then you have to pay attention to them. Keep on going until you no longer have red lines in the CMake GUI.

Click on generate after a successful configure. Pay attention to errors and warnings you get from configure

Note: Once you define the compiler is his impossible to to make changes. UNLESS you delete the ENTIRE build directory. This is the only option that worked for me.

This link inspired this guide and has useful illustrations. Though some of the details are incorrect so beware.

I also recommend reading the following Installation Guide on how to use Cmake for Visual studio by @StevenPuttemans