Stefan Karlsson/PersonalPage/OpenCV
OpenCV is the well known open source library with computer vision algorithms implemented for the use of every programmer. It is relatively easy to download and setup with MS visual studio 2010. However, none of the binaries downloadable to date supports multi-threading on multi-core processors out of the box. In order to get such support one need to make a custom build using "make" functionality through the program CMake. One gets the multi-threading support by incorporating the Intel TBB library. This library needs to be downloaded, and set up in the make utility.
This guide will tell you how to set this up on a windows 7, 64 bit, dell latitude E6400, using TBB version 4.1.
Contents
Youtube Guide
Many guides and discussions exist on the webb on installing OpenCV with extra functions, and the closest to our needs, is this one:
Howto install and setup OpenCV 2.1 with Visual studio 2010, 32 bit with TBB version < 4.1
I will explain how to modify that guide, so that it will work for 64 bit, OpenCV, TBB version 4.1.
Follow the instruction in the video, except download OpenCV 2.4.3 and TBB version 4.1. Do the following modifications for this to work.
Modifications to the Youtube Guide
- At 2.22 minutes into the video, the folder 'build' is created as the output directory for CMake. Call this directory instead 'MyBuild' (This is because the file structure of OpenCV 2.4.3 already has a folder with custom builds called 'Build').
- at 3.28 min, fix the the possible TBB "_WIN32_WINNT" issue. The _WIN32_WINNT Macro is used in the TBB header files to indicate what version of windows you have. This should be set by visual studio upon linking, but it seems its not working on my machine (You can try setting it with the /D switch, didnt work for me). Therefore, assuming that you have windows 7 on your machine, change the tbb header file "..\machine\windows_api.h" lines 46 to lines 74, put in remarks or delete
"..\internal\_tbb_windef.h" lines 35 TO 37, put in remarks or delete
- at 5.15. the property sheet is called "Microsoft.Cpp.x64.user", but otherwise follow instructions to the letter
- at 5.46 minutes, you are done with this video. Make sure you build your solution for both Release and Debug versions. Now shut youtube down, and follow these instructions:
Folder structure and includes/libs
- In the folder "MyBuild/bin", you should now have both dll files for debug and release (debug versions end with *d.dll). Make a new folder somewhere, called "openCV_lib_files", and make two subfolders called "Debug" and "Release". Put all your dll files from "MyBuild/bin/Debug" into the new Debug folder, and do the same procedure with the release version. after this, you should have duplicate files in "openCV_lib_files/Debug", and "openCV_lib_files/Release", except the Debug versions have an extra "d" at the end of their file names.
- In the folder "MyBuild/lib" you have lots of release and debug versions of lib files. Put all the debug versions (all files ending with *d.lib) into the folder "openCV_lib_files/Debug". Put all the corresponding release versions (those lacking the "d" at the end of their names) into "openCV_lib_files/Release". We now hav lib files mixed with dll files in the folders "openCV_lib_files/Debug" and "openCV_lib_files/Release".
- In the folder of your original downloaded opencv files (the source folder for your CMake), there is a folder of precompiled binaries. In this folder, you will find the "include" folder you need to copy to "openCV_lib_files/". BEWARE, there is more than one include folder in here. The folder you want to copy, has to subfolders, "opencv" and "opencv2" where the opencv2 subfolder has 19 different subfolders. Once you have the right "include" folder, copy it to "openCV_lib_files/". After that "openCV_lib_files/" has 3 folders, "Debug", "Release" and "include".
- Now change the system path to include "openCV_lib_files/Release" and "openCV_lib_files/Debug". This means that the dll files will be reacheable from any program running anywhere on your computer.
First 64 bit OpenCV application
- Close down the OpenCV solution in visual studio, start up a new project somewhere. Call it something intuitive, like myFirstOpenCV_app. Make it an empty win32 console application.
- Change the solution platform to x64 from win32. If x64 is not an option in the pull down menu, then select the option "configuration manager" instead. In the dialog that appears, in "Active Solution Platform" select "new", then choose x64.
- In the "property manager", you should now see 4 folder icons associated with the new project. 2 debug configurations, and 2 release configurations (for 32 bit and 64 bit resp.). Right click the 64 bit debug version, "add new project property sheet". Call it "OPENCV_DEBUG_SHEET"
- Edit the new debug sheet, "C/C++"->"Additional Include Directories" should have the full path to "openCV_lib_files\include"
- Edit the new debug sheet, "Linker"->"General"->"Additional Library Directories" should have the full path to "openCV_lib_files\Debug"
- Edit the new debug sheet, "Linker"->"General"->"Additional Dependencies" should have:
opencv_core243d.lib opencv_imgproc243d.lib opencv_highgui243d.lib opencv_ml243d.lib opencv_video243d.lib opencv_features2d243d.lib opencv_calib3d243d.lib
- Now make a "OPENCV_RELEASE_SHEET", in just the same way as the debug sheet, but add it to the 64 bit release configuration instead of the 64 bit debug configuration.
The "Additional Library Directories" should have the full path to "openCV_lib_files\Release", and "Additional Dependencies" should be the same lib files as above, EXCEPT remove the last d in each name:
opencv_core243.lib opencv_imgproc243.lib opencv_highgui243.lib opencv_ml243.lib opencv_video243.lib opencv_features2d243.lib opencv_calib3d243.lib
- Now add a c++ file to your project, and let it have the contents found here.
- Try compiling it for both release and debug configurations. Odds are, only the release version will work. Next is how I solved this:
- In "openCV_lib_files\Debug", swithc all the dlls and lib files for the equivalent ones from the 64 bit, prebuilt binaries that came with your original download (in the "build" folder at "build\x64\vc10"). These do not have TBB support. When developing in debug mode, you will therefore get slower programs. When you switch to release, you get the multithreaded versions of opencv functions. If you wish to debug TBB code you make yourself for your project, this is not a solution of course.