Sunday, September 25, 2011

OpenCV 2.3.1 and Microsoft Visual C++ 2010 Express

OpenCV is an open source Computer Vision software package. It includes some stereo calibration and matching functionality, and is therefore of great interest to anyone doing 3D.

I am gonna go through all the steps needed to install the 32 bit debug version of OpenCV 2.3.1 using the pre-compiled libraries and have it running on a Windows 7 64 bit machine with Microsoft Visual C++ 2010 Express under the hood.

Get the OpenCV 2.3.1 Windows Superpack and install it. I am gonna assume it's installed in C:\Program Files\opencv.

You're also gonna need the so-called TBB debug libraries because they are not included in OpenCV 2.3.1 (if you have already installed and setup OpenCV 2.3.1 and you're getting an error message about tbb_debug.dll missing when you start debugging your code, that's your problem). Get the windows TBB binaries and place the tbb30_20110427oss directory under C:\Program Files\opencv\build\common (for example). At some point in the future, OpenCV may come with the debug TBB and all the TBB stuff added here may not be needed anymore.

After having created a new Visual C++ 2010 project (make sure it's a Win32 Console Application), right-click on the name of the project and go into Properties.

Click on Configuration Properties->VC++ Directories, and edit the Include Directories. Add:
C:\Program Files\opencv\build\common\tbb30_20110427oss\include
C:\Program Files\opencv\build\include\opencv2
C:\Program Files\opencv\build\include\opencv
C:\Program Files\opencv\build\include

Click on Configuration Properties->VC++ Directories, and edit the Library Directories. Add:
C:\Program Files\opencv\build\common\tbb30_20110427oss\lib\ia32\vc10
C:\Program Files\opencv\build\x86\vc10\lib

Click on Configuration Properties->Linker->Input, and edit the Additional Dependencies. Add:
opencv_calib3d231d.lib
opencv_contrib231d.lib
opencv_core231d.lib
opencv_features2d231d.lib
opencv_flann231d.lib
opencv_gpu231d.lib
opencv_haartraining_engined.lib
opencv_highgui231d.lib
opencv_imgproc231d.lib
opencv_legacy231d.lib
opencv_ml231d.lib
opencv_objdetect231d.lib
opencv_ts231d.lib
opencv_video231d.lib
tbb_debug.lib
Here, I have put all the OpenCV libraries but you certainly don't need to do that, as you can just add the ones you need for your application.

At this point, you should be able to link your code. The only remaining issue is to let the computer know where the dll libraries are by adding the proper paths to the PATH environment variable.

Click on Configuration Properties->Debugging, and edit the Environment.
Type PATH=C:\Program Files\opencv\build\x86\vc10\bin;C:\Program Files\opencv\build\common\tbb30_20110427oss\bin\ia32\vc10 in the window.

You may also change the PATH outside of Visual Studio by going into the Control Panel->System and Security->System->Advanced System Settings->Environment Variables, and changing the PATH there.

Note about Visual C++ 2008 users: vc10 refers to Visual C++ 2010, vc9 refers to Visual C++ 2008. OpenCV 2.3.1 provides both builds.

Note about building a 64 bit project: Microsoft Visual C++ 2010 Express doesn't come with 64 bit support out of the box. You need to install Windows SDK (Software Development Kit) to have 64 bit support. After you have made Windows SDK the default in Properties->General->Platform Toolset, you should be able to go into the Configuration Manager and switch the project over to 64 bit. I haven't tried but there's no reason you shouldn't be able to link against the 64 bit OpenCV 2.3.1 libraries if you want to.

7 comments:

  1. it is very useful thanks a lot

    ReplyDelete
  2. Thank you very much.
    It helped me out.

    ReplyDelete
  3. can you tell me more about how to run opencv files , because I just started to learn opencv.

    ReplyDelete
  4. at the end I installed the open cv and I run some external programs , but when I run the sample of open cv, for example canny edge detector it gave the below errors:




    'open_cv_haval.exe': Loaded 'C:\Program Files\opencv\open_cv_haval\Debug\open_cv_haval.exe', Symbols loaded.
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Program Files\opencv\build\x86\vc10\bin\opencv_core231d.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
    'open_cv_haval.exe': Loaded 'C:\Program Files\opencv\build\x86\vc10\bin\opencv_highgui231d.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7600.16385_none_ebf82fc36c758ad5\comctl32.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\avifil32.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\msacm32.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\msvfw32.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\avicap32.dll', Cannot find or open the PDB file
    'open_cv_haval.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file


    .
    .
    .
    .
    ..
    can you help me to solve these errors

    ReplyDelete
  5. I haven't tried to run external programs so i really don't know.

    ReplyDelete
  6. i think you are getting those because the executable was built in debug mode. so you're getting warnings about debug info files but the program should be able to run anyways. i think.

    ReplyDelete