It is assumed that the following softwares are installed. If the installation path is different, please read as appropriate.
When you use Visual Studio 2017 Professional/Community, "Desktop Development with C++" ->"Windows 8.1 SDK and UCRT SDK" option must be installed. |
Executable file path | C:\opencv\bin | <-- Add this path to the Path of the environment variable. |
Include file path | C:\opencv\include | |
Library path | C:\opencv\lib |
Include file path | $(KINECTSDK20_DIR)inc | |
Library path | $(KINECTSDK20_DIR)Lib\x64 |
The projects distributed in the following explanation is created by "Visual Studio Community 2017" and "OpenCV 3.3".
When you declare a variable of NtKinect class in your program, Kinect V2 will be initialized and become available.
#include "NtKinect.h" ... NtKinect kinect; // variable declaration
Various sensors of Kinect V2 are initialized when first used. For example, an RGB camera is initialized when the setRGB() function is called for the first time.
kinect.setRGB(); // Getting an RGB image. The first call initializeds the RGB camera.
Kinect V2 can acquire RGB camera image with resolution of 1920 x 1080. Since OpenCV uses BGR or BGRA format for color pixels, NtKinect also adopts the BGRA format.
The name here is "KinectV2". The solution name will automatically be "KinectV2". Click OK button.
Near the center of the menu bar at the top of the Visual Studio window, there is a panel for specifying compile options. Change this to "x64". Also, change "Debug" to "Release" so that execution becomes faster.
If at least one C++ source file does not exist in the project, "C/C++" item can not be selected in project properties. Therefore, first add "main.cpp" here.
$(KINECTSDK20_DIR)inc C:\opencv\include
$(KINECTSDK20_DIR)Lib/x64 C:\opencv\lib
Kinect20.lib opencv_world330.lib
[CAUTION] If you run the program in Debug mode, you must specify opencv_world330d.lib as a library file of OpenCV in Debug mode of the properties.
Please download "NtKinect.h" from the above link. The location of the file is the folder where the source file such as "main.cpp" is placed. In this example, it is "KinectV2/KinectV2/NtKinect.h".
If you get an error "Cannot include NtKinect.h" at compile time, delete the "NtKinect.h" once. Then, right click "Header file" of "Solution Explorer", and select "Add" "New item" "VisualC++ header file (.h)" from th menu and specify "NtKinect.h" for "Name". Please copy the contents of the downloaded file to the newly created one.
You can easily use various functions of Kinect V2 by rewriting the red letter part.
main.cpp |
|
The function whose name is preceded by "cv::" belongs to OpenCV.
type of return value | OpenCV function name | descriptions | manual |
void | imshow(cost string& winname, const Mat& image ) | display image in the window named winname. | link |
int | waitKey(int delay =0) | Wait key input for delay milliseconds. 0 means to wait infinitely. | link |
Since the above zip file may not include the latest "NtKinect.h", Download the latest version from here and replace old one with it.