Share via


Downloading and Installing OpenCV

Kinect for Windows 1.7, 1.8

Open Source Computer Vision (OpenCV) is a library of programming functions for real-time computer vision. This overview explains how to download and install the OpenCV library in preparation for using the Kinect for Windows SDK KinectBridgeWithOpenCVBasics D2D C++ Sample.

The OpenCV download includes:

  • A setup guide for help with installation
  • An OpenCV sample program called KinectViewer that displays skeletal tracking using the depth stream.
  • A C++ class called OpenCVKinectHelper that contains helper functions.

Prerequisites

  • You must have Visual Studio 2010 or Visual Studio 2012 installed. Express, Professional, Premium, or Ultimate versions can be used.
  • You must install Kinect for Windows SDK, which is a free download.

Step 1: Installation

  1. Download the OpenCV library for Windows.
  2. Run the executable.
  3. Extract its contents to a location, such as c:\dir1. For example, C:\OpenCV2.4.x.

Step 2: Set the system environment variables

There are two ways to set the system environment variables: using the provided environment variable script or setting the environment variables manually.

Automatic Method

A script called KinectBridgeWithOpenCVBasics-D2DEnvironmentSetup.bat is provided. This script will set the appropriate system environment variables, with the exception of the PATH variable, for you.

The script can be run as follows:

KinectBridgeWithOpenCVBasics-D2DEnvironmentSetup.bat [OpenCV_Version [ OpenCV_Directory] ]

There are two parameters listed:

  • OpenCV_Version is used to specify the version of OpenCV that is installed on the machine. The periods for the version number passed in should be removed. E.g. version number 2.4.3 should be passed in as 243. This is an optional parameter.
  • OpenCV_Directory is used to specify the location of the OpenCV library. This is an optional parameter, but if it is used, the OpenCV_Version parameter must also be given.

If the location of the OpenCV library is not passed in, the script will attempt to automatically detect the OpenCV library. If it cannot detect it, the script will prompt the user for the location of the library. If the user does not pass in the OpenCV_Version parameter, the script will prompt the user for the version of OpenCV to use.

Manual Method

  1. Open the Start Menu. Right-click Computer, then select Properties. Click Advanced system settings and then click Environment Variables.
  2. Create a new system variable. For Variable name, enter OPENCV_DIR. For Variable value, enter C:\OpenCV (or another folder in which OpenCV content was extracted to).
  3. Create another new system variable. For Variable name, enter OPENCV_VER. For Variable value, enter the version number of your installation of OpenCV, removing any periods. For example, for version 2.4.3, enter 243.
  4. This step is optional. The KinectBridgeWithOpenCVBasics-D2D Visual Studio project is set up to modify the path automatically when the sample is run from within Visual Studio. If you want to run this sample outside of Visual Studio, then this step is necessary.
  5. Find and double-click the Path system variable. In the Variable value field of the dialog box, add one of the following:
    • 64-bit path: %OPENCV_DIR%\build\x64\vc10\bin;%OPENCV_DIR%\build\common\tbb\intel64\vc10
    • 32-bit path: %OPENCV_DIR%\build\x86\vc10\bin;%OPENCV_DIR%\build\common\tbb\ia32\vc10 If you ever change your installation directory or download a new version of OpenCV, change the environment variables to the correct new values.

Note that modifications to the environment variables do not result in immediate change. For example, if you start another Command Prompt after making the changes, the environment variables will reflect the previous (not the current) values. You must restart Visual Studio once you make modifications to the environment variables. The changes do not take effect until you log off and then log back on.