Search This Blog

Sunday, September 30, 2012

Installing OpenCV 2.3.1 with TBB enabled in Windows

opencv logo
(To install OpenCV on Ubuntu refer to this post).
In the last post, I explained how to install OpenCV without any third party libraries. In this one I will explain how to install OpenCV with Intel TBB. For those of you who don't know about TBB, it stands for Threaded Building Blocks. It is a library which greatly simplies creating threaded applications on Intel platform.  Without TBB installed your OpenCV algorithms run only on single core. When OpenCV is installed with TBB, the library automatically uses threading to utilize all the cores available to your processor and hence you get a significant improvement in the speed.
Although the steps have been tested for OpenCV version 2.3.1 and 2.4.2, they should work fine for the versions in between.
You will need the following softwares:
  1. Microsoft Visual Studio 10(available for free download here)
  2. Cmake 2.8.9 (available for free download here)
  3. OpenCV 2.3.1 (available for free download here
  4. TBB v4.1 (available for free download here)
Now go through the following steps:
Step 1: Prerequisites
  • Install Microsoft Visual Studio 10.
  • Download TBB library.
  • Extract tbb41_20120718oss_win.zip to any convenient location. I will assume it to be "C:\" throughout this tutorial.
  • Install Cmake.
  • Extract the OpenCV 2.3.1 zip file to somewhere convenient location. I will use “C:\” path.
Step 2: Build OpenCV library
  • Start Cmake 2.8.2 GUI.
  • Type “C:\opencv” under “Where is the source code” text box.
  • Type “C:\opencv\build” under “Where to build the binaries” text box.
  • Check the box WITH_TBB.
  • Click on “Configure”.
  • Select the compiler from the drop down list.
    • “Visual Studio 10″ if you want to target 32 bit platforms.
    • "Visual Studio 10 win64" if you want to target 64 bit platforms.
  • Click Finish.
  • You will get an error message that TBB_INCLUDE_DIR not found.
  • Set TBB_INCLUDE_DIR to 'C:\tbb41_20120718oss_win\include'.
  • Set TBB_LIB_DIR to 
    • C:\tbb41_20120718oss_win\lib\ia32\vc10 for 32 bit platforms
    • C:\tbb41_20120718oss_win\lib\intel64\vc10 for 64 bit platforms
  • Click on "Generate". (This may take several minutes...)
  • Open Microsoft Visual Studio. From FILE menu, select OPEN and then PROJECT/SOLUTION.
  • Navigate to “C:\opencv\build” and select “OpenCV.sln” to open.
  • Wait till all the files are found and Microsoft Visual Studio is ready.
  • Select BUILD SOLUTION from BUILD menu (This may take many minutes...).
Step 3: Set Environment Variables
  • Close all the softwares running.
  • Right click on My Computer and select Properties.
  • Click on “Advanced System Settings”.
  • Click on “Environment variables”.
  • Under “System variables” select “Path” and then click on Edit.
  • Add a semicolon (;) to the end of the present text and then add the following:
    • C:\opencv\build\bin\Debug
    • C:\opencv\build\x86\vc10\bin - if you opted for 32 bit platform
      C:\opencv\build\x64\vc10\bin - if you opted for 64 bit platform
    • C:\tbb41_20120718oss_win\bin\ia32\vc10 - if you opted for 32 bit platform
      C:\tbb41_20120718oss_win\bin\intel64\vc10 - if you opted for 64 bit platform
  • Click OK thrice.
  • Your OpenCV is now built and installed correctly according to your OS
  • Restart you PC.
Step 4: Configure Visual Studio for OpenCV
  • After restarting, open Microsoft Visual Studio and select “New Project”.
  • Select Win32 console application and give it a name.
  • Select PROPERTIES from PROJECT menu.
  • Under “Configuration properties” select “VC++ directories”.
  • Add the following directories under INCLUDE directories:
    • C:\opencv\build\include\opencv
    • C:\opencv\build\include\opencv2
    • C:\opencv\build\include
    • C:\tbb41_20120718oss_win\include
    • C:\tbb41_20120718oss_win\include\tbb
  • Add the following under LIBRARY directories:
    • C:\opencv\build\lib\Debug
    • C:\tbb41_20120718oss_win\lib\ia32\vc10 for 32 bit platforms
      C:\tbb41_20120718oss_win\lib\intel64\vc10 for 64 bit platforms
  • Select LINKER and then select INPUT and add the following under “Additional dependencies”:
    • opencv_core231d.lib
    • opencv_highgui231d.lib
    • opencv_video231d.lib
    • opencv_ml231d.lib
    • opencv_legacy231d.lib
    • opencv_imgproc231d.lib
    • tbb_debug.lib
    • tbb_preview_debug.lib
    • tbbmalloc_debug.lib
    • tbbmalloc_proxy_debug.lib
    • tbbproxy_debug.lib

    • Note: These were just the most common library files. You will need to add other library files as and when you require. You can easily find all of them in the folder "C:\opencv\build\lib\Debug".
    If you are using 64 bit libraries then you will have to configure Visual Studio to target 64-bit platforms. And you will need to do it for every project.

    To set up C++ applications to target 64-bit platforms:

    • Open the C++ project that you want to configure to target a 64-bit platform. 
    • Open the property pages for that project. 
    • Click Configuration Manager to open the Configuration Manager Dialog Box.
    • Click the Active Solution Platform list, and then select the <New…> option to open the New Solution Platform Dialog Box.
    • Click the Type or select the new platform drop-down arrow, and then select a 64-bit platform.
    • Click OK. The platform you selected in the preceding step will appear under Active Solution Platform in the Configuration Manager dialog box.
    • Click Close in the Configuration Manager dialog box, and then click OK in the <Projectname> Property Pages dialog box.

    No comments:

    Post a Comment