diff --git a/Kinect2Sample-master/.github/FUNDING.yml b/Kinect2Sample-master/.github/FUNDING.yml
new file mode 100644
index 0000000..fe6c3b5
--- /dev/null
+++ b/Kinect2Sample-master/.github/FUNDING.yml
@@ -0,0 +1,3 @@
+# These are supported funding model platforms
+
+github: [UnaNancyOwen] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
diff --git a/Kinect2Sample-master/HOWTOBUILD.md b/Kinect2Sample-master/HOWTOBUILD.md
new file mode 100644
index 0000000..2833a60
--- /dev/null
+++ b/Kinect2Sample-master/HOWTOBUILD.md
@@ -0,0 +1,74 @@
+How to Build Sample Program
+===================
+
+How to Install Tools and Libraries
+--------------------------------------
+* Visual Studio 2015
+ In Visual Studio 2015, Visual C++ is not installed by default. When installing, be sure to choose Custom installation and then choose the C++ components you require.
+ Or, if Visual Studio is already installed, choose [File]>[New]>[Project]>[C++] and you will be prompted to install the necessary components.
+
+* Kinect for Windows SDK v2.0
+ Please download installer, and install follow the instructions of installer.
+
+* OpenCV 3.1.0
+ Please download pre-built package, and unzip the self-extracting file.
+ Then, Please placed OpenCV folder in any directory. ( e.g. C:\Program Files\opencv
)
+
+* CMake 3.6.1
+ Please download installer, and install follow the instructions of installer.
+
+* Speech Platform SDK 11 ( and Kinect for Windows SDK v2.0 Language Packs (en-US) )
+ Please download installer for target platform, and install follow the instructions of installer.
+
+How to Generate Project of Samples using CMake
+--------------------------------------------------------
+1. Run CMake GUI
+
+2. Fill These Fields
+ * **Where is the source code**
+ This area is directory containing CMakeLists.txt file.
+ If you want to build all samples, please fill path of sample directory. ( e.g. C:/Kinect2Sample/sample
)
+ If you want to build any one sample, please fill path of any one directory. ( e.g. C:/Kinect2Sample/sample/Color
)
+
+ * **Where to build the binaries**
+ This area is directory Visual Studio project files will be generated.
+ By convention, Fill the path that added the \/build
to above path. ( e.g. C:/Kinect2Sample/sample/build
)
+
+3. Click Configure Button
+ You will be prompted for compiler and target platform.
+ Please specify compiler and target platform to use. ( e.g. Visual Studio 14 2015 Win64
)
+ Then, click finish button.
+
+4. Fill Configuration Fields
+ It will be entered almost automatically.
+ Please check configuration settings.
+ Then, click configure button.
+ * **KINECTSDK\_DIR** ... The directory path of Kinect for Windows SDK v2.0 ( e.g. C:/Program Files/Microsoft SDKs/Kinect/v2.0_1409
)
+ * **OPENCV\_DIR** ... The directory path that to search CMake configuration file for OpenCV. ( e.g. C:/Program Files/opencv/build
)
+
+5. Click Generate Button
+ If there is no errors, the Visual Studio project files will be generated into the "Where to build the binaries" directory.
+
+6. Set Environment Variable
+ You might need to add OpenCV binary directory path to environment variable "PATH" to be able to run applications. (e.g. C:\Program Filesopencv\build\x64\vc14\bin
)
+ The path that have to be added to environment variable will be displayed in output area of CMake GUI.
+ This path is depend on Compiler, Target Platform and OpenCV Directory.
+
+How to Build and Start Samples
+------------------------------------
+1. Open Visual Studio Solution File ( e.g. ..\build\Sample.sln
)
+
+2. Set Solution Configurations
+ Select Release from the Solution Configuration drop-down list, which is on the Standard toolbar. ( e.g. Release
)
+ Release build will be enabled optimization by compiler.
+
+3. Build Solution ( or Project )
+ On the Build menu, Click "Build Solution".
+ Or, In Solution Explorer, select the desired build target project within your solution. Then Click "Build Project".
+
+4. Set Startup Project
+ In Solution Explorer, select the desired startup project within your solution.
+ On the Project menu, choose "Set as StartUp Project".
+
+5. Start Without Debugging
+ On the Debug menu, choose "Start Without Debugging".
diff --git a/Kinect2Sample-master/LICENSE b/Kinect2Sample-master/LICENSE
new file mode 100644
index 0000000..484e9b4
--- /dev/null
+++ b/Kinect2Sample-master/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 Tsukasa Sugiura
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/Kinect2Sample-master/README.md b/Kinect2Sample-master/README.md
new file mode 100644
index 0000000..00ddfc3
--- /dev/null
+++ b/Kinect2Sample-master/README.md
@@ -0,0 +1,38 @@
+
+Kinect for Windows SDK v2 Sample Program
+============================
+
+This repository is Sample Program of Kinect for Windows SDK v2 written in Native C++.
+
+Environment
+--------------
+* Visual Studio Community 2015 *1
+* Kinect for Windows SDK v2.0
+* Kinect for Windows SDK v2.0 Language Packs (en-US)
+* Speech Platform SDK 11
+* OpenCV 3.1.0 *2
+* CMake 3.6.1 *3
+
+*1 This sample program need Visual Studio Community (or upper version), because depends on ATL.
+*2 Pre-built OpenCV that is distributed by official team does not include library for Win32 (x86) target platform. If you want to build sample program for Win32 (x86) target platform, You need build OpenCV yourself. Similarly, If it does not include library for your target compiler, You need build OpenCV yourself.
+*3 You need generate project of this sample program using CMake. Please read [this document](HOWTOBUILD.md) about how to generate project using CMake.
+
+License
+---------
+Copyright © 2016 Tsukasa SUGIURA
+Distributed under the [MIT License](http://www.opensource.org/licenses/mit-license.php "MIT License | Open Source Initiative").
+
+Contact
+---------
+* Tsukasa Sugiura
+ *
+ *
+ *
+
+Reference
+------------
+* KINECT for Windows SDK programming - Kinect for Windows v2 sensor supported version | Shuwa System Co.,Ltd.
+
+
+* Kinect for Windows SDK 2.0 | MSDN Library
+
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/AudioBeam/CMakeLists.txt b/Kinect2Sample-master/sample/AudioBeam/CMakeLists.txt
new file mode 100644
index 0000000..5cb94b7
--- /dev/null
+++ b/Kinect2Sample-master/sample/AudioBeam/CMakeLists.txt
@@ -0,0 +1,23 @@
+cmake_minimum_required( VERSION 3.6 )
+
+# Create Project
+project( Sample )
+add_executable( AudioBeam app.h app.cpp main.cpp util.h )
+
+# Set StartUp Project
+set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "AudioBeam" )
+
+# Find Package
+set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} )
+find_package( KinectSDK2 REQUIRED )
+
+if( KinectSDK2_FOUND )
+ # Additional Include Directories
+ include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+
+ # Additional Library Directories
+ link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+
+ # Additional Dependencies
+ target_link_libraries( AudioBeam ${KinectSDK2_LIBRARIES} )
+endif()
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/AudioBeam/FindKinectSDK2.cmake b/Kinect2Sample-master/sample/AudioBeam/FindKinectSDK2.cmake
new file mode 100644
index 0000000..00a2036
--- /dev/null
+++ b/Kinect2Sample-master/sample/AudioBeam/FindKinectSDK2.cmake
@@ -0,0 +1,182 @@
+#.rst:
+# FindKinectSDK2
+# --------------
+#
+# Find Kinect for Windows SDK v2 (Kinect SDK v2) include dirs, library dirs, libraries and post-build commands
+#
+# Use this module by invoking find_package with the form::
+#
+# find_package( KinectSDK2 [REQUIRED] )
+#
+# Results for users are reported in following variables::
+#
+# KinectSDK2_FOUND - Return "TRUE" when Kinect SDK v2 found. Otherwise, Return "FALSE".
+# KinectSDK2_INCLUDE_DIRS - Kinect SDK v2 include directories. (${KinectSDK2_DIR}/inc)
+# KinectSDK2_LIBRARY_DIRS - Kinect SDK v2 library directories. (${KinectSDK2_DIR}/Lib/x86 or ${KinectSDK2_DIR}/Lib/x64)
+# KinectSDK2_LIBRARIES - Kinect SDK v2 library files. (${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib (If check the box of any application festures, corresponding library will be added.))
+# KinectSDK2_COMMANDS - Copy commands of redist files for application functions of Kinect SDK v2. (If uncheck the box of all application features, this variable has defined empty command.)
+#
+# This module reads hints about search locations from following environment variables::
+#
+# KINECTSDK20_DIR - Kinect SDK v2 root directory. (This environment variable has been set by installer of Kinect SDK v2.)
+#
+# CMake entries::
+#
+# KinectSDK2_DIR - Kinect SDK v2 root directory. (Default $ENV{KINECTSDK20_DIR})
+# KinectSDK2_FACE - Check the box when using Face or HDFace features. (Default uncheck)
+# KinectSDK2_FUSION - Check the box when using Fusion features. (Default uncheck)
+# KinectSDK2_VGB - Check the box when using Visual Gesture Builder features. (Default uncheck)
+#
+# Example to find Kinect SDK v2::
+#
+# cmake_minimum_required( VERSION 2.8 )
+#
+# project( project )
+# add_executable( project main.cpp )
+#
+# # Find package using this module.
+# find_package( KinectSDK2 REQUIRED )
+#
+# if(KinectSDK2_FOUND)
+# # [C/C++]>[General]>[Additional Include Directories]
+# include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+#
+# # [Linker]>[General]>[Additional Library Directories]
+# link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+#
+# # [Linker]>[Input]>[Additional Dependencies]
+# target_link_libraries( project ${KinectSDK2_LIBRARIES} )
+#
+# # [Build Events]>[Post-Build Event]>[Command Line]
+# add_custom_command( TARGET project POST_BUILD ${KinectSDK2_COMMANDS} )
+# endif()
+#
+# =============================================================================
+#
+# Copyright (c) 2016 Tsukasa SUGIURA
+# Distributed under the MIT License.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# =============================================================================
+
+##### Utility #####
+
+# Check Directory Macro
+macro(CHECK_DIR _DIR)
+ if(NOT EXISTS "${${_DIR}}")
+ message(WARNING "Directory \"${${_DIR}}\" not found.")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_DIR)
+ endif()
+endmacro()
+
+# Check Files Macro
+macro(CHECK_FILES _FILES _DIR)
+ set(_MISSING_FILES)
+ foreach(_FILE ${${_FILES}})
+ if(NOT EXISTS "${_FILE}")
+ get_filename_component(_FILE ${_FILE} NAME)
+ set(_MISSING_FILES "${_MISSING_FILES}${_FILE}, ")
+ endif()
+ endforeach()
+ if(_MISSING_FILES)
+ message(WARNING "In directory \"${${_DIR}}\" not found files: ${_MISSING_FILES}")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_FILES)
+ endif()
+endmacro()
+
+# Target Platform
+set(TARGET_PLATFORM)
+if(NOT CMAKE_CL_64)
+ set(TARGET_PLATFORM x86)
+else()
+ set(TARGET_PLATFORM x64)
+endif()
+
+##### Find Kinect SDK v2 #####
+
+# Found
+set(KinectSDK2_FOUND TRUE)
+if(MSVC_VERSION LESS 1700)
+ message(WARNING "Kinect for Windows SDK v2 supported Visual Studio 2012 or later.")
+ set(KinectSDK2_FOUND FALSE)
+endif()
+
+# Options
+option(KinectSDK2_FACE "Face and HDFace features" FALSE)
+option(KinectSDK2_FUSION "Fusion features" FALSE)
+option(KinectSDK2_VGB "Visual Gesture Builder features" FALSE)
+
+# Root Directoty
+set(KinectSDK2_DIR)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_DIR $ENV{KINECTSDK20_DIR} CACHE PATH "Kinect for Windows SDK v2 Install Path." FORCE)
+ check_dir(KinectSDK2_DIR)
+endif()
+
+# Include Directories
+set(KinectSDK2_INCLUDE_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_INCLUDE_DIRS ${KinectSDK2_DIR}/inc)
+ check_dir(KinectSDK2_INCLUDE_DIRS)
+endif()
+
+# Library Directories
+set(KinectSDK2_LIBRARY_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARY_DIRS ${KinectSDK2_DIR}/Lib/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Dependencies
+set(KinectSDK2_LIBRARIES)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib)
+
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Face.lib)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Fusion.lib)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.VisualGestureBuilder.lib)
+ endif()
+
+ check_files(KinectSDK2_LIBRARIES KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Custom Commands
+set(KinectSDK2_COMMANDS)
+if(KinectSDK2_FOUND)
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Face/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Fusion/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/VGB/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ # Empty Commands
+ if(NOT KinectSDK2_COMMANDS)
+ set(KinectSDK2_COMMANDS COMMAND)
+ endif()
+endif()
+
+message(STATUS "KinectSDK2_FOUND : ${KinectSDK2_FOUND}")
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/AudioBeam/app.cpp b/Kinect2Sample-master/sample/AudioBeam/app.cpp
new file mode 100644
index 0000000..8eb51b8
--- /dev/null
+++ b/Kinect2Sample-master/sample/AudioBeam/app.cpp
@@ -0,0 +1,179 @@
+#include "app.h"
+#include "util.h"
+
+#include
+#include
+#include
+#include
+
+#include
+
+// Constructor
+Kinect::Kinect()
+{
+ // Initialize
+ initialize();
+}
+
+// Destructor
+Kinect::~Kinect()
+{
+ // Finalize
+ finalize();
+}
+
+// Processing
+void Kinect::run()
+{
+ // Main Loop
+ while( true ){
+ // Update Data
+ update();
+
+ // Draw Data
+ draw();
+
+ // Show Data
+ show();
+
+ // Key Check
+ if( GetKeyState( VK_ESCAPE ) < 0 ){
+ break;
+ }
+ }
+}
+
+// Initialize
+void Kinect::initialize()
+{
+ // Initialize Sensor
+ initializeSensor();
+
+ // Initialize Audio
+ initializeAudio();
+
+ // Wait a Few Seconds until begins to Retrieve Data from Sensor ( about 2000-[ms] )
+ std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
+}
+
+// Initialize Sensor
+inline void Kinect::initializeSensor()
+{
+ // Open Sensor
+ ERROR_CHECK( GetDefaultKinectSensor( &kinect ) );
+
+ ERROR_CHECK( kinect->Open() );
+
+ // Check Open
+ BOOLEAN isOpen = FALSE;
+ ERROR_CHECK( kinect->get_IsOpen( &isOpen ) );
+ if( !isOpen ){
+ throw std::runtime_error( "failed IKinectSensor::get_IsOpen( &isOpen )" );
+ }
+}
+
+// Initialize Audio
+inline void Kinect::initializeAudio()
+{
+ // Retrieve Audio Source
+ ComPtr audioSource;
+ ERROR_CHECK( kinect->get_AudioSource( &audioSource ) );
+
+ // Open Audio Beam Reader
+ ERROR_CHECK( audioSource->OpenReader( &audioBeamFrameReader ) );
+}
+
+// Finalize
+void Kinect::finalize()
+{
+ // Close Sensor
+ if( kinect != nullptr ){
+ kinect->Close();
+ }
+}
+
+// Update Data
+void Kinect::update()
+{
+ // Update Audio
+ updateAudio();
+}
+
+// Update Audio
+inline void Kinect::updateAudio()
+{
+ // Retrieve Audio Beam Frame List
+ ComPtr audioBeamFrameList;
+ const HRESULT ret = audioBeamFrameReader->AcquireLatestBeamFrames( &audioBeamFrameList );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Retrieve Audio Beam Frame Count
+ UINT beamCount = 0;
+ ERROR_CHECK( audioBeamFrameList->get_BeamCount( &beamCount ) );
+
+ Concurrency::parallel_for( 0, static_cast( beamCount ), [&]( int i ){
+ // Retrieve Audio Beam Frame
+ ComPtr audioBeamFrame;
+ ERROR_CHECK( audioBeamFrameList->OpenAudioBeamFrame( i, &audioBeamFrame ) );
+
+ // Retrieve Audio Beam SubFrame Count
+ UINT subFrameCount = 0;
+ ERROR_CHECK( audioBeamFrame->get_SubFrameCount( &subFrameCount ) );
+
+ Concurrency::parallel_for( 0, static_cast( subFrameCount ), [&]( int j ){
+ // Retrieve Audio Beam SubFrame
+ ComPtr audioBeamSubFrame;
+ ERROR_CHECK( audioBeamFrame->GetSubFrame( j, &audioBeamSubFrame ) );
+
+ // Retrieve Beam Angle ( Radian +/- 1.0 )
+ ERROR_CHECK( audioBeamSubFrame->get_BeamAngle( &beamAngle ) );
+
+ // Retrieve Beam Angle Confidence ( 0.0 - 1.0 )
+ ERROR_CHECK( audioBeamSubFrame->get_BeamAngleConfidence( &beamAngleConfidence ) );
+ } );
+ } );
+}
+
+// Draw Data
+void Kinect::draw()
+{
+ // Draw Audio
+ drawAudio();
+}
+
+// Draw Audio
+inline void Kinect::drawAudio()
+{
+ // Clear Beam Angle Result Buffer
+ beamAngleResult.clear();
+
+ // Check Beam Angle Confidence
+ if( beamAngleConfidence > confidenceThreshold ){
+ // Convert Degree from Radian
+ const float degree = static_cast( beamAngle * 180.0 / M_PI );
+
+ // Add Beam Angle to Result Buffer
+ beamAngleResult = std::to_string( degree ) + " (" + std::to_string( beamAngleConfidence ) + ")";
+ }
+}
+
+// Show Data
+void Kinect::show()
+{
+ // Show Audio
+ showAudio();
+}
+
+// Show Audio
+inline void Kinect::showAudio()
+{
+ // Check Empty Result Buffer
+ if( !beamAngleResult.size() ){
+ return;
+ }
+
+ // Show Result
+ std::cout << beamAngleResult << std::endl;
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/AudioBeam/app.h b/Kinect2Sample-master/sample/AudioBeam/app.h
new file mode 100644
index 0000000..4b99b85
--- /dev/null
+++ b/Kinect2Sample-master/sample/AudioBeam/app.h
@@ -0,0 +1,70 @@
+#ifndef __APP__
+#define __APP__
+
+#define _USE_MATH_DEFINES
+#include
+#include
+
+#include
+
+#include
+using namespace Microsoft::WRL;
+
+class Kinect
+{
+private:
+ // Sensor
+ ComPtr kinect;
+
+ // Reader
+ ComPtr audioBeamFrameReader;
+
+ // Audio Buffer
+ float beamAngle = 0.f;
+ float beamAngleConfidence = 0.f;
+ std::string beamAngleResult;
+ const float confidenceThreshold = 0.3f;
+
+public:
+ // Constructor
+ Kinect();
+
+ // Destructor
+ ~Kinect();
+
+ // Processing
+ void run();
+
+private:
+ // Initialize
+ void initialize();
+
+ // Initialize Sensor
+ inline void initializeSensor();
+
+ // Initialize Audio
+ inline void initializeAudio();
+
+ // Finalize
+ void finalize();
+
+ // Update Data
+ void update();
+
+ // Update Audio
+ inline void updateAudio();
+
+ // Draw Data
+ void draw();
+
+ // Draw Audio
+ inline void drawAudio();
+
+ // Show Data
+ void show();
+
+ // Show Audio
+ inline void showAudio();
+};
+
+#endif // __APP__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/AudioBeam/main.cpp b/Kinect2Sample-master/sample/AudioBeam/main.cpp
new file mode 100644
index 0000000..d88643c
--- /dev/null
+++ b/Kinect2Sample-master/sample/AudioBeam/main.cpp
@@ -0,0 +1,16 @@
+#include
+#include
+
+#include "app.h"
+
+int main( int argc, char* argv[] )
+{
+ try{
+ Kinect kinect;
+ kinect.run();
+ } catch( std::exception& ex ){
+ std::cout << ex.what() << std::endl;
+ }
+
+ return 0;
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/AudioBeam/util.h b/Kinect2Sample-master/sample/AudioBeam/util.h
new file mode 100644
index 0000000..0d9787f
--- /dev/null
+++ b/Kinect2Sample-master/sample/AudioBeam/util.h
@@ -0,0 +1,37 @@
+#ifndef __UTIL__
+#define __UTIL__
+
+#include
+#include
+
+// Error Check Macro
+#define ERROR_CHECK( ret ) \
+ if( FAILED( ret ) ){ \
+ std::stringstream ss; \
+ ss << "failed " #ret " " << std::hex << ret << std::endl; \
+ throw std::runtime_error( ss.str().c_str() ); \
+ }
+
+// Safe Release
+template
+inline void SafeRelease( T*& rel )
+{
+ if( rel != NULL ){
+ rel->Release();
+ rel = NULL;
+ }
+}
+
+// C++ Style Line Types For OpenCV 2.x
+#if ( CV_MAJOR_VERSION < 3 )
+namespace cv{
+ enum LineTypes{
+ FILLED = -1,
+ LINE_4 = 4,
+ LINE_8 = 8,
+ LINE_AA = 16
+ };
+}
+#endif
+
+#endif // __UTIL__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/AudioBody/CMakeLists.txt b/Kinect2Sample-master/sample/AudioBody/CMakeLists.txt
new file mode 100644
index 0000000..6be74c4
--- /dev/null
+++ b/Kinect2Sample-master/sample/AudioBody/CMakeLists.txt
@@ -0,0 +1,43 @@
+cmake_minimum_required( VERSION 3.6 )
+
+# Create Project
+project( Sample )
+add_executable( AudioBody app.h app.cpp main.cpp util.h )
+
+# Set StartUp Project
+set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "AudioBody" )
+
+# Find Package
+set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} )
+find_package( KinectSDK2 REQUIRED )
+
+set( OpenCV_DIR "C:/Program Files/opencv/build" )
+option( OpenCV_STATIC OFF )
+find_package( OpenCV REQUIRED )
+
+# Set Static Link Runtime Library
+if( OpenCV_STATIC )
+ foreach( flag_var
+ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO )
+ if( ${flag_var} MATCHES "/MD" )
+ string( REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}" )
+ endif()
+ endforeach()
+endif()
+
+if( KinectSDK2_FOUND AND OpenCV_FOUND )
+ # Additional Include Directories
+ include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+ include_directories( ${OpenCV_INCLUDE_DIRS} )
+
+ # Additional Library Directories
+ link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+ link_directories( ${OpenCV_LIB_DIR} )
+
+ # Additional Dependencies
+ target_link_libraries( AudioBody ${KinectSDK2_LIBRARIES} )
+ target_link_libraries( AudioBody ${OpenCV_LIBS} )
+endif()
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/AudioBody/FindKinectSDK2.cmake b/Kinect2Sample-master/sample/AudioBody/FindKinectSDK2.cmake
new file mode 100644
index 0000000..00a2036
--- /dev/null
+++ b/Kinect2Sample-master/sample/AudioBody/FindKinectSDK2.cmake
@@ -0,0 +1,182 @@
+#.rst:
+# FindKinectSDK2
+# --------------
+#
+# Find Kinect for Windows SDK v2 (Kinect SDK v2) include dirs, library dirs, libraries and post-build commands
+#
+# Use this module by invoking find_package with the form::
+#
+# find_package( KinectSDK2 [REQUIRED] )
+#
+# Results for users are reported in following variables::
+#
+# KinectSDK2_FOUND - Return "TRUE" when Kinect SDK v2 found. Otherwise, Return "FALSE".
+# KinectSDK2_INCLUDE_DIRS - Kinect SDK v2 include directories. (${KinectSDK2_DIR}/inc)
+# KinectSDK2_LIBRARY_DIRS - Kinect SDK v2 library directories. (${KinectSDK2_DIR}/Lib/x86 or ${KinectSDK2_DIR}/Lib/x64)
+# KinectSDK2_LIBRARIES - Kinect SDK v2 library files. (${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib (If check the box of any application festures, corresponding library will be added.))
+# KinectSDK2_COMMANDS - Copy commands of redist files for application functions of Kinect SDK v2. (If uncheck the box of all application features, this variable has defined empty command.)
+#
+# This module reads hints about search locations from following environment variables::
+#
+# KINECTSDK20_DIR - Kinect SDK v2 root directory. (This environment variable has been set by installer of Kinect SDK v2.)
+#
+# CMake entries::
+#
+# KinectSDK2_DIR - Kinect SDK v2 root directory. (Default $ENV{KINECTSDK20_DIR})
+# KinectSDK2_FACE - Check the box when using Face or HDFace features. (Default uncheck)
+# KinectSDK2_FUSION - Check the box when using Fusion features. (Default uncheck)
+# KinectSDK2_VGB - Check the box when using Visual Gesture Builder features. (Default uncheck)
+#
+# Example to find Kinect SDK v2::
+#
+# cmake_minimum_required( VERSION 2.8 )
+#
+# project( project )
+# add_executable( project main.cpp )
+#
+# # Find package using this module.
+# find_package( KinectSDK2 REQUIRED )
+#
+# if(KinectSDK2_FOUND)
+# # [C/C++]>[General]>[Additional Include Directories]
+# include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+#
+# # [Linker]>[General]>[Additional Library Directories]
+# link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+#
+# # [Linker]>[Input]>[Additional Dependencies]
+# target_link_libraries( project ${KinectSDK2_LIBRARIES} )
+#
+# # [Build Events]>[Post-Build Event]>[Command Line]
+# add_custom_command( TARGET project POST_BUILD ${KinectSDK2_COMMANDS} )
+# endif()
+#
+# =============================================================================
+#
+# Copyright (c) 2016 Tsukasa SUGIURA
+# Distributed under the MIT License.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# =============================================================================
+
+##### Utility #####
+
+# Check Directory Macro
+macro(CHECK_DIR _DIR)
+ if(NOT EXISTS "${${_DIR}}")
+ message(WARNING "Directory \"${${_DIR}}\" not found.")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_DIR)
+ endif()
+endmacro()
+
+# Check Files Macro
+macro(CHECK_FILES _FILES _DIR)
+ set(_MISSING_FILES)
+ foreach(_FILE ${${_FILES}})
+ if(NOT EXISTS "${_FILE}")
+ get_filename_component(_FILE ${_FILE} NAME)
+ set(_MISSING_FILES "${_MISSING_FILES}${_FILE}, ")
+ endif()
+ endforeach()
+ if(_MISSING_FILES)
+ message(WARNING "In directory \"${${_DIR}}\" not found files: ${_MISSING_FILES}")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_FILES)
+ endif()
+endmacro()
+
+# Target Platform
+set(TARGET_PLATFORM)
+if(NOT CMAKE_CL_64)
+ set(TARGET_PLATFORM x86)
+else()
+ set(TARGET_PLATFORM x64)
+endif()
+
+##### Find Kinect SDK v2 #####
+
+# Found
+set(KinectSDK2_FOUND TRUE)
+if(MSVC_VERSION LESS 1700)
+ message(WARNING "Kinect for Windows SDK v2 supported Visual Studio 2012 or later.")
+ set(KinectSDK2_FOUND FALSE)
+endif()
+
+# Options
+option(KinectSDK2_FACE "Face and HDFace features" FALSE)
+option(KinectSDK2_FUSION "Fusion features" FALSE)
+option(KinectSDK2_VGB "Visual Gesture Builder features" FALSE)
+
+# Root Directoty
+set(KinectSDK2_DIR)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_DIR $ENV{KINECTSDK20_DIR} CACHE PATH "Kinect for Windows SDK v2 Install Path." FORCE)
+ check_dir(KinectSDK2_DIR)
+endif()
+
+# Include Directories
+set(KinectSDK2_INCLUDE_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_INCLUDE_DIRS ${KinectSDK2_DIR}/inc)
+ check_dir(KinectSDK2_INCLUDE_DIRS)
+endif()
+
+# Library Directories
+set(KinectSDK2_LIBRARY_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARY_DIRS ${KinectSDK2_DIR}/Lib/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Dependencies
+set(KinectSDK2_LIBRARIES)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib)
+
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Face.lib)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Fusion.lib)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.VisualGestureBuilder.lib)
+ endif()
+
+ check_files(KinectSDK2_LIBRARIES KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Custom Commands
+set(KinectSDK2_COMMANDS)
+if(KinectSDK2_FOUND)
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Face/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Fusion/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/VGB/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ # Empty Commands
+ if(NOT KinectSDK2_COMMANDS)
+ set(KinectSDK2_COMMANDS COMMAND)
+ endif()
+endif()
+
+message(STATUS "KinectSDK2_FOUND : ${KinectSDK2_FOUND}")
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/AudioBody/app.cpp b/Kinect2Sample-master/sample/AudioBody/app.cpp
new file mode 100644
index 0000000..59c1439
--- /dev/null
+++ b/Kinect2Sample-master/sample/AudioBody/app.cpp
@@ -0,0 +1,308 @@
+#include "app.h"
+#include "util.h"
+
+#include
+#include
+#include
+
+#include
+
+// Constructor
+Kinect::Kinect()
+{
+ // Initialize
+ initialize();
+}
+
+// Destructor
+Kinect::~Kinect()
+{
+ // Finalize
+ finalize();
+}
+
+// Processing
+void Kinect::run()
+{
+ // Main Loop
+ while( true ){
+ // Update Data
+ update();
+
+ // Draw Data
+ draw();
+
+ // Show Data
+ show();
+
+ // Key Check
+ const int key = cv::waitKey( 10 );
+ if( key == VK_ESCAPE ){
+ break;
+ }
+ }
+}
+
+// Initialize
+void Kinect::initialize()
+{
+ cv::setUseOptimized( true );
+
+ // Initialize Sensor
+ initializeSensor();
+
+ // Initialize Audio
+ initializeAudio();
+
+ // Initialize Body
+ initializeBody();
+
+ // Initialize BodyIndex
+ initializeBodyIndex();
+
+ // Wait a Few Seconds until begins to Retrieve Data from Sensor ( about 2000-[ms] )
+ std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
+}
+
+// Initialize Sensor
+inline void Kinect::initializeSensor()
+{
+ // Open Sensor
+ ERROR_CHECK( GetDefaultKinectSensor( &kinect ) );
+
+ ERROR_CHECK( kinect->Open() );
+
+ // Check Open
+ BOOLEAN isOpen = FALSE;
+ ERROR_CHECK( kinect->get_IsOpen( &isOpen ) );
+ if( !isOpen ){
+ throw std::runtime_error( "failed IKinectSensor::get_IsOpen( &isOpen )" );
+ }
+}
+
+// Initialize Audio
+inline void Kinect::initializeAudio()
+{
+ // Retrieve Audio Source
+ ComPtr audioSource;
+ ERROR_CHECK( kinect->get_AudioSource( &audioSource ) );
+
+ // Open Audio Beam Reader
+ ERROR_CHECK( audioSource->OpenReader( &audioBeamFrameReader ) );
+}
+
+// Initialize Body
+inline void Kinect::initializeBody()
+{
+ // Open Body Reader
+ ComPtr bodyFrameSource;
+ ERROR_CHECK( kinect->get_BodyFrameSource( &bodyFrameSource ) );
+ ERROR_CHECK( bodyFrameSource->OpenReader( &bodyFrameReader ) );
+
+ // Initialize Body Buffer
+ Concurrency::parallel_for_each( bodies.begin(), bodies.end(), []( IBody*& body ){
+ SafeRelease( body );
+ } );
+}
+
+// Initialize BodyIndex
+inline void Kinect::initializeBodyIndex()
+{
+ // Open BodyIndex Reader
+ ComPtr bodyIndexFrameSource;
+ ERROR_CHECK( kinect->get_BodyIndexFrameSource( &bodyIndexFrameSource ) );
+ ERROR_CHECK( bodyIndexFrameSource->OpenReader( &bodyIndexFrameReader ) );
+
+ // Retrieve BodyIndex Description
+ ComPtr bodyIndexFrameDescription;
+ ERROR_CHECK( bodyIndexFrameSource->get_FrameDescription( &bodyIndexFrameDescription ) );
+ ERROR_CHECK( bodyIndexFrameDescription->get_Width( &bodyIndexWidth ) ); // 512
+ ERROR_CHECK( bodyIndexFrameDescription->get_Height( &bodyIndexHeight ) ); // 424
+
+ // Allocation BodyIndex Buffer
+ bodyIndexBuffer.resize( bodyIndexWidth * bodyIndexHeight );
+
+ // Color Table for Visualization
+ colors[0] = cv::Vec3b( 255, 0, 0 ); // Blue
+ colors[1] = cv::Vec3b( 0, 255, 0 ); // Green
+ colors[2] = cv::Vec3b( 0, 0, 255 ); // Red
+ colors[3] = cv::Vec3b( 255, 255, 0 ); // Cyan
+ colors[4] = cv::Vec3b( 255, 0, 255 ); // Magenta
+ colors[5] = cv::Vec3b( 0, 255, 255 ); // Yellow
+}
+
+// Finalize
+void Kinect::finalize()
+{
+ cv::destroyAllWindows();
+
+ // Release Body Buffer
+ Concurrency::parallel_for_each( bodies.begin(), bodies.end(), []( IBody*& body ){
+ SafeRelease( body );
+ } );
+
+ // Close Sensor
+ if( kinect != nullptr ){
+ kinect->Close();
+ }
+}
+
+// Update Data
+void Kinect::update()
+{
+ // Update Audio
+ updateAudio();
+
+ // Update Body
+ updateBody();
+
+ // Update BodyIndex
+ updateBodyIndex();
+}
+
+// Update Audio
+inline void Kinect::updateAudio()
+{
+ // Initialize Tracking ID
+ audioTrackingId = std::numeric_limits::max() - 1;
+
+ // Retrieve Audio Beam Frame List
+ ComPtr audioBeamFrameList;
+ const HRESULT ret = audioBeamFrameReader->AcquireLatestBeamFrames( &audioBeamFrameList );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Retrieve Audio Beam Frame Count
+ UINT beamCount = 0;
+ ERROR_CHECK( audioBeamFrameList->get_BeamCount( &beamCount ) );
+
+ for( int i = 0; i < beamCount; i++ ){
+ // Retrieve Audio Beam Frame
+ ComPtr audioBeamFrame;
+ ERROR_CHECK( audioBeamFrameList->OpenAudioBeamFrame( i, &audioBeamFrame ) );
+
+ // Retrieve Audio Beam SubFrame Count
+ UINT subFrameCount = 0;
+ ERROR_CHECK( audioBeamFrame->get_SubFrameCount( &subFrameCount ) );
+
+ for( int j = 0; j < subFrameCount; j++ ){
+ // Retrieve Audio Beam SubFrame
+ ComPtr audioBeamSubFrame;
+ ERROR_CHECK( audioBeamFrame->GetSubFrame( j, &audioBeamSubFrame ) );
+
+ // Retrieve Audio Body Correlation Count
+ UINT32 correlationCount;
+ ERROR_CHECK( audioBeamSubFrame->get_AudioBodyCorrelationCount( &correlationCount ) );
+
+ // Check Correlation Count
+ if( correlationCount == 0 ){
+ return;
+ }
+
+ // Retrieve First Audio Body Correlation
+ ComPtr audioBodyCorrelation;
+ ERROR_CHECK( audioBeamSubFrame->GetAudioBodyCorrelation( 0, &audioBodyCorrelation ) );
+
+ // Retrieve Tracking ID
+ ERROR_CHECK( audioBodyCorrelation->get_BodyTrackingId( &audioTrackingId ) );
+ }
+ }
+}
+
+// Update Body
+inline void Kinect::updateBody()
+{
+ // Initialize Tracking Index
+ audioTrackingIndex = -1;
+
+ // Check Tracking ID
+ if( audioTrackingId == std::numeric_limits::max() - 1 ){
+ return;
+ }
+
+ // Retrieve Body Frame
+ ComPtr bodyFrame;
+ const HRESULT ret = bodyFrameReader->AcquireLatestFrame( &bodyFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Release Previous Bodies
+ Concurrency::parallel_for_each( bodies.begin(), bodies.end(), []( IBody*& body ){
+ SafeRelease( body );
+ } );
+
+ // Retrieve Body Data
+ ERROR_CHECK( bodyFrame->GetAndRefreshBodyData( static_cast( bodies.size() ), &bodies[0] ) );
+
+ for( int count = 0; count < BODY_COUNT; count++ ){
+ // Retrive Tracking ID
+ UINT64 trackingId;
+ bodies[count]->get_TrackingId( &trackingId );
+
+ // Check Tracking ID
+ if( trackingId == audioTrackingId ){
+ audioTrackingIndex = count;
+ break;
+ }
+ }
+}
+
+// Update BodyIndex
+inline void Kinect::updateBodyIndex()
+{
+
+ // Retrieve BodyIndex Frame
+ ComPtr bodyIndexFrame;
+ const HRESULT ret = bodyIndexFrameReader->AcquireLatestFrame( &bodyIndexFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Retrieve BodyIndex Data
+ ERROR_CHECK( bodyIndexFrame->CopyFrameDataToArray( static_cast( bodyIndexBuffer.size() ), &bodyIndexBuffer[0] ) );
+}
+
+// Draw Data
+void Kinect::draw()
+{
+ // Draw BodyIndex
+ drawBodyIndex();
+}
+
+// Draw BodyIndex
+inline void Kinect::drawBodyIndex()
+{
+ // Check Tracking Index
+ if( audioTrackingIndex == -1 ){
+ return;
+ }
+
+ // Visualization BodyIndex
+ bodyIndexMat = cv::Mat::zeros( bodyIndexHeight, bodyIndexWidth, CV_8UC3 );
+ bodyIndexMat.forEach( [&]( cv::Vec3b &p, const int* position ){
+ uchar index = bodyIndexBuffer[position[0] * bodyIndexWidth + position[1]];
+ if( index == audioTrackingIndex ){
+ p = colors[index];
+ }
+ } );
+}
+
+// Show Data
+void Kinect::show()
+{
+ // Show BodyIndex
+ showBodyIndex();
+}
+
+// Show BodyIndex
+inline void Kinect::showBodyIndex()
+{
+ if( bodyIndexMat.empty() ){
+ return;
+ }
+
+ // Show Image
+ cv::imshow( "AudiBody", bodyIndexMat );
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/AudioBody/app.h b/Kinect2Sample-master/sample/AudioBody/app.h
new file mode 100644
index 0000000..a73feee
--- /dev/null
+++ b/Kinect2Sample-master/sample/AudioBody/app.h
@@ -0,0 +1,96 @@
+#ifndef __APP__
+#define __APP__
+
+#include
+#include
+#include
+
+#include
+#include
+
+#include
+using namespace Microsoft::WRL;
+
+class Kinect
+{
+private:
+ // Sensor
+ ComPtr kinect;
+
+ // Reader
+ ComPtr bodyFrameReader;
+ ComPtr bodyIndexFrameReader;
+ ComPtr audioBeamFrameReader;
+
+ // Body Buffer
+ std::array bodies = { nullptr };
+
+ // BodyIndex Buffer
+ std::vector bodyIndexBuffer;
+ int bodyIndexWidth;
+ int bodyIndexHeight;
+ cv::Mat bodyIndexMat;
+ std::array colors;
+
+ // Audio Buffer
+ UINT64 audioTrackingId;
+ int audioTrackingIndex;
+
+public:
+ // Constructor
+ Kinect();
+
+ // Destructor
+ ~Kinect();
+
+ // Processing
+ void run();
+
+private:
+ // Initialize
+ void initialize();
+
+ // Initialize Sensor
+ inline void initializeSensor();
+
+ // Initialize Body
+ inline void initializeBody();
+
+ // Initialize BodyIndex
+ inline void initializeBodyIndex();
+
+ // Initialize Audio
+ inline void initializeAudio();
+
+ // Finalize
+ void finalize();
+
+ // Update Data
+ void update();
+
+ // Update Body
+ inline void updateBody();
+
+ // Update BodyIndex
+ inline void updateBodyIndex();
+
+ // Update Audio
+ inline void updateAudio();
+
+ // Draw Data
+ void draw();
+
+ // Draw BodyIndex
+ inline void drawBodyIndex();
+
+ // Draw Audio
+ inline void drawAudio();
+
+ // Show Data
+ void show();
+
+ // Show BodyIndex
+ inline void showBodyIndex();
+};
+
+#endif // __APP__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/AudioBody/main.cpp b/Kinect2Sample-master/sample/AudioBody/main.cpp
new file mode 100644
index 0000000..d88643c
--- /dev/null
+++ b/Kinect2Sample-master/sample/AudioBody/main.cpp
@@ -0,0 +1,16 @@
+#include
+#include
+
+#include "app.h"
+
+int main( int argc, char* argv[] )
+{
+ try{
+ Kinect kinect;
+ kinect.run();
+ } catch( std::exception& ex ){
+ std::cout << ex.what() << std::endl;
+ }
+
+ return 0;
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/AudioBody/util.h b/Kinect2Sample-master/sample/AudioBody/util.h
new file mode 100644
index 0000000..0d9787f
--- /dev/null
+++ b/Kinect2Sample-master/sample/AudioBody/util.h
@@ -0,0 +1,37 @@
+#ifndef __UTIL__
+#define __UTIL__
+
+#include
+#include
+
+// Error Check Macro
+#define ERROR_CHECK( ret ) \
+ if( FAILED( ret ) ){ \
+ std::stringstream ss; \
+ ss << "failed " #ret " " << std::hex << ret << std::endl; \
+ throw std::runtime_error( ss.str().c_str() ); \
+ }
+
+// Safe Release
+template
+inline void SafeRelease( T*& rel )
+{
+ if( rel != NULL ){
+ rel->Release();
+ rel = NULL;
+ }
+}
+
+// C++ Style Line Types For OpenCV 2.x
+#if ( CV_MAJOR_VERSION < 3 )
+namespace cv{
+ enum LineTypes{
+ FILLED = -1,
+ LINE_4 = 4,
+ LINE_8 = 8,
+ LINE_AA = 16
+ };
+}
+#endif
+
+#endif // __UTIL__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Body/CMakeLists.txt b/Kinect2Sample-master/sample/Body/CMakeLists.txt
new file mode 100644
index 0000000..d7d6afc
--- /dev/null
+++ b/Kinect2Sample-master/sample/Body/CMakeLists.txt
@@ -0,0 +1,43 @@
+cmake_minimum_required( VERSION 3.6 )
+
+# Create Project
+project( Sample )
+add_executable( Body app.h app.cpp main.cpp util.h )
+
+# Set StartUp Project
+set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "Body" )
+
+# Find Package
+set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} )
+find_package( KinectSDK2 REQUIRED )
+
+set( OpenCV_DIR "C:/Program Files/opencv/build" )
+option( OpenCV_STATIC OFF )
+find_package( OpenCV REQUIRED )
+
+# Set Static Link Runtime Library
+if( OpenCV_STATIC )
+ foreach( flag_var
+ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO )
+ if( ${flag_var} MATCHES "/MD" )
+ string( REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}" )
+ endif()
+ endforeach()
+endif()
+
+if( KinectSDK2_FOUND AND OpenCV_FOUND )
+ # Additional Include Directories
+ include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+ include_directories( ${OpenCV_INCLUDE_DIRS} )
+
+ # Additional Library Directories
+ link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+ link_directories( ${OpenCV_LIB_DIR} )
+
+ # Additional Dependencies
+ target_link_libraries( Body ${KinectSDK2_LIBRARIES} )
+ target_link_libraries( Body ${OpenCV_LIBS} )
+endif()
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Body/FindKinectSDK2.cmake b/Kinect2Sample-master/sample/Body/FindKinectSDK2.cmake
new file mode 100644
index 0000000..00a2036
--- /dev/null
+++ b/Kinect2Sample-master/sample/Body/FindKinectSDK2.cmake
@@ -0,0 +1,182 @@
+#.rst:
+# FindKinectSDK2
+# --------------
+#
+# Find Kinect for Windows SDK v2 (Kinect SDK v2) include dirs, library dirs, libraries and post-build commands
+#
+# Use this module by invoking find_package with the form::
+#
+# find_package( KinectSDK2 [REQUIRED] )
+#
+# Results for users are reported in following variables::
+#
+# KinectSDK2_FOUND - Return "TRUE" when Kinect SDK v2 found. Otherwise, Return "FALSE".
+# KinectSDK2_INCLUDE_DIRS - Kinect SDK v2 include directories. (${KinectSDK2_DIR}/inc)
+# KinectSDK2_LIBRARY_DIRS - Kinect SDK v2 library directories. (${KinectSDK2_DIR}/Lib/x86 or ${KinectSDK2_DIR}/Lib/x64)
+# KinectSDK2_LIBRARIES - Kinect SDK v2 library files. (${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib (If check the box of any application festures, corresponding library will be added.))
+# KinectSDK2_COMMANDS - Copy commands of redist files for application functions of Kinect SDK v2. (If uncheck the box of all application features, this variable has defined empty command.)
+#
+# This module reads hints about search locations from following environment variables::
+#
+# KINECTSDK20_DIR - Kinect SDK v2 root directory. (This environment variable has been set by installer of Kinect SDK v2.)
+#
+# CMake entries::
+#
+# KinectSDK2_DIR - Kinect SDK v2 root directory. (Default $ENV{KINECTSDK20_DIR})
+# KinectSDK2_FACE - Check the box when using Face or HDFace features. (Default uncheck)
+# KinectSDK2_FUSION - Check the box when using Fusion features. (Default uncheck)
+# KinectSDK2_VGB - Check the box when using Visual Gesture Builder features. (Default uncheck)
+#
+# Example to find Kinect SDK v2::
+#
+# cmake_minimum_required( VERSION 2.8 )
+#
+# project( project )
+# add_executable( project main.cpp )
+#
+# # Find package using this module.
+# find_package( KinectSDK2 REQUIRED )
+#
+# if(KinectSDK2_FOUND)
+# # [C/C++]>[General]>[Additional Include Directories]
+# include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+#
+# # [Linker]>[General]>[Additional Library Directories]
+# link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+#
+# # [Linker]>[Input]>[Additional Dependencies]
+# target_link_libraries( project ${KinectSDK2_LIBRARIES} )
+#
+# # [Build Events]>[Post-Build Event]>[Command Line]
+# add_custom_command( TARGET project POST_BUILD ${KinectSDK2_COMMANDS} )
+# endif()
+#
+# =============================================================================
+#
+# Copyright (c) 2016 Tsukasa SUGIURA
+# Distributed under the MIT License.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# =============================================================================
+
+##### Utility #####
+
+# Check Directory Macro
+macro(CHECK_DIR _DIR)
+ if(NOT EXISTS "${${_DIR}}")
+ message(WARNING "Directory \"${${_DIR}}\" not found.")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_DIR)
+ endif()
+endmacro()
+
+# Check Files Macro
+macro(CHECK_FILES _FILES _DIR)
+ set(_MISSING_FILES)
+ foreach(_FILE ${${_FILES}})
+ if(NOT EXISTS "${_FILE}")
+ get_filename_component(_FILE ${_FILE} NAME)
+ set(_MISSING_FILES "${_MISSING_FILES}${_FILE}, ")
+ endif()
+ endforeach()
+ if(_MISSING_FILES)
+ message(WARNING "In directory \"${${_DIR}}\" not found files: ${_MISSING_FILES}")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_FILES)
+ endif()
+endmacro()
+
+# Target Platform
+set(TARGET_PLATFORM)
+if(NOT CMAKE_CL_64)
+ set(TARGET_PLATFORM x86)
+else()
+ set(TARGET_PLATFORM x64)
+endif()
+
+##### Find Kinect SDK v2 #####
+
+# Found
+set(KinectSDK2_FOUND TRUE)
+if(MSVC_VERSION LESS 1700)
+ message(WARNING "Kinect for Windows SDK v2 supported Visual Studio 2012 or later.")
+ set(KinectSDK2_FOUND FALSE)
+endif()
+
+# Options
+option(KinectSDK2_FACE "Face and HDFace features" FALSE)
+option(KinectSDK2_FUSION "Fusion features" FALSE)
+option(KinectSDK2_VGB "Visual Gesture Builder features" FALSE)
+
+# Root Directoty
+set(KinectSDK2_DIR)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_DIR $ENV{KINECTSDK20_DIR} CACHE PATH "Kinect for Windows SDK v2 Install Path." FORCE)
+ check_dir(KinectSDK2_DIR)
+endif()
+
+# Include Directories
+set(KinectSDK2_INCLUDE_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_INCLUDE_DIRS ${KinectSDK2_DIR}/inc)
+ check_dir(KinectSDK2_INCLUDE_DIRS)
+endif()
+
+# Library Directories
+set(KinectSDK2_LIBRARY_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARY_DIRS ${KinectSDK2_DIR}/Lib/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Dependencies
+set(KinectSDK2_LIBRARIES)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib)
+
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Face.lib)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Fusion.lib)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.VisualGestureBuilder.lib)
+ endif()
+
+ check_files(KinectSDK2_LIBRARIES KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Custom Commands
+set(KinectSDK2_COMMANDS)
+if(KinectSDK2_FOUND)
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Face/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Fusion/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/VGB/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ # Empty Commands
+ if(NOT KinectSDK2_COMMANDS)
+ set(KinectSDK2_COMMANDS COMMAND)
+ endif()
+endif()
+
+message(STATUS "KinectSDK2_FOUND : ${KinectSDK2_FOUND}")
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Body/app.cpp b/Kinect2Sample-master/sample/Body/app.cpp
new file mode 100644
index 0000000..6f9a4ed
--- /dev/null
+++ b/Kinect2Sample-master/sample/Body/app.cpp
@@ -0,0 +1,335 @@
+#include "app.h"
+#include "util.h"
+
+#include
+#include
+
+#include
+
+// Constructor
+Kinect::Kinect()
+{
+ // Initialize
+ initialize();
+}
+
+// Destructor
+Kinect::~Kinect()
+{
+ // Finalize
+ finalize();
+}
+
+// Processing
+void Kinect::run()
+{
+ // Main Loop
+ while( true ){
+ // Update Data
+ update();
+
+ // Draw Data
+ draw();
+
+ // Show Data
+ show();
+
+ // Key Check
+ const int key = cv::waitKey( 10 );
+ if( key == VK_ESCAPE ){
+ break;
+ }
+ }
+}
+
+// Initialize
+void Kinect::initialize()
+{
+ cv::setUseOptimized( true );
+
+ // Initialize Sensor
+ initializeSensor();
+
+ // Initialize Color
+ initializeColor();
+
+ // Initialize Body
+ initializeBody();
+
+ // Wait a Few Seconds until begins to Retrieve Data from Sensor ( about 2000-[ms] )
+ std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
+}
+
+// Initialize Sensor
+inline void Kinect::initializeSensor()
+{
+ // Open Sensor
+ ERROR_CHECK( GetDefaultKinectSensor( &kinect ) );
+
+ ERROR_CHECK( kinect->Open() );
+
+ // Check Open
+ BOOLEAN isOpen = FALSE;
+ ERROR_CHECK( kinect->get_IsOpen( &isOpen ) );
+ if( !isOpen ){
+ throw std::runtime_error( "failed IKinectSensor::get_IsOpen( &isOpen )" );
+ }
+
+ // Retrieve Coordinate Mapper
+ ERROR_CHECK( kinect->get_CoordinateMapper( &coordinateMapper ) );
+}
+
+// Initialize Color
+inline void Kinect::initializeColor()
+{
+ // Open Color Reader
+ ComPtr colorFrameSource;
+ ERROR_CHECK( kinect->get_ColorFrameSource( &colorFrameSource ) );
+ ERROR_CHECK( colorFrameSource->OpenReader( &colorFrameReader ) );
+
+ // Retrieve Color Description
+ ComPtr colorFrameDescription;
+ ERROR_CHECK( colorFrameSource->CreateFrameDescription( ColorImageFormat::ColorImageFormat_Bgra, &colorFrameDescription ) );
+ ERROR_CHECK( colorFrameDescription->get_Width( &colorWidth ) ); // 1920
+ ERROR_CHECK( colorFrameDescription->get_Height( &colorHeight ) ); // 1080
+ ERROR_CHECK( colorFrameDescription->get_BytesPerPixel( &colorBytesPerPixel ) ); // 4
+
+ // Allocation Color Buffer
+ colorBuffer.resize( colorWidth * colorHeight * colorBytesPerPixel );
+}
+
+// Initialize Body
+inline void Kinect::initializeBody()
+{
+ // Open Body Reader
+ ComPtr bodyFrameSource;
+ ERROR_CHECK( kinect->get_BodyFrameSource( &bodyFrameSource ) );
+ ERROR_CHECK( bodyFrameSource->OpenReader( &bodyFrameReader ) );
+
+ // Initialize Body Buffer
+ Concurrency::parallel_for_each( bodies.begin(), bodies.end(), []( IBody*& body ){
+ SafeRelease( body );
+ } );
+
+ // Color Table for Visualization
+ colors[0] = cv::Vec3b( 255, 0, 0 ); // Blue
+ colors[1] = cv::Vec3b( 0, 255, 0 ); // Green
+ colors[2] = cv::Vec3b( 0, 0, 255 ); // Red
+ colors[3] = cv::Vec3b( 255, 255, 0 ); // Cyan
+ colors[4] = cv::Vec3b( 255, 0, 255 ); // Magenta
+ colors[5] = cv::Vec3b( 0, 255, 255 ); // Yellow
+}
+
+// Finalize
+void Kinect::finalize()
+{
+ cv::destroyAllWindows();
+
+ // Release Body Buffer
+ Concurrency::parallel_for_each( bodies.begin(), bodies.end(), []( IBody*& body ){
+ SafeRelease( body );
+ } );
+
+ // Close Sensor
+ if( kinect != nullptr ){
+ kinect->Close();
+ }
+}
+
+// Update Data
+void Kinect::update()
+{
+ // Update Color
+ updateColor();
+
+ // Update Body
+ updateBody();
+}
+
+// Update Color
+inline void Kinect::updateColor()
+{
+ // Retrieve Color Frame
+ ComPtr colorFrame;
+ const HRESULT ret = colorFrameReader->AcquireLatestFrame( &colorFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Convert Format ( YUY2 -> BGRA )
+ ERROR_CHECK( colorFrame->CopyConvertedFrameDataToArray( static_cast( colorBuffer.size() ), &colorBuffer[0], ColorImageFormat::ColorImageFormat_Bgra ) );
+}
+
+// Update Body
+inline void Kinect::updateBody()
+{
+ // Retrieve Body Frame
+ ComPtr bodyFrame;
+ const HRESULT ret = bodyFrameReader->AcquireLatestFrame( &bodyFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Release Previous Bodies
+ Concurrency::parallel_for_each( bodies.begin(), bodies.end(), []( IBody*& body ){
+ SafeRelease( body );
+ } );
+
+ // Retrieve Body Data
+ ERROR_CHECK( bodyFrame->GetAndRefreshBodyData( static_cast( bodies.size() ), &bodies[0] ) );
+}
+
+// Draw Data
+void Kinect::draw()
+{
+ // Draw Color
+ drawColor();
+
+ // Draw Body
+ drawBody();
+}
+
+// Draw Color
+inline void Kinect::drawColor()
+{
+ // Create cv::Mat from Color Buffer
+ colorMat = cv::Mat( colorHeight, colorWidth, CV_8UC4, &colorBuffer[0] );
+}
+
+// Draw Body
+inline void Kinect::drawBody()
+{
+ // Draw Body Data to Color Data
+ Concurrency::parallel_for( 0, BODY_COUNT, [&]( const int count ){
+ const ComPtr body = bodies[count];
+ if( body == nullptr ){
+ return;
+ }
+
+ // Check Body Tracked
+ BOOLEAN tracked = FALSE;
+ ERROR_CHECK( body->get_IsTracked( &tracked ) );
+ if( !tracked ){
+ return;
+ }
+
+ // Retrieve Joints
+ std::array joints;
+ ERROR_CHECK( body->GetJoints( static_cast( joints.size() ), &joints[0] ) );
+
+ Concurrency::parallel_for_each( joints.begin(), joints.end(), [&]( const Joint& joint ){
+ // Check Joint Tracked
+ if( joint.TrackingState == TrackingState::TrackingState_NotTracked ){
+ return;
+ }
+
+ // Draw Joint Position
+ drawEllipse( colorMat, joint, 5, colors[count] );
+
+ // Draw Left Hand State
+ if( joint.JointType == JointType::JointType_HandLeft ){
+ HandState handState;
+ TrackingConfidence handConfidence;
+ ERROR_CHECK( body->get_HandLeftState( &handState ) );
+ ERROR_CHECK( body->get_HandLeftConfidence( &handConfidence ) );
+
+ drawHandState( colorMat, joint, handState, handConfidence );
+ }
+
+ // Draw Right Hand State
+ if( joint.JointType == JointType::JointType_HandRight ){
+ HandState handState;
+ TrackingConfidence handConfidence;
+ ERROR_CHECK( body->get_HandRightState( &handState ) );
+ ERROR_CHECK( body->get_HandRightConfidence( &handConfidence ) );
+
+ drawHandState( colorMat, joint, handState, handConfidence );
+ }
+ } );
+
+ /*
+ // Retrieve Joint Orientations
+ std::array orientations;
+ ERROR_CHECK( body->GetJointOrientations( JointType::JointType_Count, &orientations[0] ) );
+ */
+
+ /*
+ // Retrieve Amount of Body Lean
+ PointF amount;
+ ERROR_CHECK( body->get_Lean( &amount ) );
+ */
+ } );
+}
+
+// Draw Ellipse
+inline void Kinect::drawEllipse( cv::Mat& image, const Joint& joint, const int radius, const cv::Vec3b& color, const int thickness )
+{
+ if( image.empty() ){
+ return;
+ }
+
+ // Convert Coordinate System and Draw Joint
+ ColorSpacePoint colorSpacePoint;
+ ERROR_CHECK( coordinateMapper->MapCameraPointToColorSpace( joint.Position, &colorSpacePoint ) );
+ const int x = static_cast( colorSpacePoint.X + 0.5f );
+ const int y = static_cast( colorSpacePoint.Y + 0.5f );
+ if( ( 0 <= x ) && ( x < image.cols ) && ( 0 <= y ) && ( y < image.rows ) ){
+ cv::circle( image, cv::Point( x, y ), radius, static_cast( color ), thickness, cv::LINE_AA );
+ }
+}
+
+// Draw Hand State
+inline void Kinect::drawHandState( cv::Mat& image, const Joint& joint, HandState handState, TrackingConfidence handConfidence )
+{
+ if( image.empty() ){
+ return;
+ }
+
+ // Check Tracking Confidence
+ if( handConfidence != TrackingConfidence::TrackingConfidence_High ){
+ return;
+ }
+
+ // Draw Hand State
+ const int radius = 75;
+ const cv::Vec3b blue = cv::Vec3b( 128, 0, 0 ), green = cv::Vec3b( 0, 128, 0 ), red = cv::Vec3b( 0, 0, 128 );
+ switch( handState ){
+ // Open
+ case HandState::HandState_Open:
+ drawEllipse( image, joint, radius, green, 5 );
+ break;
+ // Close
+ case HandState::HandState_Closed:
+ drawEllipse( image, joint, radius, red, 5 );
+ break;
+ // Lasso
+ case HandState::HandState_Lasso:
+ drawEllipse( image, joint, radius, blue, 5 );
+ break;
+ default:
+ break;
+ }
+}
+
+// Show Data
+void Kinect::show()
+{
+ // Show Body
+ showBody();
+}
+
+// Show Body
+inline void Kinect::showBody()
+{
+ if( colorMat.empty() ){
+ return;
+ }
+
+ // Resize Image
+ cv::Mat resizeMat;
+ const double scale = 0.5;
+ cv::resize( colorMat, resizeMat, cv::Size(), scale, scale );
+
+ // Show Image
+ cv::imshow( "Body", resizeMat );
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Body/app.h b/Kinect2Sample-master/sample/Body/app.h
new file mode 100644
index 0000000..f659522
--- /dev/null
+++ b/Kinect2Sample-master/sample/Body/app.h
@@ -0,0 +1,95 @@
+#ifndef __APP__
+#define __APP__
+
+#include
+#include
+#include
+
+#include
+#include
+
+#include
+using namespace Microsoft::WRL;
+
+class Kinect
+{
+private:
+ // Sensor
+ ComPtr kinect;
+
+ // Coordinate Mapper
+ ComPtr coordinateMapper;
+
+ // Reader
+ ComPtr colorFrameReader;
+ ComPtr bodyFrameReader;
+
+ // Color Buffer
+ std::vector colorBuffer;
+ int colorWidth;
+ int colorHeight;
+ unsigned int colorBytesPerPixel;
+ cv::Mat colorMat;
+
+ // Body Buffer
+ std::array bodies = { nullptr };
+ std::array colors;
+
+public:
+ // Constructor
+ Kinect();
+
+ // Destructor
+ ~Kinect();
+
+ // Processing
+ void run();
+
+private:
+ // Initialize
+ void initialize();
+
+ // Initialize Sensor
+ inline void initializeSensor();
+
+ // Initialize Color
+ inline void initializeColor();
+
+ // Initialize Body
+ inline void initializeBody();
+
+ // Finalize
+ void finalize();
+
+ // Update Data
+ void update();
+
+ // Update Color
+ inline void updateColor();
+
+ // Update Body
+ inline void updateBody();
+
+ // Draw Data
+ void draw();
+
+ // Draw Color
+ inline void drawColor();
+
+ // Draw Body
+ inline void drawBody();
+
+ // Draw Circle
+ inline void drawEllipse( cv::Mat& image, const Joint& joint, const int radius, const cv::Vec3b& color, const int thickness = -1 );
+
+ // Draw Hand State
+ inline void drawHandState( cv::Mat& image, const Joint& joint, HandState handState, TrackingConfidence handConfidence );
+
+ // Show Data
+ void show();
+
+ // Show Body
+ inline void showBody();
+};
+
+#endif // __APP__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Body/main.cpp b/Kinect2Sample-master/sample/Body/main.cpp
new file mode 100644
index 0000000..d88643c
--- /dev/null
+++ b/Kinect2Sample-master/sample/Body/main.cpp
@@ -0,0 +1,16 @@
+#include
+#include
+
+#include "app.h"
+
+int main( int argc, char* argv[] )
+{
+ try{
+ Kinect kinect;
+ kinect.run();
+ } catch( std::exception& ex ){
+ std::cout << ex.what() << std::endl;
+ }
+
+ return 0;
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Body/util.h b/Kinect2Sample-master/sample/Body/util.h
new file mode 100644
index 0000000..0d9787f
--- /dev/null
+++ b/Kinect2Sample-master/sample/Body/util.h
@@ -0,0 +1,37 @@
+#ifndef __UTIL__
+#define __UTIL__
+
+#include
+#include
+
+// Error Check Macro
+#define ERROR_CHECK( ret ) \
+ if( FAILED( ret ) ){ \
+ std::stringstream ss; \
+ ss << "failed " #ret " " << std::hex << ret << std::endl; \
+ throw std::runtime_error( ss.str().c_str() ); \
+ }
+
+// Safe Release
+template
+inline void SafeRelease( T*& rel )
+{
+ if( rel != NULL ){
+ rel->Release();
+ rel = NULL;
+ }
+}
+
+// C++ Style Line Types For OpenCV 2.x
+#if ( CV_MAJOR_VERSION < 3 )
+namespace cv{
+ enum LineTypes{
+ FILLED = -1,
+ LINE_4 = 4,
+ LINE_8 = 8,
+ LINE_AA = 16
+ };
+}
+#endif
+
+#endif // __UTIL__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/BodyIndex/CMakeLists.txt b/Kinect2Sample-master/sample/BodyIndex/CMakeLists.txt
new file mode 100644
index 0000000..89ffd22
--- /dev/null
+++ b/Kinect2Sample-master/sample/BodyIndex/CMakeLists.txt
@@ -0,0 +1,43 @@
+cmake_minimum_required( VERSION 3.6 )
+
+# Create Project
+project( Sample )
+add_executable( BodyIndex app.h app.cpp main.cpp util.h )
+
+# Set StartUp Project
+set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "BodyIndex" )
+
+# Find Package
+set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} )
+find_package( KinectSDK2 REQUIRED )
+
+set( OpenCV_DIR "C:/Program Files/opencv/build" )
+option( OpenCV_STATIC OFF )
+find_package( OpenCV REQUIRED )
+
+# Set Static Link Runtime Library
+if( OpenCV_STATIC )
+ foreach( flag_var
+ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO )
+ if( ${flag_var} MATCHES "/MD" )
+ string( REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}" )
+ endif()
+ endforeach()
+endif()
+
+if( KinectSDK2_FOUND AND OpenCV_FOUND )
+ # Additional Include Directories
+ include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+ include_directories( ${OpenCV_INCLUDE_DIRS} )
+
+ # Additional Library Directories
+ link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+ link_directories( ${OpenCV_LIB_DIR} )
+
+ # Additional Dependencies
+ target_link_libraries( BodyIndex ${KinectSDK2_LIBRARIES} )
+ target_link_libraries( BodyIndex ${OpenCV_LIBS} )
+endif()
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/BodyIndex/FindKinectSDK2.cmake b/Kinect2Sample-master/sample/BodyIndex/FindKinectSDK2.cmake
new file mode 100644
index 0000000..00a2036
--- /dev/null
+++ b/Kinect2Sample-master/sample/BodyIndex/FindKinectSDK2.cmake
@@ -0,0 +1,182 @@
+#.rst:
+# FindKinectSDK2
+# --------------
+#
+# Find Kinect for Windows SDK v2 (Kinect SDK v2) include dirs, library dirs, libraries and post-build commands
+#
+# Use this module by invoking find_package with the form::
+#
+# find_package( KinectSDK2 [REQUIRED] )
+#
+# Results for users are reported in following variables::
+#
+# KinectSDK2_FOUND - Return "TRUE" when Kinect SDK v2 found. Otherwise, Return "FALSE".
+# KinectSDK2_INCLUDE_DIRS - Kinect SDK v2 include directories. (${KinectSDK2_DIR}/inc)
+# KinectSDK2_LIBRARY_DIRS - Kinect SDK v2 library directories. (${KinectSDK2_DIR}/Lib/x86 or ${KinectSDK2_DIR}/Lib/x64)
+# KinectSDK2_LIBRARIES - Kinect SDK v2 library files. (${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib (If check the box of any application festures, corresponding library will be added.))
+# KinectSDK2_COMMANDS - Copy commands of redist files for application functions of Kinect SDK v2. (If uncheck the box of all application features, this variable has defined empty command.)
+#
+# This module reads hints about search locations from following environment variables::
+#
+# KINECTSDK20_DIR - Kinect SDK v2 root directory. (This environment variable has been set by installer of Kinect SDK v2.)
+#
+# CMake entries::
+#
+# KinectSDK2_DIR - Kinect SDK v2 root directory. (Default $ENV{KINECTSDK20_DIR})
+# KinectSDK2_FACE - Check the box when using Face or HDFace features. (Default uncheck)
+# KinectSDK2_FUSION - Check the box when using Fusion features. (Default uncheck)
+# KinectSDK2_VGB - Check the box when using Visual Gesture Builder features. (Default uncheck)
+#
+# Example to find Kinect SDK v2::
+#
+# cmake_minimum_required( VERSION 2.8 )
+#
+# project( project )
+# add_executable( project main.cpp )
+#
+# # Find package using this module.
+# find_package( KinectSDK2 REQUIRED )
+#
+# if(KinectSDK2_FOUND)
+# # [C/C++]>[General]>[Additional Include Directories]
+# include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+#
+# # [Linker]>[General]>[Additional Library Directories]
+# link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+#
+# # [Linker]>[Input]>[Additional Dependencies]
+# target_link_libraries( project ${KinectSDK2_LIBRARIES} )
+#
+# # [Build Events]>[Post-Build Event]>[Command Line]
+# add_custom_command( TARGET project POST_BUILD ${KinectSDK2_COMMANDS} )
+# endif()
+#
+# =============================================================================
+#
+# Copyright (c) 2016 Tsukasa SUGIURA
+# Distributed under the MIT License.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# =============================================================================
+
+##### Utility #####
+
+# Check Directory Macro
+macro(CHECK_DIR _DIR)
+ if(NOT EXISTS "${${_DIR}}")
+ message(WARNING "Directory \"${${_DIR}}\" not found.")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_DIR)
+ endif()
+endmacro()
+
+# Check Files Macro
+macro(CHECK_FILES _FILES _DIR)
+ set(_MISSING_FILES)
+ foreach(_FILE ${${_FILES}})
+ if(NOT EXISTS "${_FILE}")
+ get_filename_component(_FILE ${_FILE} NAME)
+ set(_MISSING_FILES "${_MISSING_FILES}${_FILE}, ")
+ endif()
+ endforeach()
+ if(_MISSING_FILES)
+ message(WARNING "In directory \"${${_DIR}}\" not found files: ${_MISSING_FILES}")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_FILES)
+ endif()
+endmacro()
+
+# Target Platform
+set(TARGET_PLATFORM)
+if(NOT CMAKE_CL_64)
+ set(TARGET_PLATFORM x86)
+else()
+ set(TARGET_PLATFORM x64)
+endif()
+
+##### Find Kinect SDK v2 #####
+
+# Found
+set(KinectSDK2_FOUND TRUE)
+if(MSVC_VERSION LESS 1700)
+ message(WARNING "Kinect for Windows SDK v2 supported Visual Studio 2012 or later.")
+ set(KinectSDK2_FOUND FALSE)
+endif()
+
+# Options
+option(KinectSDK2_FACE "Face and HDFace features" FALSE)
+option(KinectSDK2_FUSION "Fusion features" FALSE)
+option(KinectSDK2_VGB "Visual Gesture Builder features" FALSE)
+
+# Root Directoty
+set(KinectSDK2_DIR)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_DIR $ENV{KINECTSDK20_DIR} CACHE PATH "Kinect for Windows SDK v2 Install Path." FORCE)
+ check_dir(KinectSDK2_DIR)
+endif()
+
+# Include Directories
+set(KinectSDK2_INCLUDE_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_INCLUDE_DIRS ${KinectSDK2_DIR}/inc)
+ check_dir(KinectSDK2_INCLUDE_DIRS)
+endif()
+
+# Library Directories
+set(KinectSDK2_LIBRARY_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARY_DIRS ${KinectSDK2_DIR}/Lib/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Dependencies
+set(KinectSDK2_LIBRARIES)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib)
+
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Face.lib)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Fusion.lib)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.VisualGestureBuilder.lib)
+ endif()
+
+ check_files(KinectSDK2_LIBRARIES KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Custom Commands
+set(KinectSDK2_COMMANDS)
+if(KinectSDK2_FOUND)
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Face/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Fusion/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/VGB/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ # Empty Commands
+ if(NOT KinectSDK2_COMMANDS)
+ set(KinectSDK2_COMMANDS COMMAND)
+ endif()
+endif()
+
+message(STATUS "KinectSDK2_FOUND : ${KinectSDK2_FOUND}")
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/BodyIndex/app.cpp b/Kinect2Sample-master/sample/BodyIndex/app.cpp
new file mode 100644
index 0000000..41b81cd
--- /dev/null
+++ b/Kinect2Sample-master/sample/BodyIndex/app.cpp
@@ -0,0 +1,165 @@
+#include "app.h"
+#include "util.h"
+
+#include
+#include
+
+// Constructor
+Kinect::Kinect()
+{
+ // Initialize
+ initialize();
+}
+
+// Destructor
+Kinect::~Kinect()
+{
+ // Finalize
+ finalize();
+}
+
+// Processing
+void Kinect::run()
+{
+ // Main Loop
+ while( true ){
+ // Update Data
+ update();
+
+ // Draw Data
+ draw();
+
+ // Show Data
+ show();
+
+ // Key Check
+ const int key = cv::waitKey( 10 );
+ if( key == VK_ESCAPE ){
+ break;
+ }
+ }
+}
+
+// Initialize
+void Kinect::initialize()
+{
+ cv::setUseOptimized( true );
+
+ // Initialize Sensor
+ initializeSensor();
+
+ // Initialize BodyIndex
+ initializeBodyIndex();
+
+ // Wait a Few Seconds until begins to Retrieve Data from Sensor ( about 2000-[ms] )
+ std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
+}
+
+// Initialize Sensor
+inline void Kinect::initializeSensor()
+{
+ // Open Sensor
+ ERROR_CHECK( GetDefaultKinectSensor( &kinect ) );
+
+ ERROR_CHECK( kinect->Open() );
+
+ // Check Open
+ BOOLEAN isOpen = FALSE;
+ ERROR_CHECK( kinect->get_IsOpen( &isOpen ) );
+ if( !isOpen ){
+ throw std::runtime_error( "failed IKinectSensor::get_IsOpen( &isOpen )" );
+ }
+}
+
+// Initialize BodyIndex
+inline void Kinect::initializeBodyIndex()
+{
+ // Open BodyIndex Reader
+ ComPtr bodyIndexFrameSource;
+ ERROR_CHECK( kinect->get_BodyIndexFrameSource( &bodyIndexFrameSource ) );
+ ERROR_CHECK( bodyIndexFrameSource->OpenReader( &bodyIndexFrameReader ) );
+
+ // Retrieve BodyIndex Description
+ ComPtr bodyIndexFrameDescription;
+ ERROR_CHECK( bodyIndexFrameSource->get_FrameDescription( &bodyIndexFrameDescription ) );
+ ERROR_CHECK( bodyIndexFrameDescription->get_Width( &bodyIndexWidth ) ); // 512
+ ERROR_CHECK( bodyIndexFrameDescription->get_Height( &bodyIndexHeight ) ); // 424
+ ERROR_CHECK( bodyIndexFrameDescription->get_BytesPerPixel( &bodyIndexBytesPerPixel ) ); // 1
+
+ // Allocation BodyIndex Buffer
+ bodyIndexBuffer.resize( bodyIndexWidth * bodyIndexHeight );
+
+ // Color Table for Visualization
+ colors[0] = cv::Vec3b( 255, 0, 0 ); // Blue
+ colors[1] = cv::Vec3b( 0, 255, 0 ); // Green
+ colors[2] = cv::Vec3b( 0, 0, 255 ); // Red
+ colors[3] = cv::Vec3b( 255, 255, 0 ); // Cyan
+ colors[4] = cv::Vec3b( 255, 0, 255 ); // Magenta
+ colors[5] = cv::Vec3b( 0, 255, 255 ); // Yellow
+}
+
+// Finalize
+void Kinect::finalize()
+{
+ cv::destroyAllWindows();
+
+ // Close Sensor
+ if( kinect != nullptr ){
+ kinect->Close();
+ }
+}
+
+// Update Data
+void Kinect::update()
+{
+ // Update BodyIndex
+ updateBodyIndex();
+}
+
+// Update BodyIndex
+inline void Kinect::updateBodyIndex()
+{
+ // Retrieve BodyIndex Frame
+ ComPtr bodyIndexFrame;
+ const HRESULT ret = bodyIndexFrameReader->AcquireLatestFrame( &bodyIndexFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Retrieve BodyIndex Data
+ ERROR_CHECK( bodyIndexFrame->CopyFrameDataToArray( static_cast( bodyIndexBuffer.size() ), &bodyIndexBuffer[0] ) );
+}
+
+// Draw Data
+void Kinect::draw()
+{
+ // Draw BodyIndex
+ drawBodyIndex();
+}
+
+// Draw BodyIndex
+inline void Kinect::drawBodyIndex()
+{
+ // Visualization Color to Each Index
+ bodyIndexMat = cv::Mat::zeros( bodyIndexHeight, bodyIndexWidth, CV_8UC3 );
+ bodyIndexMat.forEach( [&]( cv::Vec3b &p, const int* position ){
+ uchar index = bodyIndexBuffer[position[0] * bodyIndexWidth + position[1]];
+ if( index != 0xff ){
+ p = colors[index];
+ }
+ } );
+}
+
+// Show Data
+void Kinect::show()
+{
+ // Show BodyIndex
+ showBodyIndex();
+}
+
+// Show BodyIndex
+inline void Kinect::showBodyIndex()
+{
+ // Show Image
+ cv::imshow( "BodyIndex", bodyIndexMat );
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/BodyIndex/app.h b/Kinect2Sample-master/sample/BodyIndex/app.h
new file mode 100644
index 0000000..5a5bf2d
--- /dev/null
+++ b/Kinect2Sample-master/sample/BodyIndex/app.h
@@ -0,0 +1,74 @@
+#ifndef __APP__
+#define __APP__
+
+#include
+#include
+#include
+
+#include
+
+#include
+using namespace Microsoft::WRL;
+
+#include
+
+class Kinect
+{
+private:
+ // Sensor
+ ComPtr kinect;
+
+ // Reader
+ ComPtr bodyIndexFrameReader;
+
+ // BodyIndex Buffer
+ std::vector bodyIndexBuffer;
+ int bodyIndexWidth;
+ int bodyIndexHeight;
+ unsigned int bodyIndexBytesPerPixel;
+ cv::Mat bodyIndexMat;
+ std::array colors;
+
+public:
+ // Constructor
+ Kinect();
+
+ // Destructor
+ ~Kinect();
+
+ // Processing
+ void run();
+
+private:
+ // Initialize
+ void initialize();
+
+ // Initialize Sensor
+ inline void initializeSensor();
+
+ // Initialize BodyIndex
+ inline void initializeBodyIndex();
+
+ // Finalize
+ void finalize();
+
+ // Update Data
+ void update();
+
+ // Update BodyIndex
+ inline void updateBodyIndex();
+
+ // Draw Data
+ void draw();
+
+ // Draw BodyIndex
+ inline void drawBodyIndex();
+
+ // Show Data
+ void show();
+
+ // Show BodyIndex
+ inline void showBodyIndex();
+};
+
+#endif // __APP__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/BodyIndex/main.cpp b/Kinect2Sample-master/sample/BodyIndex/main.cpp
new file mode 100644
index 0000000..d88643c
--- /dev/null
+++ b/Kinect2Sample-master/sample/BodyIndex/main.cpp
@@ -0,0 +1,16 @@
+#include
+#include
+
+#include "app.h"
+
+int main( int argc, char* argv[] )
+{
+ try{
+ Kinect kinect;
+ kinect.run();
+ } catch( std::exception& ex ){
+ std::cout << ex.what() << std::endl;
+ }
+
+ return 0;
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/BodyIndex/util.h b/Kinect2Sample-master/sample/BodyIndex/util.h
new file mode 100644
index 0000000..0d9787f
--- /dev/null
+++ b/Kinect2Sample-master/sample/BodyIndex/util.h
@@ -0,0 +1,37 @@
+#ifndef __UTIL__
+#define __UTIL__
+
+#include
+#include
+
+// Error Check Macro
+#define ERROR_CHECK( ret ) \
+ if( FAILED( ret ) ){ \
+ std::stringstream ss; \
+ ss << "failed " #ret " " << std::hex << ret << std::endl; \
+ throw std::runtime_error( ss.str().c_str() ); \
+ }
+
+// Safe Release
+template
+inline void SafeRelease( T*& rel )
+{
+ if( rel != NULL ){
+ rel->Release();
+ rel = NULL;
+ }
+}
+
+// C++ Style Line Types For OpenCV 2.x
+#if ( CV_MAJOR_VERSION < 3 )
+namespace cv{
+ enum LineTypes{
+ FILLED = -1,
+ LINE_4 = 4,
+ LINE_8 = 8,
+ LINE_AA = 16
+ };
+}
+#endif
+
+#endif // __UTIL__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/CMakeLists.txt b/Kinect2Sample-master/sample/CMakeLists.txt
new file mode 100644
index 0000000..20bd161
--- /dev/null
+++ b/Kinect2Sample-master/sample/CMakeLists.txt
@@ -0,0 +1,32 @@
+cmake_minimum_required( VERSION 3.6 )
+
+# Create Project
+project( Sample )
+
+# Set Binary Output Directory
+set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
+
+# Sample Sub-Directories Name
+set( SAMPLES Color Depth Infrared BodyIndex Body JointSmooth MultiSource CoordinateMapper Face HDFace Fusion Gesture Speech AudioBeam AudioBody ChromaKey FaceClip )
+
+# Sample Build Option
+foreach( SAMPLE ${SAMPLES} )
+ option( BUILD_${SAMPLE} "Build ${SAMPLE} Sample Project" ON )
+endforeach()
+
+# Sample Add Sub-Directories
+foreach( SAMPLE ${SAMPLES} )
+ if( BUILD_${SAMPLE} )
+ add_subdirectory( ${SAMPLE} )
+ endif()
+endforeach()
+
+# Adjust ( Copy Run-Time Files )
+if( BUILD_Speech )
+ file( COPY ${CMAKE_SOURCE_DIR}/Speech/Grammar_enUS.grxml DESTINATION ${CMAKE_BINARY_DIR}/bin )
+ file( COPY ${CMAKE_SOURCE_DIR}/Speech/Grammar_jaJP.grxml DESTINATION ${CMAKE_BINARY_DIR}/bin )
+endif()
+
+if( BUILD_Gesture )
+ file( COPY ${CMAKE_SOURCE_DIR}/Gesture/SampleDatabase.gbd DESTINATION ${CMAKE_BINARY_DIR}/bin )
+endif()
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/ChromaKey/CMakeLists.txt b/Kinect2Sample-master/sample/ChromaKey/CMakeLists.txt
new file mode 100644
index 0000000..fbbe3a0
--- /dev/null
+++ b/Kinect2Sample-master/sample/ChromaKey/CMakeLists.txt
@@ -0,0 +1,43 @@
+cmake_minimum_required( VERSION 3.6 )
+
+# Create Project
+project( Sample )
+add_executable( ChromaKey app.h app.cpp main.cpp util.h )
+
+# Set StartUp Project
+set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "ChromaKey" )
+
+# Find Package
+set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} )
+find_package( KinectSDK2 REQUIRED )
+
+set( OpenCV_DIR "C:/Program Files/opencv/build" )
+option( OpenCV_STATIC OFF )
+find_package( OpenCV REQUIRED )
+
+# Set Static Link Runtime Library
+if( OpenCV_STATIC )
+ foreach( flag_var
+ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO )
+ if( ${flag_var} MATCHES "/MD" )
+ string( REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}" )
+ endif()
+ endforeach()
+endif()
+
+if( KinectSDK2_FOUND AND OpenCV_FOUND )
+ # Additional Include Directories
+ include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+ include_directories( ${OpenCV_INCLUDE_DIRS} )
+
+ # Additional Library Directories
+ link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+ link_directories( ${OpenCV_LIB_DIR} )
+
+ # Additional Dependencies
+ target_link_libraries( ChromaKey ${KinectSDK2_LIBRARIES} )
+ target_link_libraries( ChromaKey ${OpenCV_LIBS} )
+endif()
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/ChromaKey/FindKinectSDK2.cmake b/Kinect2Sample-master/sample/ChromaKey/FindKinectSDK2.cmake
new file mode 100644
index 0000000..00a2036
--- /dev/null
+++ b/Kinect2Sample-master/sample/ChromaKey/FindKinectSDK2.cmake
@@ -0,0 +1,182 @@
+#.rst:
+# FindKinectSDK2
+# --------------
+#
+# Find Kinect for Windows SDK v2 (Kinect SDK v2) include dirs, library dirs, libraries and post-build commands
+#
+# Use this module by invoking find_package with the form::
+#
+# find_package( KinectSDK2 [REQUIRED] )
+#
+# Results for users are reported in following variables::
+#
+# KinectSDK2_FOUND - Return "TRUE" when Kinect SDK v2 found. Otherwise, Return "FALSE".
+# KinectSDK2_INCLUDE_DIRS - Kinect SDK v2 include directories. (${KinectSDK2_DIR}/inc)
+# KinectSDK2_LIBRARY_DIRS - Kinect SDK v2 library directories. (${KinectSDK2_DIR}/Lib/x86 or ${KinectSDK2_DIR}/Lib/x64)
+# KinectSDK2_LIBRARIES - Kinect SDK v2 library files. (${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib (If check the box of any application festures, corresponding library will be added.))
+# KinectSDK2_COMMANDS - Copy commands of redist files for application functions of Kinect SDK v2. (If uncheck the box of all application features, this variable has defined empty command.)
+#
+# This module reads hints about search locations from following environment variables::
+#
+# KINECTSDK20_DIR - Kinect SDK v2 root directory. (This environment variable has been set by installer of Kinect SDK v2.)
+#
+# CMake entries::
+#
+# KinectSDK2_DIR - Kinect SDK v2 root directory. (Default $ENV{KINECTSDK20_DIR})
+# KinectSDK2_FACE - Check the box when using Face or HDFace features. (Default uncheck)
+# KinectSDK2_FUSION - Check the box when using Fusion features. (Default uncheck)
+# KinectSDK2_VGB - Check the box when using Visual Gesture Builder features. (Default uncheck)
+#
+# Example to find Kinect SDK v2::
+#
+# cmake_minimum_required( VERSION 2.8 )
+#
+# project( project )
+# add_executable( project main.cpp )
+#
+# # Find package using this module.
+# find_package( KinectSDK2 REQUIRED )
+#
+# if(KinectSDK2_FOUND)
+# # [C/C++]>[General]>[Additional Include Directories]
+# include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+#
+# # [Linker]>[General]>[Additional Library Directories]
+# link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+#
+# # [Linker]>[Input]>[Additional Dependencies]
+# target_link_libraries( project ${KinectSDK2_LIBRARIES} )
+#
+# # [Build Events]>[Post-Build Event]>[Command Line]
+# add_custom_command( TARGET project POST_BUILD ${KinectSDK2_COMMANDS} )
+# endif()
+#
+# =============================================================================
+#
+# Copyright (c) 2016 Tsukasa SUGIURA
+# Distributed under the MIT License.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# =============================================================================
+
+##### Utility #####
+
+# Check Directory Macro
+macro(CHECK_DIR _DIR)
+ if(NOT EXISTS "${${_DIR}}")
+ message(WARNING "Directory \"${${_DIR}}\" not found.")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_DIR)
+ endif()
+endmacro()
+
+# Check Files Macro
+macro(CHECK_FILES _FILES _DIR)
+ set(_MISSING_FILES)
+ foreach(_FILE ${${_FILES}})
+ if(NOT EXISTS "${_FILE}")
+ get_filename_component(_FILE ${_FILE} NAME)
+ set(_MISSING_FILES "${_MISSING_FILES}${_FILE}, ")
+ endif()
+ endforeach()
+ if(_MISSING_FILES)
+ message(WARNING "In directory \"${${_DIR}}\" not found files: ${_MISSING_FILES}")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_FILES)
+ endif()
+endmacro()
+
+# Target Platform
+set(TARGET_PLATFORM)
+if(NOT CMAKE_CL_64)
+ set(TARGET_PLATFORM x86)
+else()
+ set(TARGET_PLATFORM x64)
+endif()
+
+##### Find Kinect SDK v2 #####
+
+# Found
+set(KinectSDK2_FOUND TRUE)
+if(MSVC_VERSION LESS 1700)
+ message(WARNING "Kinect for Windows SDK v2 supported Visual Studio 2012 or later.")
+ set(KinectSDK2_FOUND FALSE)
+endif()
+
+# Options
+option(KinectSDK2_FACE "Face and HDFace features" FALSE)
+option(KinectSDK2_FUSION "Fusion features" FALSE)
+option(KinectSDK2_VGB "Visual Gesture Builder features" FALSE)
+
+# Root Directoty
+set(KinectSDK2_DIR)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_DIR $ENV{KINECTSDK20_DIR} CACHE PATH "Kinect for Windows SDK v2 Install Path." FORCE)
+ check_dir(KinectSDK2_DIR)
+endif()
+
+# Include Directories
+set(KinectSDK2_INCLUDE_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_INCLUDE_DIRS ${KinectSDK2_DIR}/inc)
+ check_dir(KinectSDK2_INCLUDE_DIRS)
+endif()
+
+# Library Directories
+set(KinectSDK2_LIBRARY_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARY_DIRS ${KinectSDK2_DIR}/Lib/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Dependencies
+set(KinectSDK2_LIBRARIES)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib)
+
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Face.lib)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Fusion.lib)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.VisualGestureBuilder.lib)
+ endif()
+
+ check_files(KinectSDK2_LIBRARIES KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Custom Commands
+set(KinectSDK2_COMMANDS)
+if(KinectSDK2_FOUND)
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Face/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Fusion/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/VGB/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ # Empty Commands
+ if(NOT KinectSDK2_COMMANDS)
+ set(KinectSDK2_COMMANDS COMMAND)
+ endif()
+endif()
+
+message(STATUS "KinectSDK2_FOUND : ${KinectSDK2_FOUND}")
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/ChromaKey/app.cpp b/Kinect2Sample-master/sample/ChromaKey/app.cpp
new file mode 100644
index 0000000..fadd399
--- /dev/null
+++ b/Kinect2Sample-master/sample/ChromaKey/app.cpp
@@ -0,0 +1,351 @@
+#include "app.h"
+#include "util.h"
+
+#include
+#include
+
+#include
+
+// Choose Resolution
+#define COLOR
+//#define DEPTH
+
+// Constructor
+Kinect::Kinect()
+{
+ // Initialize
+ initialize();
+}
+
+// Destructor
+Kinect::~Kinect()
+{
+ // Finalize
+ finalize();
+}
+
+// Processing
+void Kinect::run()
+{
+ // Main Loop
+ while( true ){
+ // Update Data
+ update();
+
+ // Draw Data
+ draw();
+
+ // Show Data
+ show();
+
+ // Key Check
+ const int key = cv::waitKey( 10 );
+ if( key == VK_ESCAPE ){
+ break;
+ }
+ }
+}
+
+// Initialize
+void Kinect::initialize()
+{
+ cv::setUseOptimized( true );
+
+ // Initialize Sensor
+ initializeSensor();
+
+ // Initialize Color
+ initializeColor();
+
+ // Initialize Depth
+ initializeDepth();
+
+ // Initialize BodyIndex
+ initializeBodyIndex();
+
+ // Wait a Few Seconds until begins to Retrieve Data from Sensor ( about 2000-[ms] )
+ std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
+}
+
+// Initialize Sensor
+inline void Kinect::initializeSensor()
+{
+ // Open Sensor
+ ERROR_CHECK( GetDefaultKinectSensor( &kinect ) );
+
+ ERROR_CHECK( kinect->Open() );
+
+ // Check Open
+ BOOLEAN isOpen = FALSE;
+ ERROR_CHECK( kinect->get_IsOpen( &isOpen ) );
+ if( !isOpen ){
+ throw std::runtime_error( "failed IKinectSensor::get_IsOpen( &isOpen )" );
+ }
+
+ // Retrieve Coordinate Mapper
+ ERROR_CHECK( kinect->get_CoordinateMapper( &coordinateMapper ) );
+}
+
+// Initialize Color
+inline void Kinect::initializeColor()
+{
+ // Open Color Reader
+ ComPtr colorFrameSource;
+ ERROR_CHECK( kinect->get_ColorFrameSource( &colorFrameSource ) );
+ ERROR_CHECK( colorFrameSource->OpenReader( &colorFrameReader ) );
+
+ // Retrieve Color Description
+ ComPtr colorFrameDescription;
+ ERROR_CHECK( colorFrameSource->CreateFrameDescription( ColorImageFormat::ColorImageFormat_Bgra, &colorFrameDescription ) );
+ ERROR_CHECK( colorFrameDescription->get_Width( &colorWidth ) ); // 1920
+ ERROR_CHECK( colorFrameDescription->get_Height( &colorHeight ) ); // 1080
+ ERROR_CHECK( colorFrameDescription->get_BytesPerPixel( &colorBytesPerPixel ) ); // 4
+
+ // Allocation Color Buffer
+ colorBuffer.resize( colorWidth * colorHeight * colorBytesPerPixel );
+}
+
+// Initialize Depth
+inline void Kinect::initializeDepth()
+{
+ // Open Depth Reader
+ ComPtr depthFrameSource;
+ ERROR_CHECK( kinect->get_DepthFrameSource( &depthFrameSource ) );
+ ERROR_CHECK( depthFrameSource->OpenReader( &depthFrameReader ) );
+
+ // Retrieve Depth Description
+ ComPtr depthFrameDescription;
+ ERROR_CHECK( depthFrameSource->get_FrameDescription( &depthFrameDescription ) );
+ ERROR_CHECK( depthFrameDescription->get_Width( &depthWidth ) ); // 512
+ ERROR_CHECK( depthFrameDescription->get_Height( &depthHeight ) ); // 424
+ ERROR_CHECK( depthFrameDescription->get_BytesPerPixel( &depthBytesPerPixel ) ); // 2
+
+ // Allocation Depth Buffer
+ depthBuffer.resize( depthWidth * depthHeight );
+}
+
+// Initialize BodyIndex
+inline void Kinect::initializeBodyIndex()
+{
+ // Open BodyIndex Reader
+ ComPtr bodyIndexFrameSource;
+ ERROR_CHECK( kinect->get_BodyIndexFrameSource( &bodyIndexFrameSource ) );
+ ERROR_CHECK( bodyIndexFrameSource->OpenReader( &bodyIndexFrameReader ) );
+
+ // Retrieve BodyIndex Description
+ ComPtr bodyIndexFrameDescription;
+ ERROR_CHECK( bodyIndexFrameSource->get_FrameDescription( &bodyIndexFrameDescription ) );
+ ERROR_CHECK( bodyIndexFrameDescription->get_Width( &bodyIndexWidth ) ); // 512
+ ERROR_CHECK( bodyIndexFrameDescription->get_Height( &bodyIndexHeight ) ); // 424
+ ERROR_CHECK( bodyIndexFrameDescription->get_BytesPerPixel( &bodyIndexBytesPerPixel ) ); // 1
+
+ // Allocation BodyIndex Buffer
+ bodyIndexBuffer.resize( bodyIndexWidth * bodyIndexHeight );
+}
+
+// Finalize
+void Kinect::finalize()
+{
+ cv::destroyAllWindows();
+
+ // Close Sensor
+ if( kinect != nullptr ){
+ kinect->Close();
+ }
+}
+
+// Update Data
+void Kinect::update()
+{
+ // Update Color
+ updateColor();
+
+ // Update Depth
+ updateDepth();
+
+ // Update BodyIndex
+ updateBodyIndex();
+}
+
+// Update Color
+inline void Kinect::updateColor()
+{
+ // Retrieve Color Frame
+ ComPtr colorFrame;
+ const HRESULT ret = colorFrameReader->AcquireLatestFrame( &colorFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Convert Format ( YUY2 -> BGRA )
+ ERROR_CHECK( colorFrame->CopyConvertedFrameDataToArray( static_cast( colorBuffer.size() ), &colorBuffer[0], ColorImageFormat::ColorImageFormat_Bgra ) );
+}
+
+// Update Depth
+inline void Kinect::updateDepth()
+{
+ // Retrieve Depth Frame
+ ComPtr depthFrame;
+ const HRESULT ret = depthFrameReader->AcquireLatestFrame( &depthFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Retrieve Depth Data
+ ERROR_CHECK( depthFrame->CopyFrameDataToArray( static_cast( depthBuffer.size() ), &depthBuffer[0] ) );
+}
+
+// Update BodyIndex
+inline void Kinect::updateBodyIndex()
+{
+ // Retrieve BodyIndex Frame
+ ComPtr bodyIndexFrame;
+ const HRESULT ret = bodyIndexFrameReader->AcquireLatestFrame( &bodyIndexFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Retrieve BodyIndex Data
+ ERROR_CHECK( bodyIndexFrame->CopyFrameDataToArray( static_cast( bodyIndexBuffer.size() ), &bodyIndexBuffer[0] ) );
+}
+
+// Draw Data
+void Kinect::draw()
+{
+ // Draw Color
+ drawColor();
+
+ // Draw BodyIndex
+ drawBodyIndex();
+
+ // Draw ChromaKey
+ drawChromaKey();
+}
+
+// Draw Color
+inline void Kinect::drawColor()
+{
+#ifdef COLOR
+ // Create cv::Mat from Color Buffer
+ colorMat = cv::Mat( colorHeight, colorWidth, CV_8UC4, &colorBuffer[0] );
+#endif
+
+#ifdef DEPTH
+ // Retrieve Mapped Coordinates
+ std::vector colorSpacePoints( depthWidth * depthHeight );
+ ERROR_CHECK( coordinateMapper->MapDepthFrameToColorSpace( depthBuffer.size(), &depthBuffer[0], colorSpacePoints.size(), &colorSpacePoints[0] ) );
+
+ // Mapping Color to Depth Resolution
+ std::vector buffer( depthWidth * depthHeight * colorBytesPerPixel );
+
+ Concurrency::parallel_for( 0, depthHeight, [&]( const int depthY ){
+ const unsigned int depthOffset = depthY * depthWidth;
+ for( int depthX = 0; depthX < depthWidth; depthX++ ){
+ unsigned int depthIndex = depthOffset + depthX;
+ const int colorX = static_cast( colorSpacePoints[depthIndex].X + 0.5f );
+ const int colorY = static_cast( colorSpacePoints[depthIndex].Y + 0.5f );
+ if( ( 0 <= colorX ) && ( colorX < colorWidth ) && ( 0 <= colorY ) && ( colorY < colorHeight ) ){
+ const unsigned int colorIndex = ( colorY * colorWidth + colorX ) * colorBytesPerPixel;
+ depthIndex = depthIndex * colorBytesPerPixel;
+ buffer[depthIndex + 0] = colorBuffer[colorIndex + 0];
+ buffer[depthIndex + 1] = colorBuffer[colorIndex + 1];
+ buffer[depthIndex + 2] = colorBuffer[colorIndex + 2];
+ buffer[depthIndex + 3] = colorBuffer[colorIndex + 3];
+ }
+ }
+ } );
+
+ // Create cv::Mat from Coordinate Buffer
+ colorMat = cv::Mat( depthHeight, depthWidth, CV_8UC4, &buffer[0] ).clone();
+#endif
+}
+
+// Draw BodyIndex
+inline void Kinect::drawBodyIndex()
+{
+#ifdef COLOR
+ // Retrieve Mapped Coordinates
+ std::vector bodyIndexSpacePoints( colorWidth * colorHeight );
+ ERROR_CHECK( coordinateMapper->MapColorFrameToDepthSpace( depthBuffer.size(), &depthBuffer[0], bodyIndexSpacePoints.size(), &bodyIndexSpacePoints[0] ) );
+
+ // Mapping BodyIndex to Color Resolution
+ std::vector buffer( colorWidth * colorHeight, 0xff );
+
+ Concurrency::parallel_for( 0, colorHeight, [&]( const int colorY ){
+ const unsigned int colorOffset = colorY * colorWidth;
+ for( int colorX = 0; colorX < colorWidth; colorX++ ){
+ const unsigned int colorIndex = colorOffset + colorX;
+ const int bodyIndexX = static_cast( bodyIndexSpacePoints[colorIndex].X + 0.5f );
+ const int bodyIndexY = static_cast( bodyIndexSpacePoints[colorIndex].Y + 0.5f );
+ if( ( 0 <= bodyIndexX ) && ( bodyIndexX < bodyIndexWidth ) && ( 0 <= bodyIndexY ) && ( bodyIndexY < bodyIndexHeight ) ){
+ const unsigned char bodyIndex = bodyIndexBuffer[bodyIndexY * bodyIndexWidth + bodyIndexX];
+ buffer[colorIndex] = bodyIndex;
+ }
+ }
+ } );
+
+ // Create cv::Mat from Coordinate Buffer
+ bodyIndexMat = cv::Mat( colorHeight, colorWidth, CV_8UC1, &buffer[0] ).clone();
+#endif
+
+#ifdef DEPTH
+ // Create cv::Mat from BodyIndex Buffer
+ bodyIndexMat = cv::Mat( bodyIndexHeight, bodyIndexWidth, CV_8UC1, &bodyIndexBuffer[0] );
+#endif
+}
+
+// Draw ChromaKey
+inline void Kinect::drawChromaKey()
+{
+ if( colorMat.empty() ){
+ return;
+ }
+
+ if( bodyIndexMat.empty() ){
+ return;
+ }
+
+ // ChromaKey
+#ifdef COLOR
+ chromaKeyMat = cv::Mat::zeros( colorHeight, colorWidth, CV_8UC4 );
+#endif
+#ifdef DEPTH
+ chromaKeyMat = cv::Mat::zeros( depthHeight, depthWidth, CV_8UC4 );
+#endif
+ chromaKeyMat.forEach( [&]( cv::Vec4b &p, const int* position ){
+ uchar bodyIndex = bodyIndexMat.at( position[0], position[1] );
+ if( bodyIndex != 0xff ){
+ p = colorMat.at( position[0], position[1] );
+ }
+ } );
+}
+
+// Show Data
+void Kinect::show()
+{
+ // Show ChromaKey
+ showChromaKey();
+}
+
+// Show ChromaKey
+inline void Kinect::showChromaKey()
+{
+ if( chromaKeyMat.empty() ){
+ return;
+ }
+
+#ifdef COLOR
+ // Resize Image
+ cv::Mat resizeMat;
+ const double scale = 0.5;
+ cv::resize( chromaKeyMat, resizeMat, cv::Size(), scale, scale );
+
+ // Show Image
+ cv::imshow( "ChromaKey", resizeMat );
+#endif
+
+#ifdef DEPTH
+ // Show Image
+ cv::imshow( "ChromaKey", chromaKeyMat );
+#endif
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/ChromaKey/app.h b/Kinect2Sample-master/sample/ChromaKey/app.h
new file mode 100644
index 0000000..1835bd9
--- /dev/null
+++ b/Kinect2Sample-master/sample/ChromaKey/app.h
@@ -0,0 +1,110 @@
+#ifndef __APP__
+#define __APP__
+
+#include
+#include
+#include
+
+#include
+
+#include
+using namespace Microsoft::WRL;
+
+class Kinect
+{
+private:
+ // Sensor
+ ComPtr kinect;
+
+ // Coordinate Mapper
+ ComPtr coordinateMapper;
+
+ // Reader
+ ComPtr colorFrameReader;
+ ComPtr depthFrameReader;
+ ComPtr bodyIndexFrameReader;
+
+ // Color Buffer
+ std::vector colorBuffer;
+ int colorWidth;
+ int colorHeight;
+ unsigned int colorBytesPerPixel;
+ cv::Mat colorMat;
+
+ // Depth Buffer
+ std::vector depthBuffer;
+ int depthWidth;
+ int depthHeight;
+ unsigned int depthBytesPerPixel;
+
+ // BodyIndex Buffer
+ std::vector bodyIndexBuffer;
+ int bodyIndexWidth;
+ int bodyIndexHeight;
+ unsigned int bodyIndexBytesPerPixel;
+ cv::Mat bodyIndexMat;
+
+ // ChromaKey Buffer
+ cv::Mat chromaKeyMat;
+
+public:
+ // Constructor
+ Kinect();
+
+ // Destructor
+ ~Kinect();
+
+ // Processing
+ void run();
+
+private:
+ // Initialize
+ void initialize();
+
+ // Initialize Sensor
+ inline void initializeSensor();
+
+ // Initialize Color
+ inline void initializeColor();
+
+ // Initialize Depth
+ inline void initializeDepth();
+
+ // Initialize BodyIndex
+ inline void initializeBodyIndex();
+
+ // Finalize
+ void finalize();
+
+ // Update Data
+ void update();
+
+ // Update Color
+ inline void updateColor();
+
+ // Update Depth
+ inline void updateDepth();
+
+ // Update BodyIndex
+ inline void updateBodyIndex();
+
+ // Draw Data
+ void draw();
+
+ // Draw Color
+ inline void drawColor();
+
+ // Draw BodyIndex
+ inline void drawBodyIndex();
+
+ // Draw ChromaKey
+ inline void drawChromaKey();
+
+ // Show Data
+ void show();
+
+ // Show ChromaKey
+ inline void showChromaKey();
+};
+
+#endif // __APP__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/ChromaKey/main.cpp b/Kinect2Sample-master/sample/ChromaKey/main.cpp
new file mode 100644
index 0000000..d88643c
--- /dev/null
+++ b/Kinect2Sample-master/sample/ChromaKey/main.cpp
@@ -0,0 +1,16 @@
+#include
+#include
+
+#include "app.h"
+
+int main( int argc, char* argv[] )
+{
+ try{
+ Kinect kinect;
+ kinect.run();
+ } catch( std::exception& ex ){
+ std::cout << ex.what() << std::endl;
+ }
+
+ return 0;
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/ChromaKey/util.h b/Kinect2Sample-master/sample/ChromaKey/util.h
new file mode 100644
index 0000000..0d9787f
--- /dev/null
+++ b/Kinect2Sample-master/sample/ChromaKey/util.h
@@ -0,0 +1,37 @@
+#ifndef __UTIL__
+#define __UTIL__
+
+#include
+#include
+
+// Error Check Macro
+#define ERROR_CHECK( ret ) \
+ if( FAILED( ret ) ){ \
+ std::stringstream ss; \
+ ss << "failed " #ret " " << std::hex << ret << std::endl; \
+ throw std::runtime_error( ss.str().c_str() ); \
+ }
+
+// Safe Release
+template
+inline void SafeRelease( T*& rel )
+{
+ if( rel != NULL ){
+ rel->Release();
+ rel = NULL;
+ }
+}
+
+// C++ Style Line Types For OpenCV 2.x
+#if ( CV_MAJOR_VERSION < 3 )
+namespace cv{
+ enum LineTypes{
+ FILLED = -1,
+ LINE_4 = 4,
+ LINE_8 = 8,
+ LINE_AA = 16
+ };
+}
+#endif
+
+#endif // __UTIL__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Color/CMakeLists.txt b/Kinect2Sample-master/sample/Color/CMakeLists.txt
new file mode 100644
index 0000000..6230a34
--- /dev/null
+++ b/Kinect2Sample-master/sample/Color/CMakeLists.txt
@@ -0,0 +1,43 @@
+cmake_minimum_required( VERSION 3.6 )
+
+# Create Project
+project( Sample )
+add_executable( Color app.h app.cpp main.cpp util.h )
+
+# Set StartUp Project
+set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "Color" )
+
+# Find Package
+set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} )
+find_package( KinectSDK2 REQUIRED )
+
+set( OpenCV_DIR "C:/Program Files/opencv/build" )
+option( OpenCV_STATIC OFF )
+find_package( OpenCV REQUIRED )
+
+# Set Static Link Runtime Library
+if( OpenCV_STATIC )
+ foreach( flag_var
+ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO )
+ if( ${flag_var} MATCHES "/MD" )
+ string( REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}" )
+ endif()
+ endforeach()
+endif()
+
+if( KinectSDK2_FOUND AND OpenCV_FOUND )
+ # Additional Include Directories
+ include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+ include_directories( ${OpenCV_INCLUDE_DIRS} )
+
+ # Additional Library Directories
+ link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+ link_directories( ${OpenCV_LIB_DIR} )
+
+ # Additional Dependencies
+ target_link_libraries( Color ${KinectSDK2_LIBRARIES} )
+ target_link_libraries( Color ${OpenCV_LIBS} )
+endif()
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Color/FindKinectSDK2.cmake b/Kinect2Sample-master/sample/Color/FindKinectSDK2.cmake
new file mode 100644
index 0000000..00a2036
--- /dev/null
+++ b/Kinect2Sample-master/sample/Color/FindKinectSDK2.cmake
@@ -0,0 +1,182 @@
+#.rst:
+# FindKinectSDK2
+# --------------
+#
+# Find Kinect for Windows SDK v2 (Kinect SDK v2) include dirs, library dirs, libraries and post-build commands
+#
+# Use this module by invoking find_package with the form::
+#
+# find_package( KinectSDK2 [REQUIRED] )
+#
+# Results for users are reported in following variables::
+#
+# KinectSDK2_FOUND - Return "TRUE" when Kinect SDK v2 found. Otherwise, Return "FALSE".
+# KinectSDK2_INCLUDE_DIRS - Kinect SDK v2 include directories. (${KinectSDK2_DIR}/inc)
+# KinectSDK2_LIBRARY_DIRS - Kinect SDK v2 library directories. (${KinectSDK2_DIR}/Lib/x86 or ${KinectSDK2_DIR}/Lib/x64)
+# KinectSDK2_LIBRARIES - Kinect SDK v2 library files. (${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib (If check the box of any application festures, corresponding library will be added.))
+# KinectSDK2_COMMANDS - Copy commands of redist files for application functions of Kinect SDK v2. (If uncheck the box of all application features, this variable has defined empty command.)
+#
+# This module reads hints about search locations from following environment variables::
+#
+# KINECTSDK20_DIR - Kinect SDK v2 root directory. (This environment variable has been set by installer of Kinect SDK v2.)
+#
+# CMake entries::
+#
+# KinectSDK2_DIR - Kinect SDK v2 root directory. (Default $ENV{KINECTSDK20_DIR})
+# KinectSDK2_FACE - Check the box when using Face or HDFace features. (Default uncheck)
+# KinectSDK2_FUSION - Check the box when using Fusion features. (Default uncheck)
+# KinectSDK2_VGB - Check the box when using Visual Gesture Builder features. (Default uncheck)
+#
+# Example to find Kinect SDK v2::
+#
+# cmake_minimum_required( VERSION 2.8 )
+#
+# project( project )
+# add_executable( project main.cpp )
+#
+# # Find package using this module.
+# find_package( KinectSDK2 REQUIRED )
+#
+# if(KinectSDK2_FOUND)
+# # [C/C++]>[General]>[Additional Include Directories]
+# include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+#
+# # [Linker]>[General]>[Additional Library Directories]
+# link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+#
+# # [Linker]>[Input]>[Additional Dependencies]
+# target_link_libraries( project ${KinectSDK2_LIBRARIES} )
+#
+# # [Build Events]>[Post-Build Event]>[Command Line]
+# add_custom_command( TARGET project POST_BUILD ${KinectSDK2_COMMANDS} )
+# endif()
+#
+# =============================================================================
+#
+# Copyright (c) 2016 Tsukasa SUGIURA
+# Distributed under the MIT License.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# =============================================================================
+
+##### Utility #####
+
+# Check Directory Macro
+macro(CHECK_DIR _DIR)
+ if(NOT EXISTS "${${_DIR}}")
+ message(WARNING "Directory \"${${_DIR}}\" not found.")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_DIR)
+ endif()
+endmacro()
+
+# Check Files Macro
+macro(CHECK_FILES _FILES _DIR)
+ set(_MISSING_FILES)
+ foreach(_FILE ${${_FILES}})
+ if(NOT EXISTS "${_FILE}")
+ get_filename_component(_FILE ${_FILE} NAME)
+ set(_MISSING_FILES "${_MISSING_FILES}${_FILE}, ")
+ endif()
+ endforeach()
+ if(_MISSING_FILES)
+ message(WARNING "In directory \"${${_DIR}}\" not found files: ${_MISSING_FILES}")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_FILES)
+ endif()
+endmacro()
+
+# Target Platform
+set(TARGET_PLATFORM)
+if(NOT CMAKE_CL_64)
+ set(TARGET_PLATFORM x86)
+else()
+ set(TARGET_PLATFORM x64)
+endif()
+
+##### Find Kinect SDK v2 #####
+
+# Found
+set(KinectSDK2_FOUND TRUE)
+if(MSVC_VERSION LESS 1700)
+ message(WARNING "Kinect for Windows SDK v2 supported Visual Studio 2012 or later.")
+ set(KinectSDK2_FOUND FALSE)
+endif()
+
+# Options
+option(KinectSDK2_FACE "Face and HDFace features" FALSE)
+option(KinectSDK2_FUSION "Fusion features" FALSE)
+option(KinectSDK2_VGB "Visual Gesture Builder features" FALSE)
+
+# Root Directoty
+set(KinectSDK2_DIR)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_DIR $ENV{KINECTSDK20_DIR} CACHE PATH "Kinect for Windows SDK v2 Install Path." FORCE)
+ check_dir(KinectSDK2_DIR)
+endif()
+
+# Include Directories
+set(KinectSDK2_INCLUDE_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_INCLUDE_DIRS ${KinectSDK2_DIR}/inc)
+ check_dir(KinectSDK2_INCLUDE_DIRS)
+endif()
+
+# Library Directories
+set(KinectSDK2_LIBRARY_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARY_DIRS ${KinectSDK2_DIR}/Lib/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Dependencies
+set(KinectSDK2_LIBRARIES)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib)
+
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Face.lib)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Fusion.lib)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.VisualGestureBuilder.lib)
+ endif()
+
+ check_files(KinectSDK2_LIBRARIES KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Custom Commands
+set(KinectSDK2_COMMANDS)
+if(KinectSDK2_FOUND)
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Face/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Fusion/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/VGB/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ # Empty Commands
+ if(NOT KinectSDK2_COMMANDS)
+ set(KinectSDK2_COMMANDS COMMAND)
+ endif()
+endif()
+
+message(STATUS "KinectSDK2_FOUND : ${KinectSDK2_FOUND}")
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Color/app.cpp b/Kinect2Sample-master/sample/Color/app.cpp
new file mode 100644
index 0000000..6ecc9a8
--- /dev/null
+++ b/Kinect2Sample-master/sample/Color/app.cpp
@@ -0,0 +1,160 @@
+#include "app.h"
+#include "util.h"
+
+#include
+#include
+
+// Constructor
+Kinect::Kinect()
+{
+ // Initialize
+ initialize();
+}
+
+// Destructor
+Kinect::~Kinect()
+{
+ // Finalize
+ finalize();
+}
+
+// Processing
+void Kinect::run()
+{
+ // Main Loop
+ while( true ){
+ // Update Data
+ update();
+
+ // Draw Data
+ draw();
+
+ // Show Data
+ show();
+
+ // Key Check
+ const int key = cv::waitKey( 10 );
+ if( key == VK_ESCAPE ){
+ break;
+ }
+ }
+}
+
+// Initialize
+void Kinect::initialize()
+{
+ cv::setUseOptimized( true );
+
+ // Initialize Sensor
+ initializeSensor();
+
+ // Initialize Color
+ initializeColor();
+
+ // Wait a Few Seconds until begins to Retrieve Data from Sensor ( about 2000-[ms] )
+ std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
+}
+
+// Initialize Sensor
+inline void Kinect::initializeSensor()
+{
+ // Open Sensor
+ ERROR_CHECK( GetDefaultKinectSensor( &kinect ) );
+
+ ERROR_CHECK( kinect->Open() );
+
+ // Check Open
+ BOOLEAN isOpen = FALSE;
+ ERROR_CHECK( kinect->get_IsOpen( &isOpen ) );
+ if( !isOpen ){
+ throw std::runtime_error( "failed IKinectSensor::get_IsOpen( &isOpen )" );
+ }
+}
+
+// Initialize Color
+inline void Kinect::initializeColor()
+{
+ // Open Color Reader
+ ComPtr colorFrameSource;
+ ERROR_CHECK( kinect->get_ColorFrameSource( &colorFrameSource ) );
+ ERROR_CHECK( colorFrameSource->OpenReader( &colorFrameReader ) );
+
+ // Retrieve Color Description
+ ComPtr colorFrameDescription;
+ ERROR_CHECK( colorFrameSource->CreateFrameDescription( ColorImageFormat::ColorImageFormat_Bgra, &colorFrameDescription ) );
+ ERROR_CHECK( colorFrameDescription->get_Width( &colorWidth ) ); // 1920
+ ERROR_CHECK( colorFrameDescription->get_Height( &colorHeight ) ); // 1080
+ ERROR_CHECK( colorFrameDescription->get_BytesPerPixel( &colorBytesPerPixel ) ); // 4
+
+ // Allocation Color Buffer
+ colorBuffer.resize( colorWidth * colorHeight * colorBytesPerPixel );
+}
+
+// Finalize
+void Kinect::finalize()
+{
+ cv::destroyAllWindows();
+
+ // Close Sensor
+ if( kinect != nullptr ){
+ kinect->Close();
+ }
+}
+
+// Update Data
+void Kinect::update()
+{
+ // Update Color
+ updateColor();
+}
+
+// Update Color
+inline void Kinect::updateColor()
+{
+ // Retrieve Color Frame
+ ComPtr colorFrame;
+ const HRESULT ret = colorFrameReader->AcquireLatestFrame( &colorFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Convert Format ( YUY2 -> BGRA )
+ ERROR_CHECK( colorFrame->CopyConvertedFrameDataToArray( static_cast( colorBuffer.size() ), &colorBuffer[0], ColorImageFormat::ColorImageFormat_Bgra ) );
+}
+
+// Draw Data
+void Kinect::draw()
+{
+ // Draw Color
+ drawColor();
+}
+
+// Draw Color
+inline void Kinect::drawColor()
+{
+ // Create cv::Mat from Color Buffer
+ colorMat = cv::Mat( colorHeight, colorWidth, CV_8UC4, &colorBuffer[0] );
+}
+
+// Show Data
+void Kinect::show()
+{
+ // Show Color
+ showColor();
+}
+
+// Show Color
+inline void Kinect::showColor()
+{
+ if( colorMat.empty() ){
+ return;
+ }
+
+ // Resize Image
+ cv::Mat resizeMat;
+ const double scale = 0.5;
+ cv::resize( colorMat, resizeMat, cv::Size(), scale, scale );
+
+ // Show Image
+ cv::imshow( "Color", resizeMat );
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Color/app.h b/Kinect2Sample-master/sample/Color/app.h
new file mode 100644
index 0000000..4843a5d
--- /dev/null
+++ b/Kinect2Sample-master/sample/Color/app.h
@@ -0,0 +1,71 @@
+#ifndef __APP__
+#define __APP__
+
+#include
+#include
+#include
+
+#include
+
+#include
+using namespace Microsoft::WRL;
+
+class Kinect
+{
+private:
+ // Sensor
+ ComPtr kinect;
+
+ // Reader
+ ComPtr colorFrameReader;
+
+ // Color Buffer
+ std::vector colorBuffer;
+ int colorWidth;
+ int colorHeight;
+ unsigned int colorBytesPerPixel;
+ cv::Mat colorMat;
+
+public:
+ // Constructor
+ Kinect();
+
+ // Destructor
+ ~Kinect();
+
+ // Processing
+ void run();
+
+private:
+ // Initialize
+ void initialize();
+
+ // Initialize Sensor
+ inline void initializeSensor();
+
+ // Initialize Color
+ inline void initializeColor();
+
+ // Finalize
+ void finalize();
+
+ // Update Data
+ void update();
+
+ // Update Color
+ inline void updateColor();
+
+ // Draw Data
+ void draw();
+
+ // Draw Color
+ inline void drawColor();
+
+ // Show Data
+ void show();
+
+ // Show Color
+ inline void showColor();
+};
+
+#endif // __APP__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Color/main.cpp b/Kinect2Sample-master/sample/Color/main.cpp
new file mode 100644
index 0000000..d88643c
--- /dev/null
+++ b/Kinect2Sample-master/sample/Color/main.cpp
@@ -0,0 +1,16 @@
+#include
+#include
+
+#include "app.h"
+
+int main( int argc, char* argv[] )
+{
+ try{
+ Kinect kinect;
+ kinect.run();
+ } catch( std::exception& ex ){
+ std::cout << ex.what() << std::endl;
+ }
+
+ return 0;
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Color/util.h b/Kinect2Sample-master/sample/Color/util.h
new file mode 100644
index 0000000..0d9787f
--- /dev/null
+++ b/Kinect2Sample-master/sample/Color/util.h
@@ -0,0 +1,37 @@
+#ifndef __UTIL__
+#define __UTIL__
+
+#include
+#include
+
+// Error Check Macro
+#define ERROR_CHECK( ret ) \
+ if( FAILED( ret ) ){ \
+ std::stringstream ss; \
+ ss << "failed " #ret " " << std::hex << ret << std::endl; \
+ throw std::runtime_error( ss.str().c_str() ); \
+ }
+
+// Safe Release
+template
+inline void SafeRelease( T*& rel )
+{
+ if( rel != NULL ){
+ rel->Release();
+ rel = NULL;
+ }
+}
+
+// C++ Style Line Types For OpenCV 2.x
+#if ( CV_MAJOR_VERSION < 3 )
+namespace cv{
+ enum LineTypes{
+ FILLED = -1,
+ LINE_4 = 4,
+ LINE_8 = 8,
+ LINE_AA = 16
+ };
+}
+#endif
+
+#endif // __UTIL__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/CoordinateMapper/CMakeLists.txt b/Kinect2Sample-master/sample/CoordinateMapper/CMakeLists.txt
new file mode 100644
index 0000000..fecf614
--- /dev/null
+++ b/Kinect2Sample-master/sample/CoordinateMapper/CMakeLists.txt
@@ -0,0 +1,43 @@
+cmake_minimum_required( VERSION 3.6 )
+
+# Create Project
+project( Sample )
+add_executable( CoordinateMapper app.h app.cpp main.cpp util.h )
+
+# Set StartUp Project
+set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "CoordinateMapper" )
+
+# Find Package
+set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} )
+find_package( KinectSDK2 REQUIRED )
+
+set( OpenCV_DIR "C:/Program Files/opencv/build" )
+option( OpenCV_STATIC OFF )
+find_package( OpenCV REQUIRED )
+
+# Set Static Link Runtime Library
+if( OpenCV_STATIC )
+ foreach( flag_var
+ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO )
+ if( ${flag_var} MATCHES "/MD" )
+ string( REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}" )
+ endif()
+ endforeach()
+endif()
+
+if( KinectSDK2_FOUND AND OpenCV_FOUND )
+ # Additional Include Directories
+ include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+ include_directories( ${OpenCV_INCLUDE_DIRS} )
+
+ # Additional Library Directories
+ link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+ link_directories( ${OpenCV_LIB_DIR} )
+
+ # Additional Dependencies
+ target_link_libraries( CoordinateMapper ${KinectSDK2_LIBRARIES} )
+ target_link_libraries( CoordinateMapper ${OpenCV_LIBS} )
+endif()
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/CoordinateMapper/FindKinectSDK2.cmake b/Kinect2Sample-master/sample/CoordinateMapper/FindKinectSDK2.cmake
new file mode 100644
index 0000000..00a2036
--- /dev/null
+++ b/Kinect2Sample-master/sample/CoordinateMapper/FindKinectSDK2.cmake
@@ -0,0 +1,182 @@
+#.rst:
+# FindKinectSDK2
+# --------------
+#
+# Find Kinect for Windows SDK v2 (Kinect SDK v2) include dirs, library dirs, libraries and post-build commands
+#
+# Use this module by invoking find_package with the form::
+#
+# find_package( KinectSDK2 [REQUIRED] )
+#
+# Results for users are reported in following variables::
+#
+# KinectSDK2_FOUND - Return "TRUE" when Kinect SDK v2 found. Otherwise, Return "FALSE".
+# KinectSDK2_INCLUDE_DIRS - Kinect SDK v2 include directories. (${KinectSDK2_DIR}/inc)
+# KinectSDK2_LIBRARY_DIRS - Kinect SDK v2 library directories. (${KinectSDK2_DIR}/Lib/x86 or ${KinectSDK2_DIR}/Lib/x64)
+# KinectSDK2_LIBRARIES - Kinect SDK v2 library files. (${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib (If check the box of any application festures, corresponding library will be added.))
+# KinectSDK2_COMMANDS - Copy commands of redist files for application functions of Kinect SDK v2. (If uncheck the box of all application features, this variable has defined empty command.)
+#
+# This module reads hints about search locations from following environment variables::
+#
+# KINECTSDK20_DIR - Kinect SDK v2 root directory. (This environment variable has been set by installer of Kinect SDK v2.)
+#
+# CMake entries::
+#
+# KinectSDK2_DIR - Kinect SDK v2 root directory. (Default $ENV{KINECTSDK20_DIR})
+# KinectSDK2_FACE - Check the box when using Face or HDFace features. (Default uncheck)
+# KinectSDK2_FUSION - Check the box when using Fusion features. (Default uncheck)
+# KinectSDK2_VGB - Check the box when using Visual Gesture Builder features. (Default uncheck)
+#
+# Example to find Kinect SDK v2::
+#
+# cmake_minimum_required( VERSION 2.8 )
+#
+# project( project )
+# add_executable( project main.cpp )
+#
+# # Find package using this module.
+# find_package( KinectSDK2 REQUIRED )
+#
+# if(KinectSDK2_FOUND)
+# # [C/C++]>[General]>[Additional Include Directories]
+# include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+#
+# # [Linker]>[General]>[Additional Library Directories]
+# link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+#
+# # [Linker]>[Input]>[Additional Dependencies]
+# target_link_libraries( project ${KinectSDK2_LIBRARIES} )
+#
+# # [Build Events]>[Post-Build Event]>[Command Line]
+# add_custom_command( TARGET project POST_BUILD ${KinectSDK2_COMMANDS} )
+# endif()
+#
+# =============================================================================
+#
+# Copyright (c) 2016 Tsukasa SUGIURA
+# Distributed under the MIT License.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# =============================================================================
+
+##### Utility #####
+
+# Check Directory Macro
+macro(CHECK_DIR _DIR)
+ if(NOT EXISTS "${${_DIR}}")
+ message(WARNING "Directory \"${${_DIR}}\" not found.")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_DIR)
+ endif()
+endmacro()
+
+# Check Files Macro
+macro(CHECK_FILES _FILES _DIR)
+ set(_MISSING_FILES)
+ foreach(_FILE ${${_FILES}})
+ if(NOT EXISTS "${_FILE}")
+ get_filename_component(_FILE ${_FILE} NAME)
+ set(_MISSING_FILES "${_MISSING_FILES}${_FILE}, ")
+ endif()
+ endforeach()
+ if(_MISSING_FILES)
+ message(WARNING "In directory \"${${_DIR}}\" not found files: ${_MISSING_FILES}")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_FILES)
+ endif()
+endmacro()
+
+# Target Platform
+set(TARGET_PLATFORM)
+if(NOT CMAKE_CL_64)
+ set(TARGET_PLATFORM x86)
+else()
+ set(TARGET_PLATFORM x64)
+endif()
+
+##### Find Kinect SDK v2 #####
+
+# Found
+set(KinectSDK2_FOUND TRUE)
+if(MSVC_VERSION LESS 1700)
+ message(WARNING "Kinect for Windows SDK v2 supported Visual Studio 2012 or later.")
+ set(KinectSDK2_FOUND FALSE)
+endif()
+
+# Options
+option(KinectSDK2_FACE "Face and HDFace features" FALSE)
+option(KinectSDK2_FUSION "Fusion features" FALSE)
+option(KinectSDK2_VGB "Visual Gesture Builder features" FALSE)
+
+# Root Directoty
+set(KinectSDK2_DIR)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_DIR $ENV{KINECTSDK20_DIR} CACHE PATH "Kinect for Windows SDK v2 Install Path." FORCE)
+ check_dir(KinectSDK2_DIR)
+endif()
+
+# Include Directories
+set(KinectSDK2_INCLUDE_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_INCLUDE_DIRS ${KinectSDK2_DIR}/inc)
+ check_dir(KinectSDK2_INCLUDE_DIRS)
+endif()
+
+# Library Directories
+set(KinectSDK2_LIBRARY_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARY_DIRS ${KinectSDK2_DIR}/Lib/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Dependencies
+set(KinectSDK2_LIBRARIES)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib)
+
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Face.lib)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Fusion.lib)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.VisualGestureBuilder.lib)
+ endif()
+
+ check_files(KinectSDK2_LIBRARIES KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Custom Commands
+set(KinectSDK2_COMMANDS)
+if(KinectSDK2_FOUND)
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Face/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Fusion/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/VGB/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ # Empty Commands
+ if(NOT KinectSDK2_COMMANDS)
+ set(KinectSDK2_COMMANDS COMMAND)
+ endif()
+endif()
+
+message(STATUS "KinectSDK2_FOUND : ${KinectSDK2_FOUND}")
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/CoordinateMapper/app.cpp b/Kinect2Sample-master/sample/CoordinateMapper/app.cpp
new file mode 100644
index 0000000..554730b
--- /dev/null
+++ b/Kinect2Sample-master/sample/CoordinateMapper/app.cpp
@@ -0,0 +1,307 @@
+#include "app.h"
+#include "util.h"
+
+#include
+#include
+
+#include
+
+// Choose Resolution
+//#define COLOR
+#define DEPTH
+
+// Constructor
+Kinect::Kinect()
+{
+ // Initialize
+ initialize();
+}
+
+// Destructor
+Kinect::~Kinect()
+{
+ // Finalize
+ finalize();
+}
+
+// Processing
+void Kinect::run()
+{
+ // Main Loop
+ while( true ){
+ // Update Data
+ update();
+
+ // Draw Data
+ draw();
+
+ // Show Data
+ show();
+
+ // Key Check
+ const int key = cv::waitKey( 10 );
+ if( key == VK_ESCAPE ){
+ break;
+ }
+ }
+}
+
+// Initialize
+void Kinect::initialize()
+{
+ cv::setUseOptimized( true );
+
+ // Initialize Sensor
+ initializeSensor();
+
+ // Initialize Color
+ initializeColor();
+
+ // Initialize Depth
+ initializeDepth();
+
+ // Wait a Few Seconds until begins to Retrieve Data from Sensor ( about 2000-[ms] )
+ std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
+}
+
+// Initialize Sensor
+inline void Kinect::initializeSensor()
+{
+ // Open Sensor
+ ERROR_CHECK( GetDefaultKinectSensor( &kinect ) );
+
+ ERROR_CHECK( kinect->Open() );
+
+ // Check Open
+ BOOLEAN isOpen = FALSE;
+ ERROR_CHECK( kinect->get_IsOpen( &isOpen ) );
+ if( !isOpen ){
+ throw std::runtime_error( "failed IKinectSensor::get_IsOpen( &isOpen )" );
+ }
+
+ // Retrieve Coordinate Mapper
+ ERROR_CHECK( kinect->get_CoordinateMapper( &coordinateMapper ) );
+}
+
+// Initialize Color
+inline void Kinect::initializeColor()
+{
+ // Open Color Reader
+ ComPtr colorFrameSource;
+ ERROR_CHECK( kinect->get_ColorFrameSource( &colorFrameSource ) );
+ ERROR_CHECK( colorFrameSource->OpenReader( &colorFrameReader ) );
+
+ // Retrieve Color Description
+ ComPtr colorFrameDescription;
+ ERROR_CHECK( colorFrameSource->CreateFrameDescription( ColorImageFormat::ColorImageFormat_Bgra, &colorFrameDescription ) );
+ ERROR_CHECK( colorFrameDescription->get_Width( &colorWidth ) ); // 1920
+ ERROR_CHECK( colorFrameDescription->get_Height( &colorHeight ) ); // 1080
+ ERROR_CHECK( colorFrameDescription->get_BytesPerPixel( &colorBytesPerPixel ) ); // 4
+
+ // Allocation Color Buffer
+ colorBuffer.resize( colorWidth * colorHeight * colorBytesPerPixel );
+}
+
+// Initialize Depth
+inline void Kinect::initializeDepth()
+{
+ // Open Depth Reader
+ ComPtr depthFrameSource;
+ ERROR_CHECK( kinect->get_DepthFrameSource( &depthFrameSource ) );
+ ERROR_CHECK( depthFrameSource->OpenReader( &depthFrameReader ) );
+
+ // Retrieve Depth Description
+ ComPtr depthFrameDescription;
+ ERROR_CHECK( depthFrameSource->get_FrameDescription( &depthFrameDescription ) );
+ ERROR_CHECK( depthFrameDescription->get_Width( &depthWidth ) ); // 512
+ ERROR_CHECK( depthFrameDescription->get_Height( &depthHeight ) ); // 424
+ ERROR_CHECK( depthFrameDescription->get_BytesPerPixel( &depthBytesPerPixel ) ); // 2
+
+ // Allocation Depth Buffer
+ depthBuffer.resize( depthWidth * depthHeight );
+}
+
+// Finalize
+void Kinect::finalize()
+{
+ cv::destroyAllWindows();
+
+ // Close Sensor
+ if( kinect != nullptr ){
+ kinect->Close();
+ }
+}
+
+// Update Data
+void Kinect::update()
+{
+ // Update Color
+ updateColor();
+
+ // Update Depth
+ updateDepth();
+}
+
+// Update Color
+inline void Kinect::updateColor()
+{
+ // Retrieve Color Frame
+ ComPtr colorFrame;
+ const HRESULT ret = colorFrameReader->AcquireLatestFrame( &colorFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Convert Format ( YUY2 -> BGRA )
+ ERROR_CHECK( colorFrame->CopyConvertedFrameDataToArray( static_cast( colorBuffer.size() ), &colorBuffer[0], ColorImageFormat::ColorImageFormat_Bgra ) );
+}
+
+// Update Depth
+inline void Kinect::updateDepth()
+{
+ // Retrieve Depth Frame
+ ComPtr depthFrame;
+ const HRESULT ret = depthFrameReader->AcquireLatestFrame( &depthFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Retrieve Depth Data
+ ERROR_CHECK( depthFrame->CopyFrameDataToArray( static_cast( depthBuffer.size() ), &depthBuffer[0] ) );
+}
+
+// Draw Data
+void Kinect::draw()
+{
+ // Draw Color
+ drawColor();
+
+ // Draw Depth
+ drawDepth();
+}
+
+// Draw Color
+inline void Kinect::drawColor()
+{
+#ifdef DEPTH
+ // Retrieve Mapped Coordinates
+ std::vector colorSpacePoints( depthWidth * depthHeight );
+ ERROR_CHECK( coordinateMapper->MapDepthFrameToColorSpace( depthBuffer.size(), &depthBuffer[0], colorSpacePoints.size(), &colorSpacePoints[0] ) );
+
+ // Mapping Color to Depth Resolution
+ std::vector buffer( depthWidth * depthHeight * colorBytesPerPixel );
+
+ Concurrency::parallel_for( 0, depthHeight, [&]( const int depthY ){
+ const unsigned int depthOffset = depthY * depthWidth;
+ for( int depthX = 0; depthX < depthWidth; depthX++ ){
+ unsigned int depthIndex = depthOffset + depthX;
+ const int colorX = static_cast( colorSpacePoints[depthIndex].X + 0.5f );
+ const int colorY = static_cast( colorSpacePoints[depthIndex].Y + 0.5f );
+ if( ( 0 <= colorX ) && ( colorX < colorWidth ) && ( 0 <= colorY ) && ( colorY < colorHeight ) ){
+ const unsigned int colorIndex = ( colorY * colorWidth + colorX ) * colorBytesPerPixel;
+ depthIndex = depthIndex * colorBytesPerPixel;
+ buffer[depthIndex + 0] = colorBuffer[colorIndex + 0];
+ buffer[depthIndex + 1] = colorBuffer[colorIndex + 1];
+ buffer[depthIndex + 2] = colorBuffer[colorIndex + 2];
+ buffer[depthIndex + 3] = colorBuffer[colorIndex + 3];
+ }
+ }
+ } );
+
+ // Create cv::Mat from Coordinate Buffer
+ colorMat = cv::Mat( depthHeight, depthWidth, CV_8UC4, &buffer[0] ).clone();
+#else
+ // Create cv::Mat from Color Buffer
+ colorMat = cv::Mat( colorHeight, colorWidth, CV_8UC4, &colorBuffer[0]);
+#endif
+
+}
+
+// Draw Depth
+inline void Kinect::drawDepth()
+{
+#ifdef COLOR
+ // Retrieve Mapped Coordinates
+ std::vector depthSpacePoints( colorWidth * colorHeight );
+ ERROR_CHECK( coordinateMapper->MapColorFrameToDepthSpace( depthBuffer.size(), &depthBuffer[0], depthSpacePoints.size(), &depthSpacePoints[0] ) );
+
+ // Mapping Depth to Color Resolution
+ std::vector buffer( colorWidth * colorHeight );
+
+ Concurrency::parallel_for( 0, colorHeight, [&]( const int colorY ){
+ const unsigned int colorOffset = colorY * colorWidth;
+ for( int colorX = 0; colorX < colorWidth; colorX++ ){
+ const unsigned int colorIndex = colorOffset + colorX;
+ const int depthX = static_cast( depthSpacePoints[colorIndex].X + 0.5f );
+ const int depthY = static_cast( depthSpacePoints[colorIndex].Y + 0.5f );
+ if( ( 0 <= depthX ) && ( depthX < depthWidth ) && ( 0 <= depthY ) && ( depthY < depthHeight ) ){
+ const unsigned int depthIndex = depthY * depthWidth + depthX;
+ buffer[colorIndex] = depthBuffer[depthIndex];
+ }
+ }
+ } );
+
+ // Create cv::Mat from Coordinate Buffer
+ depthMat = cv::Mat( colorHeight, colorWidth, CV_16UC1, &buffer[0] ).clone();
+#else
+ // Create cv::Mat from Depth Buffer
+ depthMat = cv::Mat( depthHeight, depthWidth, CV_16UC1, &depthBuffer[0]);
+#endif
+}
+
+// Show Data
+void Kinect::show()
+{
+ // Show Color
+ showColor();
+
+ // Show Depth
+ showDepth();
+}
+
+// Show Color
+inline void Kinect::showColor()
+{
+ if( colorMat.empty() ){
+ return;
+ }
+
+#ifdef COLOR
+ // Resize Image
+ cv::Mat resizeMat;
+ const double scale = 0.5;
+ cv::resize( colorMat, resizeMat, cv::Size(), scale, scale );
+
+ // Show Image
+ cv::imshow( "Color", resizeMat );
+#else
+ // Show Image
+ cv::imshow( "Color", colorMat );
+#endif
+}
+
+// Show Depth
+inline void Kinect::showDepth()
+{
+ if( depthMat.empty() ){
+ return;
+ }
+
+ // Scaling ( 0-8000 -> 255-0 )
+ cv::Mat scaleMat;
+ depthMat.convertTo( scaleMat, CV_8U, -255.0 / 8000.0, 255.0 );
+ //cv::applyColorMap( scaleMat, scaleMat, cv::COLORMAP_BONE );
+
+#ifdef COLOR
+ // Resize Image
+ cv::Mat resizeMat;
+ const double scale = 0.5;
+ cv::resize( scaleMat, resizeMat, cv::Size(), scale, scale );
+
+ // Show Image
+ cv::imshow( "Depth", resizeMat );
+#else
+ // Show Image
+ cv::imshow( "Depth", scaleMat );
+#endif
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/CoordinateMapper/app.h b/Kinect2Sample-master/sample/CoordinateMapper/app.h
new file mode 100644
index 0000000..d598f68
--- /dev/null
+++ b/Kinect2Sample-master/sample/CoordinateMapper/app.h
@@ -0,0 +1,94 @@
+#ifndef __APP__
+#define __APP__
+
+#include
+#include
+#include
+
+#include
+
+#include
+using namespace Microsoft::WRL;
+
+class Kinect
+{
+private:
+ // Sensor
+ ComPtr kinect;
+
+ // Coordinate Mapper
+ ComPtr coordinateMapper;
+
+ // Reader
+ ComPtr colorFrameReader;
+ ComPtr depthFrameReader;
+
+ // Color Buffer
+ std::vector colorBuffer;
+ int colorWidth;
+ int colorHeight;
+ unsigned int colorBytesPerPixel;
+ cv::Mat colorMat;
+
+ // Depth Buffer
+ std::vector depthBuffer;
+ int depthWidth;
+ int depthHeight;
+ unsigned int depthBytesPerPixel;
+ cv::Mat depthMat;
+
+public:
+ // Constructor
+ Kinect();
+
+ // Destructor
+ ~Kinect();
+
+ // Processing
+ void run();
+
+private:
+ // Initialize
+ void initialize();
+
+ // Initialize Sensor
+ inline void initializeSensor();
+
+ // Initialize Color
+ inline void initializeColor();
+
+ // Initialize Depth
+ inline void initializeDepth();
+
+ // Finalize
+ void finalize();
+
+ // Update Data
+ void update();
+
+ // Update Color
+ inline void updateColor();
+
+ // Update Depth
+ inline void updateDepth();
+
+ // Draw Data
+ void draw();
+
+ // Draw Color
+ inline void drawColor();
+
+ // Draw Depth
+ inline void drawDepth();
+
+ // Show Data
+ void show();
+
+ // Show Color
+ inline void showColor();
+
+ // Show Depth
+ inline void showDepth();
+};
+
+#endif // __APP__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/CoordinateMapper/main.cpp b/Kinect2Sample-master/sample/CoordinateMapper/main.cpp
new file mode 100644
index 0000000..d88643c
--- /dev/null
+++ b/Kinect2Sample-master/sample/CoordinateMapper/main.cpp
@@ -0,0 +1,16 @@
+#include
+#include
+
+#include "app.h"
+
+int main( int argc, char* argv[] )
+{
+ try{
+ Kinect kinect;
+ kinect.run();
+ } catch( std::exception& ex ){
+ std::cout << ex.what() << std::endl;
+ }
+
+ return 0;
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/CoordinateMapper/util.h b/Kinect2Sample-master/sample/CoordinateMapper/util.h
new file mode 100644
index 0000000..0d9787f
--- /dev/null
+++ b/Kinect2Sample-master/sample/CoordinateMapper/util.h
@@ -0,0 +1,37 @@
+#ifndef __UTIL__
+#define __UTIL__
+
+#include
+#include
+
+// Error Check Macro
+#define ERROR_CHECK( ret ) \
+ if( FAILED( ret ) ){ \
+ std::stringstream ss; \
+ ss << "failed " #ret " " << std::hex << ret << std::endl; \
+ throw std::runtime_error( ss.str().c_str() ); \
+ }
+
+// Safe Release
+template
+inline void SafeRelease( T*& rel )
+{
+ if( rel != NULL ){
+ rel->Release();
+ rel = NULL;
+ }
+}
+
+// C++ Style Line Types For OpenCV 2.x
+#if ( CV_MAJOR_VERSION < 3 )
+namespace cv{
+ enum LineTypes{
+ FILLED = -1,
+ LINE_4 = 4,
+ LINE_8 = 8,
+ LINE_AA = 16
+ };
+}
+#endif
+
+#endif // __UTIL__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Depth/CMakeLists.txt b/Kinect2Sample-master/sample/Depth/CMakeLists.txt
new file mode 100644
index 0000000..1b42d61
--- /dev/null
+++ b/Kinect2Sample-master/sample/Depth/CMakeLists.txt
@@ -0,0 +1,43 @@
+cmake_minimum_required( VERSION 3.6 )
+
+# Create Project
+project( Sample )
+add_executable( Depth app.h app.cpp main.cpp util.h )
+
+# Set StartUp Project
+set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "Depth" )
+
+# Find Package
+set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} )
+find_package( KinectSDK2 REQUIRED )
+
+set( OpenCV_DIR "C:/Program Files/opencv/build" )
+option( OpenCV_STATIC OFF )
+find_package( OpenCV REQUIRED )
+
+# Set Static Link Runtime Library
+if( OpenCV_STATIC )
+ foreach( flag_var
+ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO )
+ if( ${flag_var} MATCHES "/MD" )
+ string( REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}" )
+ endif()
+ endforeach()
+endif()
+
+if( KinectSDK2_FOUND AND OpenCV_FOUND )
+ # Additional Include Directories
+ include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+ include_directories( ${OpenCV_INCLUDE_DIRS} )
+
+ # Additional Library Directories
+ link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+ link_directories( ${OpenCV_LIB_DIR} )
+
+ # Additional Dependencies
+ target_link_libraries( Depth ${KinectSDK2_LIBRARIES} )
+ target_link_libraries( Depth ${OpenCV_LIBS} )
+endif()
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Depth/FindKinectSDK2.cmake b/Kinect2Sample-master/sample/Depth/FindKinectSDK2.cmake
new file mode 100644
index 0000000..00a2036
--- /dev/null
+++ b/Kinect2Sample-master/sample/Depth/FindKinectSDK2.cmake
@@ -0,0 +1,182 @@
+#.rst:
+# FindKinectSDK2
+# --------------
+#
+# Find Kinect for Windows SDK v2 (Kinect SDK v2) include dirs, library dirs, libraries and post-build commands
+#
+# Use this module by invoking find_package with the form::
+#
+# find_package( KinectSDK2 [REQUIRED] )
+#
+# Results for users are reported in following variables::
+#
+# KinectSDK2_FOUND - Return "TRUE" when Kinect SDK v2 found. Otherwise, Return "FALSE".
+# KinectSDK2_INCLUDE_DIRS - Kinect SDK v2 include directories. (${KinectSDK2_DIR}/inc)
+# KinectSDK2_LIBRARY_DIRS - Kinect SDK v2 library directories. (${KinectSDK2_DIR}/Lib/x86 or ${KinectSDK2_DIR}/Lib/x64)
+# KinectSDK2_LIBRARIES - Kinect SDK v2 library files. (${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib (If check the box of any application festures, corresponding library will be added.))
+# KinectSDK2_COMMANDS - Copy commands of redist files for application functions of Kinect SDK v2. (If uncheck the box of all application features, this variable has defined empty command.)
+#
+# This module reads hints about search locations from following environment variables::
+#
+# KINECTSDK20_DIR - Kinect SDK v2 root directory. (This environment variable has been set by installer of Kinect SDK v2.)
+#
+# CMake entries::
+#
+# KinectSDK2_DIR - Kinect SDK v2 root directory. (Default $ENV{KINECTSDK20_DIR})
+# KinectSDK2_FACE - Check the box when using Face or HDFace features. (Default uncheck)
+# KinectSDK2_FUSION - Check the box when using Fusion features. (Default uncheck)
+# KinectSDK2_VGB - Check the box when using Visual Gesture Builder features. (Default uncheck)
+#
+# Example to find Kinect SDK v2::
+#
+# cmake_minimum_required( VERSION 2.8 )
+#
+# project( project )
+# add_executable( project main.cpp )
+#
+# # Find package using this module.
+# find_package( KinectSDK2 REQUIRED )
+#
+# if(KinectSDK2_FOUND)
+# # [C/C++]>[General]>[Additional Include Directories]
+# include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+#
+# # [Linker]>[General]>[Additional Library Directories]
+# link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+#
+# # [Linker]>[Input]>[Additional Dependencies]
+# target_link_libraries( project ${KinectSDK2_LIBRARIES} )
+#
+# # [Build Events]>[Post-Build Event]>[Command Line]
+# add_custom_command( TARGET project POST_BUILD ${KinectSDK2_COMMANDS} )
+# endif()
+#
+# =============================================================================
+#
+# Copyright (c) 2016 Tsukasa SUGIURA
+# Distributed under the MIT License.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# =============================================================================
+
+##### Utility #####
+
+# Check Directory Macro
+macro(CHECK_DIR _DIR)
+ if(NOT EXISTS "${${_DIR}}")
+ message(WARNING "Directory \"${${_DIR}}\" not found.")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_DIR)
+ endif()
+endmacro()
+
+# Check Files Macro
+macro(CHECK_FILES _FILES _DIR)
+ set(_MISSING_FILES)
+ foreach(_FILE ${${_FILES}})
+ if(NOT EXISTS "${_FILE}")
+ get_filename_component(_FILE ${_FILE} NAME)
+ set(_MISSING_FILES "${_MISSING_FILES}${_FILE}, ")
+ endif()
+ endforeach()
+ if(_MISSING_FILES)
+ message(WARNING "In directory \"${${_DIR}}\" not found files: ${_MISSING_FILES}")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_FILES)
+ endif()
+endmacro()
+
+# Target Platform
+set(TARGET_PLATFORM)
+if(NOT CMAKE_CL_64)
+ set(TARGET_PLATFORM x86)
+else()
+ set(TARGET_PLATFORM x64)
+endif()
+
+##### Find Kinect SDK v2 #####
+
+# Found
+set(KinectSDK2_FOUND TRUE)
+if(MSVC_VERSION LESS 1700)
+ message(WARNING "Kinect for Windows SDK v2 supported Visual Studio 2012 or later.")
+ set(KinectSDK2_FOUND FALSE)
+endif()
+
+# Options
+option(KinectSDK2_FACE "Face and HDFace features" FALSE)
+option(KinectSDK2_FUSION "Fusion features" FALSE)
+option(KinectSDK2_VGB "Visual Gesture Builder features" FALSE)
+
+# Root Directoty
+set(KinectSDK2_DIR)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_DIR $ENV{KINECTSDK20_DIR} CACHE PATH "Kinect for Windows SDK v2 Install Path." FORCE)
+ check_dir(KinectSDK2_DIR)
+endif()
+
+# Include Directories
+set(KinectSDK2_INCLUDE_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_INCLUDE_DIRS ${KinectSDK2_DIR}/inc)
+ check_dir(KinectSDK2_INCLUDE_DIRS)
+endif()
+
+# Library Directories
+set(KinectSDK2_LIBRARY_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARY_DIRS ${KinectSDK2_DIR}/Lib/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Dependencies
+set(KinectSDK2_LIBRARIES)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib)
+
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Face.lib)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Fusion.lib)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.VisualGestureBuilder.lib)
+ endif()
+
+ check_files(KinectSDK2_LIBRARIES KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Custom Commands
+set(KinectSDK2_COMMANDS)
+if(KinectSDK2_FOUND)
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Face/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Fusion/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/VGB/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ # Empty Commands
+ if(NOT KinectSDK2_COMMANDS)
+ set(KinectSDK2_COMMANDS COMMAND)
+ endif()
+endif()
+
+message(STATUS "KinectSDK2_FOUND : ${KinectSDK2_FOUND}")
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Depth/app.cpp b/Kinect2Sample-master/sample/Depth/app.cpp
new file mode 100644
index 0000000..4eb9472
--- /dev/null
+++ b/Kinect2Sample-master/sample/Depth/app.cpp
@@ -0,0 +1,167 @@
+#include "app.h"
+#include "util.h"
+
+#include
+#include
+
+// Constructor
+Kinect::Kinect()
+{
+ // Initialize
+ initialize();
+}
+
+// Destructor
+Kinect::~Kinect()
+{
+ // Finalize
+ finalize();
+}
+
+// Processing
+void Kinect::run()
+{
+ // Main Loop
+ while( true ){
+ // Update Data
+ update();
+
+ // Draw Data
+ draw();
+
+ // Show Data
+ show();
+
+ // Key Check
+ const int key = cv::waitKey( 10 );
+ if( key == VK_ESCAPE ){
+ break;
+ }
+ }
+}
+
+// Initialize
+void Kinect::initialize()
+{
+ cv::setUseOptimized( true );
+
+ // Initialize Sensor
+ initializeSensor();
+
+ // Initialize Depth
+ initializeDepth();
+
+ // Wait a Few Seconds until begins to Retrieve Data from Sensor ( about 2000-[ms] )
+ std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
+}
+
+// Initialize Sensor
+inline void Kinect::initializeSensor()
+{
+ // Open Sensor
+ ERROR_CHECK( GetDefaultKinectSensor( &kinect ) );
+
+ ERROR_CHECK( kinect->Open() );
+
+ // Check Open
+ BOOLEAN isOpen = FALSE;
+ ERROR_CHECK( kinect->get_IsOpen( &isOpen ) );
+ if( !isOpen ){
+ throw std::runtime_error( "failed IKinectSensor::get_IsOpen( &isOpen )" );
+ }
+}
+
+// Initialize Depth
+inline void Kinect::initializeDepth()
+{
+ // Open Depth Reader
+ ComPtr depthFrameSource;
+ ERROR_CHECK( kinect->get_DepthFrameSource( &depthFrameSource ) );
+ ERROR_CHECK( depthFrameSource->OpenReader( &depthFrameReader ) );
+
+ // Retrieve Depth Description
+ ComPtr depthFrameDescription;
+ ERROR_CHECK( depthFrameSource->get_FrameDescription( &depthFrameDescription ) );
+ ERROR_CHECK( depthFrameDescription->get_Width( &depthWidth ) ); // 512
+ ERROR_CHECK( depthFrameDescription->get_Height( &depthHeight ) ); // 424
+ ERROR_CHECK( depthFrameDescription->get_BytesPerPixel( &depthBytesPerPixel ) ); // 2
+
+ // Retrieve Depth Reliable Range
+ UINT16 minReliableDistance;
+ UINT16 maxReliableDistance;
+ ERROR_CHECK( depthFrameSource->get_DepthMinReliableDistance( &minReliableDistance ) ); // 500
+ ERROR_CHECK( depthFrameSource->get_DepthMaxReliableDistance( &maxReliableDistance ) ); // 4500
+ std::cout << "Depth Reliable Range : " << minReliableDistance << " - " << maxReliableDistance << std::endl;
+
+ // Allocation Depth Buffer
+ depthBuffer.resize( depthWidth * depthHeight );
+}
+
+// Finalize
+void Kinect::finalize()
+{
+ cv::destroyAllWindows();
+
+ // Close Sensor
+ if( kinect != nullptr ){
+ kinect->Close();
+ }
+}
+
+// Update Data
+void Kinect::update()
+{
+ // Update Depth
+ updateDepth();
+}
+
+// Update Depth
+inline void Kinect::updateDepth()
+{
+ // Retrieve Depth Frame
+ ComPtr depthFrame;
+ const HRESULT ret = depthFrameReader->AcquireLatestFrame( &depthFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Retrieve Depth Data
+ ERROR_CHECK( depthFrame->CopyFrameDataToArray( static_cast( depthBuffer.size() ), &depthBuffer[0] ) );
+}
+
+// Draw Data
+void Kinect::draw()
+{
+ // Draw Depth
+ drawDepth();
+}
+
+// Draw Depth
+inline void Kinect::drawDepth()
+{
+ // Create cv::Mat from Depth Buffer
+ depthMat = cv::Mat( depthHeight, depthWidth, CV_16UC1, &depthBuffer[0] );
+}
+
+// Show Data
+void Kinect::show()
+{
+ // Show Depth
+ showDepth();
+}
+
+// Show Depth
+inline void Kinect::showDepth()
+{
+ if( depthMat.empty() ){
+ return;
+ }
+
+ // Scaling ( 0-8000 -> 255-0 )
+ cv::Mat scaleMat;
+ depthMat.convertTo( scaleMat, CV_8U, -255.0 / 8000.0, 255.0 );
+ //cv::applyColorMap( scaleMat, scaleMat, cv::COLORMAP_BONE );
+
+ // Show Image
+ cv::imshow( "Depth", scaleMat );
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Depth/app.h b/Kinect2Sample-master/sample/Depth/app.h
new file mode 100644
index 0000000..0afc2f0
--- /dev/null
+++ b/Kinect2Sample-master/sample/Depth/app.h
@@ -0,0 +1,71 @@
+#ifndef __APP__
+#define __APP__
+
+#include
+#include
+#include
+
+#include
+
+#include
+using namespace Microsoft::WRL;
+
+class Kinect
+{
+private:
+ // Sensor
+ ComPtr kinect;
+
+ // Reader
+ ComPtr depthFrameReader;
+
+ // Depth Buffer
+ std::vector depthBuffer;
+ int depthWidth;
+ int depthHeight;
+ unsigned int depthBytesPerPixel;
+ cv::Mat depthMat;
+
+public:
+ // Constructor
+ Kinect();
+
+ // Destructor
+ ~Kinect();
+
+ // Processing
+ void run();
+
+private:
+ // Initialize
+ void initialize();
+
+ // Initialize Sensor
+ inline void initializeSensor();
+
+ // Initialize Depth
+ inline void initializeDepth();
+
+ // Finalize
+ void finalize();
+
+ // Update Data
+ void update();
+
+ // Update Depth
+ inline void updateDepth();
+
+ // Draw Data
+ void draw();
+
+ // Draw Depth
+ inline void drawDepth();
+
+ // Show Data
+ void show();
+
+ // Show Depth
+ inline void showDepth();
+};
+
+#endif // __APP__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Depth/main.cpp b/Kinect2Sample-master/sample/Depth/main.cpp
new file mode 100644
index 0000000..d88643c
--- /dev/null
+++ b/Kinect2Sample-master/sample/Depth/main.cpp
@@ -0,0 +1,16 @@
+#include
+#include
+
+#include "app.h"
+
+int main( int argc, char* argv[] )
+{
+ try{
+ Kinect kinect;
+ kinect.run();
+ } catch( std::exception& ex ){
+ std::cout << ex.what() << std::endl;
+ }
+
+ return 0;
+}
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Depth/util.h b/Kinect2Sample-master/sample/Depth/util.h
new file mode 100644
index 0000000..0d9787f
--- /dev/null
+++ b/Kinect2Sample-master/sample/Depth/util.h
@@ -0,0 +1,37 @@
+#ifndef __UTIL__
+#define __UTIL__
+
+#include
+#include
+
+// Error Check Macro
+#define ERROR_CHECK( ret ) \
+ if( FAILED( ret ) ){ \
+ std::stringstream ss; \
+ ss << "failed " #ret " " << std::hex << ret << std::endl; \
+ throw std::runtime_error( ss.str().c_str() ); \
+ }
+
+// Safe Release
+template
+inline void SafeRelease( T*& rel )
+{
+ if( rel != NULL ){
+ rel->Release();
+ rel = NULL;
+ }
+}
+
+// C++ Style Line Types For OpenCV 2.x
+#if ( CV_MAJOR_VERSION < 3 )
+namespace cv{
+ enum LineTypes{
+ FILLED = -1,
+ LINE_4 = 4,
+ LINE_8 = 8,
+ LINE_AA = 16
+ };
+}
+#endif
+
+#endif // __UTIL__
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Face/CMakeLists.txt b/Kinect2Sample-master/sample/Face/CMakeLists.txt
new file mode 100644
index 0000000..ee899c6
--- /dev/null
+++ b/Kinect2Sample-master/sample/Face/CMakeLists.txt
@@ -0,0 +1,47 @@
+cmake_minimum_required( VERSION 3.6 )
+
+# Create Project
+project( Sample )
+add_executable( Face app.h app.cpp main.cpp util.h )
+
+# Set StartUp Project
+set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "Face" )
+
+# Find Package
+set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} )
+set( KinectSDK2_FACE TRUE )
+find_package( KinectSDK2 REQUIRED )
+
+set( OpenCV_DIR "C:/Program Files/opencv/build" )
+option( OpenCV_STATIC OFF )
+find_package( OpenCV REQUIRED )
+
+# Set Static Link Runtime Library
+if( OpenCV_STATIC )
+ foreach( flag_var
+ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO )
+ if( ${flag_var} MATCHES "/MD" )
+ string( REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}" )
+ endif()
+ endforeach()
+endif()
+
+if( KinectSDK2_FOUND AND OpenCV_FOUND )
+ # Additional Include Directories
+ include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+ include_directories( ${OpenCV_INCLUDE_DIRS} )
+
+ # Additional Library Directories
+ link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+ link_directories( ${OpenCV_LIB_DIR} )
+
+ # Additional Dependencies
+ target_link_libraries( Face ${KinectSDK2_LIBRARIES} )
+ target_link_libraries( Face ${OpenCV_LIBS} )
+
+ # Post Build Event
+ add_custom_command( TARGET Face POST_BUILD ${KinectSDK2_COMMANDS} )
+endif()
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Face/FindKinectSDK2.cmake b/Kinect2Sample-master/sample/Face/FindKinectSDK2.cmake
new file mode 100644
index 0000000..00a2036
--- /dev/null
+++ b/Kinect2Sample-master/sample/Face/FindKinectSDK2.cmake
@@ -0,0 +1,182 @@
+#.rst:
+# FindKinectSDK2
+# --------------
+#
+# Find Kinect for Windows SDK v2 (Kinect SDK v2) include dirs, library dirs, libraries and post-build commands
+#
+# Use this module by invoking find_package with the form::
+#
+# find_package( KinectSDK2 [REQUIRED] )
+#
+# Results for users are reported in following variables::
+#
+# KinectSDK2_FOUND - Return "TRUE" when Kinect SDK v2 found. Otherwise, Return "FALSE".
+# KinectSDK2_INCLUDE_DIRS - Kinect SDK v2 include directories. (${KinectSDK2_DIR}/inc)
+# KinectSDK2_LIBRARY_DIRS - Kinect SDK v2 library directories. (${KinectSDK2_DIR}/Lib/x86 or ${KinectSDK2_DIR}/Lib/x64)
+# KinectSDK2_LIBRARIES - Kinect SDK v2 library files. (${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib (If check the box of any application festures, corresponding library will be added.))
+# KinectSDK2_COMMANDS - Copy commands of redist files for application functions of Kinect SDK v2. (If uncheck the box of all application features, this variable has defined empty command.)
+#
+# This module reads hints about search locations from following environment variables::
+#
+# KINECTSDK20_DIR - Kinect SDK v2 root directory. (This environment variable has been set by installer of Kinect SDK v2.)
+#
+# CMake entries::
+#
+# KinectSDK2_DIR - Kinect SDK v2 root directory. (Default $ENV{KINECTSDK20_DIR})
+# KinectSDK2_FACE - Check the box when using Face or HDFace features. (Default uncheck)
+# KinectSDK2_FUSION - Check the box when using Fusion features. (Default uncheck)
+# KinectSDK2_VGB - Check the box when using Visual Gesture Builder features. (Default uncheck)
+#
+# Example to find Kinect SDK v2::
+#
+# cmake_minimum_required( VERSION 2.8 )
+#
+# project( project )
+# add_executable( project main.cpp )
+#
+# # Find package using this module.
+# find_package( KinectSDK2 REQUIRED )
+#
+# if(KinectSDK2_FOUND)
+# # [C/C++]>[General]>[Additional Include Directories]
+# include_directories( ${KinectSDK2_INCLUDE_DIRS} )
+#
+# # [Linker]>[General]>[Additional Library Directories]
+# link_directories( ${KinectSDK2_LIBRARY_DIRS} )
+#
+# # [Linker]>[Input]>[Additional Dependencies]
+# target_link_libraries( project ${KinectSDK2_LIBRARIES} )
+#
+# # [Build Events]>[Post-Build Event]>[Command Line]
+# add_custom_command( TARGET project POST_BUILD ${KinectSDK2_COMMANDS} )
+# endif()
+#
+# =============================================================================
+#
+# Copyright (c) 2016 Tsukasa SUGIURA
+# Distributed under the MIT License.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# =============================================================================
+
+##### Utility #####
+
+# Check Directory Macro
+macro(CHECK_DIR _DIR)
+ if(NOT EXISTS "${${_DIR}}")
+ message(WARNING "Directory \"${${_DIR}}\" not found.")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_DIR)
+ endif()
+endmacro()
+
+# Check Files Macro
+macro(CHECK_FILES _FILES _DIR)
+ set(_MISSING_FILES)
+ foreach(_FILE ${${_FILES}})
+ if(NOT EXISTS "${_FILE}")
+ get_filename_component(_FILE ${_FILE} NAME)
+ set(_MISSING_FILES "${_MISSING_FILES}${_FILE}, ")
+ endif()
+ endforeach()
+ if(_MISSING_FILES)
+ message(WARNING "In directory \"${${_DIR}}\" not found files: ${_MISSING_FILES}")
+ set(KinectSDK2_FOUND FALSE)
+ unset(_FILES)
+ endif()
+endmacro()
+
+# Target Platform
+set(TARGET_PLATFORM)
+if(NOT CMAKE_CL_64)
+ set(TARGET_PLATFORM x86)
+else()
+ set(TARGET_PLATFORM x64)
+endif()
+
+##### Find Kinect SDK v2 #####
+
+# Found
+set(KinectSDK2_FOUND TRUE)
+if(MSVC_VERSION LESS 1700)
+ message(WARNING "Kinect for Windows SDK v2 supported Visual Studio 2012 or later.")
+ set(KinectSDK2_FOUND FALSE)
+endif()
+
+# Options
+option(KinectSDK2_FACE "Face and HDFace features" FALSE)
+option(KinectSDK2_FUSION "Fusion features" FALSE)
+option(KinectSDK2_VGB "Visual Gesture Builder features" FALSE)
+
+# Root Directoty
+set(KinectSDK2_DIR)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_DIR $ENV{KINECTSDK20_DIR} CACHE PATH "Kinect for Windows SDK v2 Install Path." FORCE)
+ check_dir(KinectSDK2_DIR)
+endif()
+
+# Include Directories
+set(KinectSDK2_INCLUDE_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_INCLUDE_DIRS ${KinectSDK2_DIR}/inc)
+ check_dir(KinectSDK2_INCLUDE_DIRS)
+endif()
+
+# Library Directories
+set(KinectSDK2_LIBRARY_DIRS)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARY_DIRS ${KinectSDK2_DIR}/Lib/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Dependencies
+set(KinectSDK2_LIBRARIES)
+if(KinectSDK2_FOUND)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib)
+
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Face.lib)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Fusion.lib)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.VisualGestureBuilder.lib)
+ endif()
+
+ check_files(KinectSDK2_LIBRARIES KinectSDK2_LIBRARY_DIRS)
+endif()
+
+# Custom Commands
+set(KinectSDK2_COMMANDS)
+if(KinectSDK2_FOUND)
+ if(KinectSDK2_FACE)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Face/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_FUSION)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Fusion/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ if(KinectSDK2_VGB)
+ set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/VGB/${TARGET_PLATFORM})
+ check_dir(KinectSDK2_REDIST_DIR)
+ list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL)
+ endif()
+
+ # Empty Commands
+ if(NOT KinectSDK2_COMMANDS)
+ set(KinectSDK2_COMMANDS COMMAND)
+ endif()
+endif()
+
+message(STATUS "KinectSDK2_FOUND : ${KinectSDK2_FOUND}")
\ No newline at end of file
diff --git a/Kinect2Sample-master/sample/Face/app.cpp b/Kinect2Sample-master/sample/Face/app.cpp
new file mode 100644
index 0000000..334314b
--- /dev/null
+++ b/Kinect2Sample-master/sample/Face/app.cpp
@@ -0,0 +1,440 @@
+#include "app.h"
+#include "util.h"
+
+#include
+#include
+#define _USE_MATH_DEFINES
+#include
+
+#include
+
+// Constructor
+Kinect::Kinect()
+{
+ // Initialize
+ initialize();
+}
+
+// Destructor
+Kinect::~Kinect()
+{
+ // Finalize
+ finalize();
+}
+
+// Processing
+void Kinect::run()
+{
+ // Main Loop
+ while( true ){
+ // Update Data
+ update();
+
+ // Draw Data
+ draw();
+
+ // Show Data
+ show();
+
+ // Key Check
+ const int key = cv::waitKey( 10 );
+ if( key == VK_ESCAPE ){
+ break;
+ }
+ }
+}
+
+// Initialize
+void Kinect::initialize()
+{
+ cv::setUseOptimized( true );
+
+ // Initialize Sensor
+ initializeSensor();
+
+ // Initialize Color
+ initializeColor();
+
+ // Initialize Body
+ initializeBody();
+
+ // Initialize Face
+ initializeFace();
+
+ // Wait a Few Seconds until begins to Retrieve Data from Sensor ( about 2000-[ms] )
+ std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
+}
+
+// Initialize Sensor
+inline void Kinect::initializeSensor()
+{
+ // Open Sensor
+ ERROR_CHECK( GetDefaultKinectSensor( &kinect ) );
+
+ ERROR_CHECK( kinect->Open() );
+
+ // Check Open
+ BOOLEAN isOpen = FALSE;
+ ERROR_CHECK( kinect->get_IsOpen( &isOpen ) );
+ if( !isOpen ){
+ throw std::runtime_error( "failed IKinectSensor::get_IsOpen( &isOpen )" );
+ }
+
+ // Retrieve Coordinate Mapper
+ ERROR_CHECK( kinect->get_CoordinateMapper( &coordinateMapper ) );
+}
+
+// Initialize Color
+inline void Kinect::initializeColor()
+{
+ // Open Color Reader
+ ComPtr colorFrameSource;
+ ERROR_CHECK( kinect->get_ColorFrameSource( &colorFrameSource ) );
+ ERROR_CHECK( colorFrameSource->OpenReader( &colorFrameReader ) );
+
+ // Retrieve Color Description
+ ComPtr colorFrameDescription;
+ ERROR_CHECK( colorFrameSource->CreateFrameDescription( ColorImageFormat::ColorImageFormat_Bgra, &colorFrameDescription ) );
+ ERROR_CHECK( colorFrameDescription->get_Width( &colorWidth ) ); // 1920
+ ERROR_CHECK( colorFrameDescription->get_Height( &colorHeight ) ); // 1080
+ ERROR_CHECK( colorFrameDescription->get_BytesPerPixel( &colorBytesPerPixel ) ); // 4
+
+ // Allocation Color Buffer
+ colorBuffer.resize( colorWidth * colorHeight * colorBytesPerPixel );
+}
+
+// Initialize Body
+inline void Kinect::initializeBody()
+{
+ // Open Body Reader
+ ComPtr bodyFrameSource;
+ ERROR_CHECK( kinect->get_BodyFrameSource( &bodyFrameSource ) );
+ ERROR_CHECK( bodyFrameSource->OpenReader( &bodyFrameReader ) );
+
+ // Initialize Body Buffer
+ Concurrency::parallel_for_each( bodies.begin(), bodies.end(), []( IBody*& body ){
+ SafeRelease( body );
+ } );
+}
+
+// Initialize Face
+inline void Kinect::initializeFace()
+{
+ // Set Face Features to Enable
+ const DWORD features =
+ FaceFrameFeatures::FaceFrameFeatures_BoundingBoxInColorSpace
+ | FaceFrameFeatures::FaceFrameFeatures_PointsInColorSpace
+ | FaceFrameFeatures::FaceFrameFeatures_RotationOrientation
+ | FaceFrameFeatures::FaceFrameFeatures_Happy
+ | FaceFrameFeatures::FaceFrameFeatures_RightEyeClosed
+ | FaceFrameFeatures::FaceFrameFeatures_LeftEyeClosed
+ | FaceFrameFeatures::FaceFrameFeatures_MouthOpen
+ | FaceFrameFeatures::FaceFrameFeatures_MouthMoved
+ | FaceFrameFeatures::FaceFrameFeatures_LookingAway
+ | FaceFrameFeatures::FaceFrameFeatures_Glasses
+ | FaceFrameFeatures::FaceFrameFeatures_FaceEngagement;
+
+ Concurrency::parallel_for( 0, BODY_COUNT, [&]( const int count ){
+ // Create Face Sources
+ ComPtr faceFrameSource;
+ ERROR_CHECK( CreateFaceFrameSource( kinect.Get(), 0, features, &faceFrameSource ) );
+
+ // Open Face Readers
+ ERROR_CHECK( faceFrameSource->OpenReader( &faceFrameReader[count] ) );
+ } );
+
+ // Color Table for Visualization
+ colors[0] = cv::Vec3b( 255, 0, 0 ); // Blue
+ colors[1] = cv::Vec3b( 0, 255, 0 ); // Green
+ colors[2] = cv::Vec3b( 0, 0, 255 ); // Red
+ colors[3] = cv::Vec3b( 255, 255, 0 ); // Cyan
+ colors[4] = cv::Vec3b( 255, 0, 255 ); // Magenta
+ colors[5] = cv::Vec3b( 0, 255, 255 ); // Yellow
+
+ // Face Property Label Text Table for Display
+ labels[0] = "Happy";
+ labels[1] = "Engaged";
+ labels[2] = "WearingGlasses";
+ labels[3] = "LeftEyeClosed";
+ labels[4] = "RightEyeClosed";
+ labels[5] = "MouthOpen";
+ labels[6] = "MouthMoved";
+ labels[7] = "LookingAway";
+}
+
+// Finalize
+void Kinect::finalize()
+{
+ cv::destroyAllWindows();
+
+ // Release Body Buffer
+ Concurrency::parallel_for_each( bodies.begin(), bodies.end(), []( IBody*& body ){
+ SafeRelease( body );
+ } );
+
+ // Close Sensor
+ if( kinect != nullptr ){
+ kinect->Close();
+ }
+}
+
+// Update Data
+void Kinect::update()
+{
+ // Update Color
+ updateColor();
+
+ // Update Body
+ updateBody();
+
+ // Update Face
+ updateFace();
+}
+
+// Update Color
+inline void Kinect::updateColor()
+{
+ // Retrieve Color Frame
+ ComPtr colorFrame;
+ const HRESULT ret = colorFrameReader->AcquireLatestFrame( &colorFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Convert Format ( YUY2 -> BGRA )
+ ERROR_CHECK( colorFrame->CopyConvertedFrameDataToArray( static_cast( colorBuffer.size() ), &colorBuffer[0], ColorImageFormat::ColorImageFormat_Bgra ) );
+}
+
+// Update Body
+inline void Kinect::updateBody()
+{
+ // Retrieve Body Frame
+ ComPtr bodyFrame;
+ const HRESULT ret = bodyFrameReader->AcquireLatestFrame( &bodyFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Release Previous Bodies
+ Concurrency::parallel_for_each( bodies.begin(), bodies.end(), []( IBody*& body ){
+ SafeRelease( body );
+ } );
+
+ // Retrieve Body Data
+ ERROR_CHECK( bodyFrame->GetAndRefreshBodyData( static_cast( bodies.size() ), &bodies[0] ) );
+ Concurrency::parallel_for( 0, BODY_COUNT, [&]( const int count ){
+ const ComPtr body = bodies[count];
+ BOOLEAN tracked;
+ ERROR_CHECK( body->get_IsTracked( &tracked ) );
+ if( !tracked ){
+ return;
+ }
+
+ // Retrieve Tracking ID
+ UINT64 trackingId;
+ ERROR_CHECK( body->get_TrackingId( &trackingId ) );
+
+ // Registration Tracking ID
+ ComPtr faceFrameSource;
+ ERROR_CHECK( faceFrameReader[count]->get_FaceFrameSource( &faceFrameSource ) );
+ ERROR_CHECK( faceFrameSource->put_TrackingId( trackingId ) );
+ } );
+}
+
+// Update Face
+inline void Kinect::updateFace()
+{
+ // ReSet Results
+ results.fill( nullptr );
+
+ Concurrency::parallel_for( 0, BODY_COUNT, [&]( const int count ){
+ // Retrieve Face Frame
+ ComPtr faceFrame;
+ const HRESULT ret = faceFrameReader[count]->AcquireLatestFrame( &faceFrame );
+ if( FAILED( ret ) ){
+ return;
+ }
+
+ // Check Tracking ID is Valid
+ BOOLEAN tracked;
+ ERROR_CHECK( faceFrame->get_IsTrackingIdValid( &tracked ) );
+ if( !tracked ){
+ return;
+ }
+
+ // Release Previous Face Result and Retrieve Face Result
+ ERROR_CHECK( faceFrame->get_FaceFrameResult( &results[count] ) );
+ } );
+}
+
+// Draw Data
+void Kinect::draw()
+{
+ // Draw Color
+ drawColor();
+
+ // Draw Face
+ drawFace();
+}
+
+// Draw Color
+inline void Kinect::drawColor()
+{
+ // Create cv::Mat from Color Buffer
+ colorMat = cv::Mat( colorHeight, colorWidth, CV_8UC4, &colorBuffer[0] );
+}
+
+// Draw Face
+inline void Kinect::drawFace()
+{
+ if( colorMat.empty() ){
+ return;
+ }
+
+ Concurrency::parallel_for( 0, BODY_COUNT, [&]( const int count ){
+ const ComPtr