OpenCV 2.3.1 and Visual Studio 2010

OpenCV 2.3.1 and Visual Studio 2010

Nov 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 [1]. 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 :

opencv_calib3d231.lib

opencv_contrib231.lib

opencv_core231.lib

opencv_features2d231.lib

opencv_flann231.lib

opencv_gpu231.lib

opencv_haartraining_engine.lib

opencv_highgui231.lib

opencv_imgproc231.lib

opencv_legacy231.lib

opencv_ml231.lib

opencv_objdetect231.lib

opencv_ts231.lib

opencv_video231.lib

 

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” :

tbb_debug

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 [2]. 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”:

tbb

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!   

 

[1] http://goo.gl/TM42y 

[2] http://goo.gl/1YRIx

33 comments

  1. TechBitar

    Thanks for the article. I have been trying to get openCV 2.3.1 to work with Visual Studio 2010 for a couple of days and no luck. There are so many variables and it’s been a frustrating experience. Will give this a shot.

  2. Raúl

    Very, very good!! I think that this article is of the bests that I read, and run ok.

    Sorry for my english.

    Thanks!!

  3. TechBitar

    I can build the solution with no errors but soon as I run debug, I get a list of files with error message of “Cannot find or open the PDB file” even though the paths are set to the files listed such as kernel32.dll and opencv_core231d.dll What am I doing wrong?

    • Ok, you have messages like “Cannot find or open the PDB file” for several dll’s mostly system ones on Output window, but it should not really affect how application works. Am I right? These are not error messages that block your application’s flow. I mean, your code should work just fine even after throwing these messages.

    • aozkano

      hay man ı have the same problem. Can you sold the problem…

    • You can find detailed information about PDB files from very nice article in John Robbins’ Blog found at http://goo.gl/ooFH6

  4. new2Cv

    I am getting the error that:
    “The program can’t start because tbb.dll is missing from my computer. Try re-installing the program to fix this problem.”

    ^ Is for debug compilation.
    For release, the include files are not opened though the path and all are same.
    Please help.

  5. Please read carefully the article above, all answers of your questions are mentioned in it in detail.

  6. Luke

    You are a god sent.

  7. Daniel

    when i do build->build solution it succeeds but when i go to do Debug->Start Debugging it says this application has failed to start because opencv_core231d.dll was not found. Re-installing the application may fix this problem.

    I don’t know how to fix this or what caused it. I double checked the steps and at this point I’ve done all you have said up until the tbb part i haven’t done that.

    • Daniel

      nevermind sorry i hadn’t closed VS2010 for the change of environment variables to take place. I am now at the tbb_debug.dll problem now.

  8. Daniel

    Ok so I did the tbb thing and now it runs the debug a command window pops up for a second then closes and this is the output i get. Is something wrong? I’ve never used VS2010 before or openCV but I need them for my senior design project next semester.

    ‘test.exe’: Loaded ‘C:\Documents and Settings\Danny\My Documents\Visual Studio 2010\Projects\test\Release\test.exe’, Symbols loaded.
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\ntdll.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\kernel32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\OpenCV2.3.1\build\x86\vc10\bin\opencv_core231.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\msvcp100.dll’, Symbols loaded.
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\msvcr100.dll’, Symbols loaded.
    ‘test.exe’: Loaded ‘C:\OpenCV2.3.1\build\x86\vc10\bin\opencv_highgui231.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\user32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\gdi32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\ole32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\advapi32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\rpcrt4.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\secur32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\msvcrt.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\oleaut32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\comctl32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\avifil32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\winmm.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\msacm32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\msvfw32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\shell32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\shlwapi.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\avicap32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\version.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\OpenCV2.3.1\build\x86\vc10\bin\opencv_imgproc231.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\OpenCV2.3.1\build\common\tbb\bin\ia32\vc10\tbb.dll’, Symbols loaded.
    ‘test.exe’: Loaded ‘C:\OpenCV2.3.1\build\x86\vc10\bin\opencv_objdetect231.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\OpenCV2.3.1\build\x86\vc10\bin\opencv_features2d231.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\OpenCV2.3.1\build\x86\vc10\bin\opencv_flann231.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\OpenCV2.3.1\build\x86\vc10\bin\opencv_calib3d231.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\imm32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\UmxSbxExw.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\UmxSbxw.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\psapi.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202\comctl32.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\uxtheme.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\Program Files\CA\CA Internet Security Suite\CA Anti-Spam\QSP-9.0.0.211\QOEHook.dll’, Cannot find or open the PDB file
    ‘test.exe’: Loaded ‘C:\WINDOWS\system32\msctf.dll’, Cannot find or open the PDB file
    The thread ‘Win32 Thread’ (0x36e0) has exited with code -1 (0xffffffff).
    The program ‘[10492] test.exe: Native’ has exited with code -1 (0xffffffff).

    • Daniel, I don’t know what your code is or does, so I can’t help you with your code, but it seems to me that your Visual Studio and OpenCV connection is OK and also you surpassed the tbb error. So, I think if you build the right code, there will be no problem. I recommend you to try to build any basic reference code from OpenCV, if you manage to build and debug it, you can fix your code. If there is an error at reference code, we should look at it.

      • Daniel

        my code was the facedetect.cpp you listed in the guide. i guess i can try to do a hello world type program.

        • OK, then probably you don’t give any input to compiled executable like any jpeg image having one or multiple faces. Go to Project-Properties-Configuration Properties- Debugging and enter jpeg image’s name to Command Arguments section like “lena.jpg”. You should copy the image file to Debug or Release folder depending on your configuration.

  9. brahma shankar

    thanx for this article…i was trying to communicate between visual studio and opencv for last 3 days…now after reading this article i m feeling good…ll give a try

  10. Thank you!
    Great article. I like it!

  11. Jehiel

    Hey I’ve done exactly what you said except for the tbb part. After adding the libraries and the debug, I could not build facedetect. The error they gave me was opencv_video231d.lib could not be opened. I’ve checked that I already added the library into the project properties. Any idea on how to solve this problem?

Leave a Reply