├── Assets ├── 25_Joints.png ├── Joints_index.png ├── Kinect v2.jpeg ├── Kinect_coordinate.png └── Opencv编译器版本选择.PNG ├── README.md └── Samples ├── CMakeLists.txt ├── FindKInectSDK2.cmake ├── kinect_continuous_acquisition.cpp └── sdk_pointcloud.cpp /Assets/25_Joints.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YufengLii/Kinect-v2-Tutorial/de15547776bf44cc6731b9ffe21d4a8d3301f957/Assets/25_Joints.png -------------------------------------------------------------------------------- /Assets/Joints_index.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YufengLii/Kinect-v2-Tutorial/de15547776bf44cc6731b9ffe21d4a8d3301f957/Assets/Joints_index.png -------------------------------------------------------------------------------- /Assets/Kinect v2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YufengLii/Kinect-v2-Tutorial/de15547776bf44cc6731b9ffe21d4a8d3301f957/Assets/Kinect v2.jpeg -------------------------------------------------------------------------------- /Assets/Kinect_coordinate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YufengLii/Kinect-v2-Tutorial/de15547776bf44cc6731b9ffe21d4a8d3301f957/Assets/Kinect_coordinate.png -------------------------------------------------------------------------------- /Assets/Opencv编译器版本选择.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YufengLii/Kinect-v2-Tutorial/de15547776bf44cc6731b9ffe21d4a8d3301f957/Assets/Opencv编译器版本选择.PNG -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kinect-v2-Tutorial 2 | 3 | - Kinect采集彩色图,深度图,点云 4 | - 彩色图深度图对齐 5 | 6 | # 编程环境配置 7 | 8 | **依赖项:** Kinect SDK提供了获取传感器数据和相机信息的API;需要用到Opencv的图像数据结构、显示、存储等;PCL中用到点云数据结构,点云存取等; 9 | - Kinect SDK 2.0 10 | - Opencv 11 | - PCL 12 | 13 | 两种配置方法: 14 | 1. VS添加Kinect SDK属性表的方式(不推荐使用,对每个依赖库手动添加属性表比较繁琐); 15 | 2. 使用Cmake **推荐方式** 16 | 17 | 由于CMAKE配置方式配置过程简单,项目构建与调整更加灵活,只介绍CMake配置方法; 18 | 19 | ## 依赖项安装方法 20 | 21 | ### visual studio 22 | 1. visual studio版本需要等于或高于目标平台。即,你计划用vc14 x64的编译配置,那么vs版本不能低于2015版; 23 | 2. opencv、pcl库的编译选项一定需要和目标编译选项一致。建议下载预编译版本的OPENCV与PCL,注意下载时,选择与目标平台相同的预编译版本;如`PCL-1.8.1-AllInOne-msvc2017-win64.exe`与`opencv-3.4.0-vc14_vc15.exe`均为`vc15 x64`的配置,在用CMAKE编译自己代码时,平台选择应相同。 24 | ![平台一致性](./Assets/Opencv编译器版本选择.PNG) 25 | ### [cmake](https://cmake.org/) 26 | - 添加Kinect sdk2的cmake配置文件。将Samples目录下的`FindKInectSDK2.cmake`文件复制到Cmake安装目录下的`share\cmake-3.10\Modules\`文件夹中。例如:`D:\CMAKE\share\cmake-3.10\Modules`。 27 | 28 | ### [Opencv](https://opencv.org/releases.html) 29 | - 可自己编译或下载预编译版本 30 | - 注意平台一致性 31 | - Opencv环境变量 32 | 1. 在系统变量中添加`OpenCV_DIR`,值为build目录下包含`OpenCVConfig.cmake`文件的文件夹路径。例如:`D:\opencv3.2\build_vc15_x64\install`; 33 | 2. 在环境变量`Path`中添加opencv `bin`目录,例如:`D:\opencv3.2\build_vc15_x64\install\bin` 34 | ### [PCL](http://unanancyowen.com/en/) 35 | 可自行编译或下载预编译版本。 36 | **注意:**预编译版本需要跟自己电脑的Visual studio版本一致;且不要忘记添加相应的环境变量 37 | 38 | 39 | ## cmake工程配置文件CMakeLists.txt写法 40 | ```cmake 41 | # Example CMakeLists.txt 42 | # FindKInectSDK2.cmake copy to CMake\share\cmake-3.5\Modules or same directory as this file 43 | 44 | cmake_minimum_required( VERSION 2.8 ) 45 | set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} ) 46 | 47 | project( Kinect_v2_Tutorial ) 48 | 49 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ./bin) 50 | 51 | # Find Kinect SDK v2 52 | find_package( KinectSDK2 REQUIRED ) 53 | FIND_PACKAGE(OpenCV REQUIRED) 54 | INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS}) 55 | 56 | # Settings Kinect SDK v2 57 | include_directories( ${KinectSDK2_INCLUDE_DIRS} ) 58 | link_directories( ${KinectSDK2_LIBRARY_DIRS} ) 59 | 60 | # Find Packages 61 | find_package(PCL 1.8 REQUIRED) 62 | 63 | # Additional Include Directories 64 | # [C/C++]>[General]>[Additional Include Directories] 65 | include_directories( ${PCL_INCLUDE_DIRS} ) 66 | 67 | # Preprocessor Definitions 68 | # [C/C++]>[Preprocessor]>[Preprocessor Definitions] 69 | add_definitions( ${PCL_DEFINITIONS} ) 70 | add_definitions( -DPCL_NO_PRECOMPILE ) 71 | 72 | # Additional Library Directories 73 | # [Linker]>[General]>[Additional Library Directories] 74 | link_directories( ${PCL_LIBRARY_DIRS} ) 75 | 76 | # 可按下面的格式添加自己的源文件 77 | add_executable( camera_calibration camera_calibration.cpp ) 78 | add_custom_command( TARGET camera_calibration POST_BUILD ${KinectSDK2_COMMANDS} ) 79 | set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "camera_calibration" ) 80 | target_link_libraries( camera_calibration ${OpenCV_LIBS} ${KinectSDK2_LIBRARIES} ) 81 | ``` 82 | -------------------------------------------------------------------------------- /Samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Example CMakeLists.txt 2 | # FindKInectSDK2.cmake copy to CMake\share\cmake-3.5\Modules or same directory as this file 3 | 4 | cmake_minimum_required( VERSION 2.8 ) 5 | set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} ) 6 | 7 | project( Kinect_v2_Tutorial ) 8 | 9 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ./bin) 10 | 11 | # Find Kinect SDK v2 12 | find_package( KinectSDK2 REQUIRED ) 13 | FIND_PACKAGE(OpenCV REQUIRED) 14 | INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS}) 15 | 16 | # Settings Kinect SDK v2 17 | include_directories( ${KinectSDK2_INCLUDE_DIRS} ) 18 | link_directories( ${KinectSDK2_LIBRARY_DIRS} ) 19 | 20 | # Find Packages 21 | find_package(PCL 1.8 REQUIRED) 22 | 23 | # Additional Include Directories 24 | # [C/C++]>[General]>[Additional Include Directories] 25 | include_directories( ${PCL_INCLUDE_DIRS} ) 26 | 27 | # Preprocessor Definitions 28 | # [C/C++]>[Preprocessor]>[Preprocessor Definitions] 29 | add_definitions( ${PCL_DEFINITIONS} ) 30 | add_definitions( -DPCL_NO_PRECOMPILE ) 31 | 32 | # Additional Library Directories 33 | # [Linker]>[General]>[Additional Library Directories] 34 | link_directories( ${PCL_LIBRARY_DIRS} ) 35 | 36 | # 可按下面的格式添加自己的源文件 37 | add_executable( sdk_pointcloud sdk_pointcloud.cpp) 38 | add_custom_command( TARGET sdk_pointcloud POST_BUILD ${KinectSDK2_COMMANDS} ) 39 | set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "sdk_pointcloud" ) 40 | target_link_libraries( sdk_pointcloud ${OpenCV_LIBS} ${KinectSDK2_LIBRARIES} ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES}) 41 | 42 | add_executable( kinect_continuous_acquisition kinect_continuous_acquisition.cpp) 43 | add_custom_command( TARGET kinect_continuous_acquisition POST_BUILD ${KinectSDK2_COMMANDS} ) 44 | set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "kinect_continuous_acquisition" ) 45 | target_link_libraries( kinect_continuous_acquisition ${OpenCV_LIBS} ${KinectSDK2_LIBRARIES} ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES}) 46 | -------------------------------------------------------------------------------- /Samples/FindKInectSDK2.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # FindKinectSDK2 3 | # -------------- 4 | # 5 | # Find Kinect for Windows SDK v2 (Kinect SDK v2) include dirs, library dirs, libraries 6 | # 7 | # Use this module by invoking find_package with the form:: 8 | # 9 | # find_package( KinectSDK2 [REQUIRED] ) 10 | # 11 | # Results for users are reported in following variables:: 12 | # 13 | # KinectSDK2_FOUND - Return "TRUE" when Kinect SDK v2 found. Otherwise, Return "FALSE". 14 | # KinectSDK2_INCLUDE_DIRS - Kinect SDK v2 include directories. (${KinectSDK2_DIR}/inc) 15 | # KinectSDK2_LIBRARY_DIRS - Kinect SDK v2 library directories. (${KinectSDK2_DIR}/Lib/x86 or ${KinectSDK2_DIR}/Lib/x64) 16 | # 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.)) 17 | # 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.) 18 | # 19 | # This module reads hints about search locations from following environment variables:: 20 | # 21 | # KINECTSDK20_DIR - Kinect SDK v2 root directory. (This environment variable has been set by installer of Kinect SDK v2.) 22 | # 23 | # CMake entries:: 24 | # 25 | # KinectSDK2_DIR - Kinect SDK v2 root directory. (Default $ENV{KINECTSDK20_DIR}) 26 | # KinectSDK2_FACE - Check the box when using Face or HDFace features. (Default uncheck) 27 | # KinectSDK2_FUSION - Check the box when using Fusion features. (Default uncheck) 28 | # KinectSDK2_VGB - Check the box when using Visual Gesture Builder features. (Default uncheck) 29 | # 30 | # Example to find Kinect SDK v2:: 31 | # 32 | # cmake_minimum_required( VERSION 2.8 ) 33 | # 34 | # project( project ) 35 | # add_executable( project main.cpp ) 36 | # set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "project" ) 37 | # 38 | # # Find package using this module. 39 | # find_package( KinectSDK2 REQUIRED ) 40 | # 41 | # if(KinectSDK2_FOUND) 42 | # # [C/C++]>[General]>[Additional Include Directories] 43 | # include_directories( ${KinectSDK2_INCLUDE_DIRS} ) 44 | # 45 | # # [Linker]>[General]>[Additional Library Directories] 46 | # link_directories( ${KinectSDK2_LIBRARY_DIRS} ) 47 | # 48 | # # [Linker]>[Input]>[Additional Dependencies] 49 | # target_link_libraries( project ${KinectSDK2_LIBRARIES} ) 50 | # 51 | # # [Build Events]>[Post-Build Event]>[Command Line] 52 | # add_custom_command( TARGET project POST_BUILD ${KinectSDK2_COMMANDS} ) 53 | # endif() 54 | # 55 | # ============================================================================= 56 | # 57 | # Copyright (c) 2016 Tsukasa SUGIURA 58 | # Distributed under the MIT License. 59 | # 60 | # 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: 61 | # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 62 | # 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. 63 | # 64 | # ============================================================================= 65 | 66 | ##### Utility ##### 67 | 68 | # Check Directory Macro 69 | macro(CHECK_DIR _DIR) 70 | if(NOT EXISTS "${${_DIR}}") 71 | message(WARNING "Directory \"${${_DIR}}\" not found.") 72 | set(KinectSDK2_FOUND FALSE) 73 | unset(_DIR) 74 | endif() 75 | endmacro() 76 | 77 | # Check Files Macro 78 | macro(CHECK_FILES _FILES _DIR) 79 | set(_MISSING_FILES) 80 | foreach(_FILE ${${_FILES}}) 81 | if(NOT EXISTS "${_FILE}") 82 | get_filename_component(_FILE ${_FILE} NAME) 83 | set(_MISSING_FILES "${_MISSING_FILES}${_FILE}, ") 84 | endif() 85 | endforeach() 86 | if(_MISSING_FILES) 87 | message(WARNING "In directory \"${${_DIR}}\" not found files: ${_MISSING_FILES}") 88 | set(KinectSDK2_FOUND FALSE) 89 | unset(_FILES) 90 | endif() 91 | endmacro() 92 | 93 | # Target Platform 94 | set(TARGET_PLATFORM) 95 | if(NOT CMAKE_CL_64) 96 | set(TARGET_PLATFORM x86) 97 | else() 98 | set(TARGET_PLATFORM x64) 99 | endif() 100 | 101 | ##### Find Kinect SDK v2 ##### 102 | 103 | # Found 104 | set(KinectSDK2_FOUND TRUE) 105 | if(MSVC_VERSION LESS 1700) 106 | message(WARNING "Kinect for Windows SDK v2 supported Visual Studio 2012 or later.") 107 | set(KinectSDK2_FOUND FALSE) 108 | endif() 109 | 110 | # Options 111 | option(KinectSDK2_FACE "Face and HDFace features" FALSE) 112 | option(KinectSDK2_FUSION "Fusion features" FALSE) 113 | option(KinectSDK2_VGB "Visual Gesture Builder features" FALSE) 114 | 115 | # Root Directoty 116 | set(KinectSDK2_DIR) 117 | if(KinectSDK2_FOUND) 118 | set(KinectSDK2_DIR $ENV{KINECTSDK20_DIR} CACHE PATH "Kinect for Windows SDK v2 Install Path." FORCE) 119 | check_dir(KinectSDK2_DIR) 120 | endif() 121 | 122 | # Include Directories 123 | set(KinectSDK2_INCLUDE_DIRS) 124 | if(KinectSDK2_FOUND) 125 | set(KinectSDK2_INCLUDE_DIRS ${KinectSDK2_DIR}/inc) 126 | check_dir(KinectSDK2_INCLUDE_DIRS) 127 | endif() 128 | 129 | # Library Directories 130 | set(KinectSDK2_LIBRARY_DIRS) 131 | if(KinectSDK2_FOUND) 132 | set(KinectSDK2_LIBRARY_DIRS ${KinectSDK2_DIR}/Lib/${TARGET_PLATFORM}) 133 | check_dir(KinectSDK2_LIBRARY_DIRS) 134 | endif() 135 | 136 | # Dependencies 137 | set(KinectSDK2_LIBRARIES) 138 | if(KinectSDK2_FOUND) 139 | set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARY_DIRS}/Kinect20.lib) 140 | 141 | if(KinectSDK2_FACE) 142 | set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Face.lib) 143 | endif() 144 | 145 | if(KinectSDK2_FUSION) 146 | set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.Fusion.lib) 147 | endif() 148 | 149 | if(KinectSDK2_VGB) 150 | set(KinectSDK2_LIBRARIES ${KinectSDK2_LIBRARIES};${KinectSDK2_LIBRARY_DIRS}/Kinect20.VisualGestureBuilder.lib) 151 | endif() 152 | 153 | check_files(KinectSDK2_LIBRARIES KinectSDK2_LIBRARY_DIRS) 154 | endif() 155 | 156 | # Custom Commands 157 | set(KinectSDK2_COMMANDS) 158 | if(KinectSDK2_FOUND) 159 | if(KinectSDK2_FACE) 160 | set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Face/${TARGET_PLATFORM}) 161 | check_dir(KinectSDK2_REDIST_DIR) 162 | list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL) 163 | endif() 164 | 165 | if(KinectSDK2_FUSION) 166 | set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/Fusion/${TARGET_PLATFORM}) 167 | check_dir(KinectSDK2_REDIST_DIR) 168 | list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL) 169 | endif() 170 | 171 | if(KinectSDK2_VGB) 172 | set(KinectSDK2_REDIST_DIR ${KinectSDK2_DIR}/Redist/VGB/${TARGET_PLATFORM}) 173 | check_dir(KinectSDK2_REDIST_DIR) 174 | list(APPEND KinectSDK2_COMMANDS COMMAND xcopy "${KinectSDK2_REDIST_DIR}" "$(OutDir)" /e /y /i /r > NUL) 175 | endif() 176 | 177 | # Empty Commands 178 | if(NOT KinectSDK2_COMMANDS) 179 | set(KinectSDK2_COMMANDS COMMAND) 180 | endif() 181 | endif() 182 | 183 | message(STATUS "KinectSDK2_FOUND : ${KinectSDK2_FOUND}") -------------------------------------------------------------------------------- /Samples/kinect_continuous_acquisition.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YufengLii/Kinect-v2-Tutorial/de15547776bf44cc6731b9ffe21d4a8d3301f957/Samples/kinect_continuous_acquisition.cpp -------------------------------------------------------------------------------- /Samples/sdk_pointcloud.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YufengLii/Kinect-v2-Tutorial/de15547776bf44cc6731b9ffe21d4a8d3301f957/Samples/sdk_pointcloud.cpp --------------------------------------------------------------------------------