Search This Blog

Tuesday, September 25, 2012

Installing OpenCV 2.3.1 on Windows 7

(To install OpenCV on Ubuntu refer to this post).
Installing OpenCV can be tricky on Windows. If you are using 32 bit version of Windows then you are in luck. You will find 32-bit executables ready for deployment. But if you happen to use a 64 bit version of Windows you will need to build the binaries yourself.
Note: This guide does not cover installing third party libraries. (Refer to this post to install OpenCV on windows with Intel TBB support)

You will need the following softwares:
  1. Microsoft Visual Studio 10(available for free download here)
  2. Cmake 2.8.10.2 (available for free download here)
  3. OpenCV 2.3.1 (available for free download here
Now follow the following steps to install OpenCV:
Step 1: Prerequisites
  • Install Microsoft Visual Studio 10.
  • 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.
  • 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.
  • 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
  • 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
  • Add the following under LIBRARY directories:
    • C:\opencv\build\lib\Debug
  • 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

    • These were just the most commonly used library files. You will need to include more library files as and when you require. You can find all the library files 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