Getting the Kinect SDK to work with visual studio

2019-04-07 19:22发布

问题:

I've been following the guide microsoft have made for setting up the Kinect SDK with c++. The steps they have created are as follows.

  1. Include windows.h in your source code.
  2. To use the NUI API, include MSR_NuiApi.h. Location: Program Files\Microsoft Research KinectSDK\inc
  3. To use the Kinect Audio API, include MSRKinectAudio.h. Location: Program Files\Microsoft Research KinectSDK\inc
  4. Link to MSRKinectNUI.lib. Location: Program Files\Microsoft Research KinectSDK\lib
  5. Ensure that the beta SDK DLLs are on your path when you run your project. Location: \Program Files\Microsoft Research KinectSDK

I believe I've done everything apart from step 5. Could anyone give me more details on what this means and how to do this?

thanks in advance, John

回答1:

2.To use the NUI API, include MSR_NuiApi.h. Location: Program Files\Microsoft Research KinectSDK\inc

To do this, you probably want to add that path to your project

  • Right-click on your project, properties, VC++ directories
  • Add ;C:\Program Files\Microsoft Research KinectSDK\inc to the end of the include paths
  • Add ;C:\Program Files\Microsoft Research KinectSDK\lib to the end of the libraries paths

then add

#include <MSR_NuiApi.h>

to the includes at top of your source file. If you're using precompiled headers then you should put it below the stdafx.h include, or just add it to stdafx.h instead.

5.Ensure that the beta SDK DLLs are on your path when you run your project. Location: \Program Files\Microsoft Research KinectSDK

This means that your binary needs to be able to find these files at runtime.

The easiest way to do this is to add them to your system path; go to

  • start menu
  • right-click computer, properties
  • advanced system settings
  • environment variables
  • PATH, in your user or system settings - edit and append ; then the path given

You may then need to restart Visual Studio to pick this up, or it should be registered when you open a new command prompt.

Or, if you don't want to change the system settings, you can e.g. add it to an open command prompt with

PATH=%PATH%;C:\Program Files\Microsoft Research KinectSDK

or you can work out exactly which files there are necessary and copy them into the same directory as your binary, etc.



回答2:

To implement a C++ application

  1. Include windows.h in your source code first. (This is important--you can't have WIN32_LEAN_AND_MEAN defined anywhere in your project or else you won't be able to compile NuiApi.h)

  2. Include <NuiApi.h> in your source code.

  3. Make sure you have an environment variable set up for your OS that reflects the SDK file path. The SDK installation should automatically do this for you. Example:

     KINECTSDK10_DIR = "C:\Program Files\Microsoft SDKs\Kinect\v1.0\"
    
  4. Go to your Visual Studio project settings under VC++ directories. Add $(KINECTSDK10_DIR)\inc to the include directories.

  5. Under the same VC++ directories area, include $(KINECTSDK10_DIR)\lib\x86 (for 32-bit apps) or $(KINECTSDK10_DIR)\lib\amd64 (for 64-bit apps) in your libraries directory.



回答3:

We are using the Kinect SDK version 1.0 and this is how the project is configured. Please note that the developer machine is Windows 7 x86. If you are using x64, please change the path accordingly.

Step 1. Copy header files and library. There is a reason to do this: the project can be checked out to any machine and compile just fine (the machine doesn't have to install the SDK). Another benefit: we upgraded the SDK to version 1.0 but because our project hasn't been updated and the deadline is coming, we had to built it with SDK version beta and everything went smoothly.

I suggest you create a new directory in your solution called "3rdparty/KinectSDK" (change it to suit your need).

Copy C:\Program Files\Microsoft SDKs\Kinect\v1.0\inc

Copy C:\Program Files\Microsoft SDKs\Kinect\v1.0\lib (you will have both x86 and x64 libraries)

Step 2. Configure the project. You will need to do this for each project that uses Kinect SDK! All configuration is happened in the Project Properties dialog.

C/C++ > General > add "$(SolutionDir)\3rdparty\KinectSDK\inc" to your Additional Include Directories

Linker > General > add "$(SolutionDir)\3rdparty\KinectSDK\lib\x86" to your Additional Library Directories (if you are configuring for x64, use the amd64 directory)

Linker > Input > add "Kinect10.lib" to Additional Dependencies

Step 3. Compile time!

Note:

  • If you install the SDK correctly, your machine will be able to run / debug the program without further configuration.
  • In order to run the program in client machine, you will need to copy the Kinect10.dll file. It's best to build a deploy project, the DLL will be detected automatically for you.
  • Talking about client machine, you don't need to install SDK for it. Just grab the driver files (.inf and stuff) and install the driver manually when you plug in the Kinect.

Good luck.