OpenCV 2.3.1 and Visual Studio 2010Nov 24
Setting up OpenCV and making the necessary changes for projects in Visual Studio environment are always a bit tricky and painful. But, with OpenCV 2.3.1, it becomes an unbelievable trouble. First in first, directory structure of OpenCV was changed, so everything becomes different. Second, there is a new tbb.dll and tbb_debug.dll problems which can drive a person crazy.
Let’s begin to setup: I’m working on a x86 Windows environment and using Visual Studio 2010, so my assumption is we are all in the same page. However, person using other platforms can use these guide in an analogous manner.
First, we should download OpenCV 2.3.1, there is a win-superpack at . After downloading, double-click it and it extracts itself in a directory called opencv. I cut and paste it to my C:\ root directory and also renamed it as OpenCV2.3.1. So, I’m going to set paths accordingly, I recommend you to do the same. After doing that, we should set path in Windows environment variables to OpenCV’s bin directory. Therefore, go to Control Panel – System and Security – System – Advanced System Settings – Environment Variables and find Path in System Variables section, then add “C:\OpenCV2.3.1\build\x86\vc10\bin” without quotation marks.
We are ready to create a trial project. Go to Visual Studio and create a new Windows Console Application project without precompiled header. Then, delete all the files and headers. Go to My Computer and open “C:\OpenCV2.3.1\samples\c” and copy facedetect.cpp to your new project directory. Then, click your project on Solution Explorer and right click Source Files, click Add and Existing File and choose facedetect.cpp. So, we only have one file in our project and let’s open it. You can see that there are lots of red underlines on includes and functions. It’s because, Visual Studio can’t find the locations of these files and functions. Let’s give them to it. Go to Project menu click Project Properties(Alt + F7). Here, we should select All Configurations from Configuration combo box, because we don’t want to set different things for Debug and Build except the lib files. Then select C/C++ – General – Additional Include Directories and add “C:\OpenCV2.3.1\build\include” without quotation marks. Now, we are going to Linker section, choose Linker – General – Additional Library Directories and add “C:\OpenCV2.3.1\build\x86\vc10\lib”. After that, select Linker – Input – Additional Dependencies and add necessary lib file names there.
Libs in OpenCV 2.3.1 :
These are the release versions of lib files, if you add “d” suffix to the filename it becomes the debug version, e.g. opencv_core231.lib – release version, opencv_core231d.lib – debug version. We have just chosen All Configurations, so after adding necessary lib files, we should change the configuration to debug and add “d” suffix to the lib files. Here, for facedetect.cpp project, we should add core, highgui, imgproc and objdetect libs. That’s all, now Visual Studio knows where our lib files and functions are. So, we are ready to build our solution. We can successfully build it, but we can’t start debugging. Because we have a problem in hand “tbb_debug.dll is missing from your computer” :
Let’s talk about tbb – Intel’s Threading Building Blocks. There are a tbb.dll for release versions which OpenCV package includes, and a tbb_debug.dll for debug versions which surprisingly OpenCV package does not include. So, we should deal with this problem starting with downloading tbb for Windows from . After downloading and unzipping it, change the directory name from something like “tbb30_20110427oss” to “tbb”. Then go to My Computer and “C:\OpenCV2.3.1\build\common”. There is another tbb directory, rename it as “tbb_old” for backup. Then copy newly downloaded and renamed tbb directory to this “C:\OpenCV2.3.1\build\common” location. Now, we have tbb.dll, tbb_debug.dll and any other necessary tools for tbb. We should add new tbb location’s bin directory to path in environment variables. So, go to Control Panel – System and Security – System – Advanced System Settings – Environment Variables and find Path in System Variables section, then add “C:\OpenCV2.3.1\build\common\tbb\bin\ia32\vc10” without quotation marks. Now, we should restart the Visual Studio to get updated System Variables. At last, our cruel journey of setup may come to an end and your application may be built up in all configurations and run for both debug and release. But, it may not and you may have a problem like below when in release version “Entry Point Not Found – The procedure entry point bla bla bla could not be located in the dynamic link library tbb.dll”:
If you have another program, like another Intel Compiler or Intel ArBB or any version of Matlab using another version of tbb.dll, this problem may arise. But, don’t panic, it is an easy problem to fix. Let’s try to see which program blocks our tbb.dll. Run your program in release mode and get the error. When you get it in screen do not close it, go to Output box where all loaded DLL’s and stuff are written and find where tbb.dll are loaded from. After finding it, go to Control Panel – System and Security – System – Advanced System Settings – Environment Variables – System Variables – Path again and make sure that our new tbb.dll location, i.e. “C:\OpenCV2.3.1\build\common\tbb\bin\ia32\vc10” should come up before the blocking application’s location. For example, if Matlab is the blocker for our application, meaning that it also has another version tbb.dll. System variables section loads its path first and when Visual Studio wants a tbb.dll from system, system gives it from Matlab’s directory. Therefore, OpenCV’s tbb.dll has to come up before the blocker application’s tbb.dll in the Path section of System Variables.
That’s all you have to do to setup new OpenCV 2.3.1 on Visual Studio 2010. I want to explain it as simple as possible, I hope it is crystal clear to understand. I wish you luck with your projects!