This tutorial guides you through the process of installing OpenCV 2.3.1 in windows using Visual Studio 10. OpenCV changes its installation process from version to version and sometimes make it too confusing to work properly. In this tutorial I’ll try to mention as much details as possible in the installation process of OpenCV.
Preparation Step: Install Visual Studio 10.
Stage One: Installing OpenCV
- Download OpenCV 2.3.1 Superpack from the following link: http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.3.1/.
- Run the exe file and extract the contents in C:OpenCV231. If the contents (i.e. the folders named 3rdparty, android etc) are copied in a folder named “opencv” inside C:OpenCV231 then copy all of them to C:OpenCV231. (I’ll describe all the later steps assuming that the files has been extracted here. If not, please modify the instruction accordingly.)
- Download and install cmake from http://www.cmake.org/
- Run the Graphical User Interface of Cmake (cmake-gui).
- In the field named “Where is the source code:” white c:opencv231. In the field named “Where to build the binaries” specify C:OpenCV231msvc. Now click “configure”.
- A dialog box will appear (Figure 1) asking you to specify the generator for the project. Select Visual Studio 10 from the dropdown list. Select “Use default native compiler”. Now click “Finish”. It may ask for your permission to create a new folder named msvc. Just allow to do it. It
- Now the cmake window will look something like Figure 2. In this dialog, check the box named “install_c_examples”. Click the “Generate” button. This will make Visual Studio solutions in the C:OpenCV231msvc folder.
- Open OpenCV.sln. Select “Debug” in the solution configuration listbox. Now press F7 to build the solution. If all the projects are successfully built (3 projects may be skipped, don’t worry about that) it will show such message. Now do the same by selecting “release” in the solution configuration listbox.
- Copy the “lib” and “bin” folders from C:OpenCV231msvc to C:OpenCV231. Also copy the contents of “include” folder from C:OpenCV231build to C:OpenCV231include
- Now we need to add the following 2 folders in environment variables:
To do this, go to Control Panel > System > Advanced System Settings > Environment Variables and append these two folders into the “path” variable. Remember to separate the entries by semicolon. Click ok.
- Create a new Win32 console application.
- In solution explorer, right click on the project and click properties. Go to VC++ Directories. in Include Directories, add the following 2 folders:
- Add the following folder in Library Directories while you are in Debug configuration:
Add the following while in Release configuration:
- Go to Linker > Input. Add the following in the “Additional Dependencies” field while in debug configuration:
Add the following while in release configuration:
- In earlier versions, OpenCV used to be included by the following line:
From OpenCV 2.2, it is included by either the following:
Or, by individually including each module located in different folders inside C:OpenCV231libDebug
I have found the following backward compatibility issue while moving from opencv 2.1 to 2.3.1
If M be a cv::Mat then if you have a command M.inv(CV_SVD_SYM) then you have to change it to M.inv(cv::DECOMP_SVD)
Update: OpenCV 2.4.0 is released. It has very similar installation process except the lib filenames. Release filenames:
And Debug Filenames