Repository: elliotwoods/ofxKinectForWindows2 Branch: master Commit: ce6e3a924854 Files: 81 Total size: 223.1 KB Directory structure: gitextract_6bj2llpn/ ├── .gitignore ├── README.md ├── addon_config.mk ├── example/ │ ├── addons.make │ ├── example.sln │ ├── example.vcxproj │ ├── example.vcxproj.filters │ ├── icon.rc │ └── src/ │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── exampleBodyIndexColor/ │ ├── addons.make │ ├── exampleBodyIndexColor.sln │ ├── exampleBodyIndexColor.vcxproj │ ├── exampleBodyIndexColor.vcxproj.filters │ ├── icon.rc │ └── src/ │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── exampleBodyIndexShader/ │ ├── addons.make │ ├── example-bodyIndex.sln │ ├── example-bodyIndex.vcxproj │ ├── example-bodyIndex.vcxproj.filters │ ├── icon.rc │ └── src/ │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── exampleDepthMeshShader/ │ ├── README.md │ ├── addons.make │ ├── exampleDepthMeshShader.sln │ ├── exampleDepthMeshShader.vcxproj │ ├── exampleDepthMeshShader.vcxproj.filters │ ├── icon.rc │ └── src/ │ ├── MeshUtils.h │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── exampleDepthToCameraTable/ │ ├── addons.make │ ├── exampleDepthToCameraTable.sln │ ├── exampleDepthToCameraTable.vcxproj │ ├── exampleDepthToCameraTable.vcxproj.filters │ ├── icon.rc │ └── src/ │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── exampleWithGui/ │ ├── addons.make │ ├── example.sln │ ├── example.vcxproj │ ├── example.vcxproj.filters │ ├── icon.rc │ ├── src/ │ │ ├── main.cpp │ │ ├── ofApp.cpp │ │ └── ofApp.h │ └── ~AutoRecover.example.vcxproj ├── ofxKinectForWindows2.props ├── ofxKinectForWindows2Lib/ │ ├── ofxKinectForWindows2Lib.vcxproj │ └── ofxKinectForWindows2Lib.vcxproj.filters └── src/ ├── ofxKinectForWindows2/ │ ├── Data/ │ │ ├── Body.cpp │ │ ├── Body.h │ │ ├── Joint.cpp │ │ └── Joint.h │ ├── Device.cpp │ ├── Device.h │ ├── Source/ │ │ ├── Base.h │ │ ├── BaseImage.cpp │ │ ├── BaseImage.h │ │ ├── Body.cpp │ │ ├── Body.h │ │ ├── BodyIndex.cpp │ │ ├── BodyIndex.h │ │ ├── Color.cpp │ │ ├── Color.h │ │ ├── Depth.cpp │ │ ├── Depth.h │ │ ├── Infrared.cpp │ │ ├── Infrared.h │ │ ├── LongExposureInfraRed.cpp │ │ └── LongExposureInfrared.h │ ├── Utils.cpp │ └── Utils.h └── ofxKinectForWindows2.h ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ libs/ docs/ *.depend *.layout *.mode*v3 *.pbxuser *.app* *.DS_* ._*.* .svn/ obj/ bin/ build/ !data/ xcuserdata/ ipch/ *.suo *.opensdf *.vcxproj.user *.db *.opendb *.obj *.tlog *.sdf *.pdb *.idb *.pch Debug/ Release/ *~.xml !exampleDepthMeshShader/bin/data/ ================================================ FILE: README.md ================================================ ofxKinectForWindows2 ==================== ![exampleWithGui](https://raw.github.com/elliotwoods/ofxKinectForWindows2/master/screenshots/exampleWithGui.png) Implementation of Kinect For Windows v2 API using COM (not KinectCommonBridge) ## Important notes The current version is designed for the upcoming oF 0.10.0 available from GitHub, and works with Visual Studio 2015 (it is not compatible with non-windows platforms). - If you are working with an 0.9.x release, please use the [`0.9.0` tag](https://github.com/elliotwoods/ofxKinectForWindows2/tree/0.9.0) - If you are working with an 0.8.x release, please use the [`0.8.4` branch](https://github.com/elliotwoods/ofxKinectForWindows2/tree/0.8.4) ## Features Currently lets you: * Grab all the image streams (color, depth, IR, long exposure IR, body index) * Generate a 3D ofMesh (point cloud or stitched mesh) with texture coordinates * Track bodies (skeleton points, bone maps) * Transfer coordinates Currently doesn't support: * Audio * Some remapping functions ## License MIT License http://en.wikipedia.org/wiki/MIT_License ## Usage First install the [Kinect for Windows SDK 2.0](https://www.microsoft.com/en-gb/download/details.aspx?id=44561) installed __(you will need to restart after installing this before all system paths are correctly set)__. Try the examples to see if they build and run. Then try with your own project: 1. Make your project with Project Generator, but do __not__ select ofxKinectForWindows2 as an addon at this stage 2. Open the solution, and add the ofxKinectForWindows2Lib.vcxproj to your solution (right click on the Solution and choose `Add > Existing Project...`) 3. In `Property Manager` (open it from `View -> Other Windows -> Property Manager`), right click on your project to select `Add Existing Property Sheet...` and select the `ofxKinectForWindows2.props` file. 4. Go back to `Solution Explorer`, right click on your project (e.g. 'mySketch') and select 'Add Reference...', and add a reference to `ofxKinectForWindows2Lib`. ### Alternative Usage with OF Project Generator This method requires the [OF nightly build](http://ci.openframeworks.cc/nightlybuilds.html) of Project Generator. It will not work with the Project Generator from OF 0.9.8 or earlier. 1. Make your project with Project Generator, **including** the ofxKinectForWindows2 addon, and open in IDE (Visual Studio 2015) 2. In `Property Manager` (open it from `View -> Other Windows -> Property Manager`), right click on your project to select `Add Existing Property Sheet...` and select the `ofxKinectForWindows2.props` file. ## Notes 0. The depth image comes in as 'RAW' mm values (i'm not amplifying the values), so it may appear dark. Look closely :) 1. This addon does not ship with any libraries, it'll look locally on your system for them 2. You'll need to get a copy of the Kinect v2 SDK (i'm testing with v1404 April release) # Troubleshooting ## Can't find `Kinect.h` or `ofxKinectForWindows2.h` First, please check that you have the Kinect SDK installed. The `Kinect.h` file should be here on your drive: ![Kinect SDK includes](https://github.com/elliotwoods/ofxKinectForWindows2/blob/master/screenshots/KinectSDKIncludes.PNG?raw=true) Second check that one of the examples shipped with ofxKinectForWindows2 builds and runs. Third please make sure you're using standard paths, e.g.: ``` addons/ofxKinectForWindows2 apps/myAppFolder/myApp/myApp.sln ``` **If you're using your own path structure then ofxKinectForWindows2 may not work.** Check that your Solution Explorer has the right settings, e.g.: ![Solution Explorer](https://github.com/elliotwoods/ofxKinectForWindows2/blob/master/screenshots/SolutionExplorer.PNG?raw=true) Check that the `.props` file has been added correctly, e.g.: ![Property Manager](https://github.com/elliotwoods/ofxKinectForWindows2/blob/master/screenshots/PropertyManager.PNG?raw=true) ## Make sure the file path to your project isn't too long. If you encounter errors like `The specified task executable CL.exe could not be run` (or similarly ambiguous errors) it may be that the path to your project is too long for Visual Studio to compile (e.g. if your `openFrameworks` folder is in a subfolder on your Desktop). While there are many solutions to making a shorter path, one easy solution is to move your openFrameworks root directory to something like `C:\of`. [reference](https://github.com/elliotwoods/ofxKinectForWindows2/issues/72). ## Platform This addon should work with both x86 and x64 platform settings. However, I'm mostly testing with x64 so I'd suggest you use that if you're having issues. Try changing the platfrom setting near the top of the Visual Studio window if you are having troubles. ================================================ FILE: addon_config.mk ================================================ # All variables and this file are optional, if they are not present the PG and the # makefiles will try to parse the correct values from the file system. # # Variables that specify exclusions can use % as a wildcard to specify that anything in # that position will match. A partial path can also be specified to, for example, exclude # a whole folder from the parsed paths from the file system # # Variables can be specified using = or += # = will clear the contents of that variable both specified from the file or the ones parsed # from the file system # += will add the values to the previous ones in the file or the ones parsed from the file # system # # The PG can be used to detect errors in this file, just create a new project with this addon # and the PG will write to the console the kind of error and in which line it is meta: # ADDON_NAME = # ADDON_DESCRIPTION = # ADDON_AUTHOR = # ADDON_TAGS = # ADDON_URL = common: # dependencies with other addons, a list of them separated by spaces # or use += in several lines # ADDON_DEPENDENCIES = # include search paths, this will be usually parsed from the file system # but if the addon or addon libraries need special search paths they can be # specified here separated by spaces or one per line using += # any special flag that should be passed to the compiler when using this # addon # ADDON_CFLAGS = # any special flag that should be passed to the linker when using this # addon, also used for system libraries with -lname # ADDON_LDFLAGS = # linux only, any library that should be included in the project using # pkg-config # ADDON_PKG_CONFIG_LIBRARIES = # osx/iOS only, any framework that should be included in the project # ADDON_FRAMEWORKS = # source files, these will be usually parsed from the file system looking # in the src folders in libs and the root of the addon. if your addon needs # to include files in different places or a different set of files per platform # they can be specified here # ADDON_SOURCES = # some addons need resources to be copied to the bin/data folder of the project # specify here any files that need to be copied, you can use wildcards like * and ? # ADDON_DATA = # when parsing the file system looking for libraries exclude this for all or # a specific platform # ADDON_LIBS_EXCLUDE = vs: ADDON_INCLUDES += $(KINECTSDK20_DIR)inc ADDON_LIBS += $(KINECTSDK20_DIR)Lib\$(PlatformTarget)\Kinect20.lib linux64: # binary libraries, these will be usually parsed from the file system but some # libraries need to passed to the linker in a specific order/ # # For example in the ofxOpenCV addon we do something like this: # # ADDON_LIBS = # ADDON_LIBS += libs/opencv/lib/linuxarmv6l/libopencv_legacy.a # ADDON_LIBS += libs/opencv/lib/linuxarmv6l/libopencv_calib3d.a # ... linux: win_cb: linuxarmv6l: linuxarmv7l: android/armeabi: android/armeabi-v7a: ================================================ FILE: example/addons.make ================================================ ================================================ FILE: example/example.sln ================================================ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example", "example.vcxproj", "{7FD42DF7-442E-479A-BA76-D0022F99702A}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\..\libs\openFrameworksCompiled\project\vs\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ofxKinectForWindows2Lib", "..\ofxKinectForWindows2Lib\ofxKinectForWindows2Lib.vcxproj", "{F6008D6A-6D39-4B68-840E-E7AC8ED855DA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.ActiveCfg = Debug|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.Build.0 = Debug|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.ActiveCfg = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.Build.0 = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.ActiveCfg = Release|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.Build.0 = Release|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.ActiveCfg = Release|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.Build.0 = Release|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.ActiveCfg = Debug|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.Build.0 = Debug|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.ActiveCfg = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.Build.0 = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.ActiveCfg = Release|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.Build.0 = Release|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.ActiveCfg = Release|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.Build.0 = Release|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|Win32.ActiveCfg = Debug|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|Win32.Build.0 = Debug|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|x64.ActiveCfg = Debug|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|x64.Build.0 = Debug|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|Win32.ActiveCfg = Release|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|Win32.Build.0 = Release|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|x64.ActiveCfg = Release|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal ================================================ FILE: example/example.vcxproj ================================================  Debug Win32 Debug x64 Release Win32 Release x64 {7FD42DF7-442E-479A-BA76-D0022F99702A} Win32Proj example 10.0 Application Unicode v142 Application Unicode v142 Application Unicode true v142 Application Unicode true v142 bin\ obj\$(Configuration)\ $(ProjectName)_debug true true $(ProjectName)_debug true true bin\ obj\$(Configuration)\ false false Disabled true EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 EditAndContinue ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) Disabled EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 ProgramDatabase ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) {5837595d-aca9-485c-8e76-729040ce4b0b} {f6008d6a-6d39-4b68-840e-e7ac8ed855da} /D_DEBUG %(AdditionalOptions) /D_DEBUG %(AdditionalOptions) ================================================ FILE: example/example.vcxproj.filters ================================================ src src {d8376475-7454-4a24-b08a-aac121d3ad6f} src ================================================ FILE: example/icon.rc ================================================ // Icon Resource Definition #define MAIN_ICON 102 #if defined(_DEBUG) MAIN_ICON ICON "..\..\..\libs\openFrameworksCompiled\project\vs\icon_debug.ico" #else MAIN_ICON ICON "..\..\..\libs\openFrameworksCompiled\project\vs\icon.ico" #endif ================================================ FILE: example/src/main.cpp ================================================ #include "ofApp.h" //======================================================================== int main( ){ ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context // this kicks off the running of my app // can be OF_WINDOW or OF_FULLSCREEN // pass in width and height too: ofRunApp(new ofApp()); } ================================================ FILE: example/src/ofApp.cpp ================================================ #include "ofApp.h" int previewWidth = 640; int previewHeight = 480; //-------------------------------------------------------------- void ofApp::setup(){ kinect.open(); kinect.initDepthSource(); kinect.initColorSource(); kinect.initInfraredSource(); kinect.initBodySource(); kinect.initBodyIndexSource(); ofSetWindowShape(previewWidth * 2, previewHeight * 2); } //-------------------------------------------------------------- void ofApp::update(){ kinect.update(); //-- //Getting joint positions (skeleton tracking) //-- // { auto bodies = kinect.getBodySource()->getBodies(); for (auto body : bodies) { for (auto joint : body.joints) { //now do something with the joints } } } // //-- //-- //Getting bones (connected joints) //-- // { // Note that for this we need a reference of which joints are connected to each other. // We call this the 'boneAtlas', and you can ask for a reference to this atlas whenever you like auto bodies = kinect.getBodySource()->getBodies(); auto boneAtlas = ofxKinectForWindows2::Data::Body::getBonesAtlas(); for (auto body : bodies) { for (auto bone : boneAtlas) { auto firstJointInBone = body.joints[bone.first]; auto secondJointInBone = body.joints[bone.second]; //now do something with the joints } } } // //-- } //-------------------------------------------------------------- void ofApp::draw(){ kinect.getDepthSource()->draw(0, 0, previewWidth, previewHeight); // note that the depth texture is RAW so may appear dark // Color is at 1920x1080 instead of 512x424 so we should fix aspect ratio float colorHeight = previewWidth * (kinect.getColorSource()->getHeight() / kinect.getColorSource()->getWidth()); float colorTop = (previewHeight - colorHeight) / 2.0; kinect.getColorSource()->draw(previewWidth, 0 + colorTop, previewWidth, colorHeight); kinect.getBodySource()->drawProjected(previewWidth, 0 + colorTop, previewWidth, colorHeight); kinect.getInfraredSource()->draw(0, previewHeight, previewWidth, previewHeight); kinect.getBodyIndexSource()->draw(previewWidth, previewHeight, previewWidth, previewHeight); kinect.getBodySource()->drawProjected(previewWidth, previewHeight, previewWidth, previewHeight, ofxKFW2::ProjectionCoordinates::DepthCamera); } //-------------------------------------------------------------- void ofApp::keyPressed(int key){ } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ } ================================================ FILE: example/src/ofApp.h ================================================ #pragma once #include "ofxKinectForWindows2.h" #include "ofMain.h" class ofApp : public ofBaseApp{ public: void setup(); void update(); void draw(); void keyPressed(int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); ofxKFW2::Device kinect; }; ================================================ FILE: exampleBodyIndexColor/addons.make ================================================ ================================================ FILE: exampleBodyIndexColor/exampleBodyIndexColor.sln ================================================ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exampleBodyIndexColor", "exampleBodyIndexColor.vcxproj", "{7FD42DF7-442E-479A-BA76-D0022F99702A}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\..\libs\openFrameworksCompiled\project\vs\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ofxKinectForWindows2Lib", "..\ofxKinectForWindows2Lib\ofxKinectForWindows2Lib.vcxproj", "{F6008D6A-6D39-4B68-840E-E7AC8ED855DA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.ActiveCfg = Debug|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.Build.0 = Debug|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.ActiveCfg = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.Build.0 = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.ActiveCfg = Release|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.Build.0 = Release|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.ActiveCfg = Release|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.Build.0 = Release|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.ActiveCfg = Debug|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.Build.0 = Debug|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.ActiveCfg = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.Build.0 = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.ActiveCfg = Release|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.Build.0 = Release|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.ActiveCfg = Release|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.Build.0 = Release|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|Win32.ActiveCfg = Debug|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|Win32.Build.0 = Debug|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|x64.ActiveCfg = Debug|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|x64.Build.0 = Debug|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|Win32.ActiveCfg = Release|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|Win32.Build.0 = Release|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|x64.ActiveCfg = Release|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal ================================================ FILE: exampleBodyIndexColor/exampleBodyIndexColor.vcxproj ================================================  Debug Win32 Debug x64 Release Win32 Release x64 {7FD42DF7-442E-479A-BA76-D0022F99702A} Win32Proj exampleBodyIndexColor Application Unicode v140 Application Unicode v140 Application Unicode true v140 Application Unicode true v140 bin\ obj\$(Configuration)\ $(ProjectName)_debug true true bin\ obj\$(Configuration)\ $(ProjectName)_debug true true bin\ obj\$(Configuration)\ false bin\ obj\$(Configuration)\ false Disabled EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 %(AdditionalIncludeDirectories) CompileAsCpp true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) Disabled EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 %(AdditionalIncludeDirectories) CompileAsCpp true true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 %(AdditionalIncludeDirectories) CompileAsCpp true false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 %(AdditionalIncludeDirectories) CompileAsCpp false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) {5837595d-aca9-485c-8e76-729040ce4b0b} {f6008d6a-6d39-4b68-840e-e7ac8ed855da} /D_DEBUG %(AdditionalOptions) /D_DEBUG %(AdditionalOptions) $(OF_ROOT)\libs\openFrameworksCompiled\project\vs ================================================ FILE: exampleBodyIndexColor/exampleBodyIndexColor.vcxproj.filters ================================================ src src {d8376475-7454-4a24-b08a-aac121d3ad6f} src ================================================ FILE: exampleBodyIndexColor/icon.rc ================================================ // Icon Resource Definition #define MAIN_ICON 102 #if defined(_DEBUG) MAIN_ICON ICON "icon_debug.ico" #else MAIN_ICON ICON "icon.ico" #endif ================================================ FILE: exampleBodyIndexColor/src/main.cpp ================================================ #include "ofApp.h" //======================================================================== int main( ){ ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context // this kicks off the running of my app // can be OF_WINDOW or OF_FULLSCREEN // pass in width and height too: ofRunApp(new ofApp()); } ================================================ FILE: exampleBodyIndexColor/src/ofApp.cpp ================================================ // This example shows how to work with the BodyIndex image in order to create // a green screen effect. Note that this isn't super fast, but is helpful // in understanding how the different image types & coordinate spaces work // together. If you need performance, you will probably want to do this with shaders! #include "ofApp.h" #define DEPTH_WIDTH 512 #define DEPTH_HEIGHT 424 #define DEPTH_SIZE DEPTH_WIDTH * DEPTH_HEIGHT #define COLOR_WIDTH 1920 #define COLOR_HEIGHT 1080 //-------------------------------------------------------------- void ofApp::setup() { ofSetWindowShape(DEPTH_WIDTH * 2, DEPTH_HEIGHT); kinect.open(); kinect.initDepthSource(); kinect.initColorSource(); kinect.initInfraredSource(); kinect.initBodySource(); kinect.initBodyIndexSource(); if (kinect.getSensor()->get_CoordinateMapper(&coordinateMapper) < 0) { ofLogError() << "Could not acquire CoordinateMapper!"; } numBodiesTracked = 0; bHaveAllStreams = false; bodyIndexImg.allocate(DEPTH_WIDTH, DEPTH_HEIGHT, OF_IMAGE_COLOR); foregroundImg.allocate(DEPTH_WIDTH, DEPTH_HEIGHT, OF_IMAGE_COLOR); colorCoords.resize(DEPTH_WIDTH * DEPTH_HEIGHT); } //-------------------------------------------------------------- void ofApp::update() { kinect.update(); // Get pixel data auto& depthPix = kinect.getDepthSource()->getPixels(); auto& bodyIndexPix = kinect.getBodyIndexSource()->getPixels(); auto& colorPix = kinect.getColorSource()->getPixels(); // Make sure there's some data here, otherwise the cam probably isn't ready yet if (!depthPix.size() || !bodyIndexPix.size() || !colorPix.size()) { bHaveAllStreams = false; return; } else { bHaveAllStreams = true; } // Count number of tracked bodies numBodiesTracked = 0; auto& bodies = kinect.getBodySource()->getBodies(); for (auto& body : bodies) { if (body.tracked) { numBodiesTracked++; } } // Do the depth space -> color space mapping // More info here: // https://msdn.microsoft.com/en-us/library/windowspreview.kinect.coordinatemapper.mapdepthframetocolorspace.aspx // https://msdn.microsoft.com/en-us/library/dn785530.aspx coordinateMapper->MapDepthFrameToColorSpace(DEPTH_SIZE, (UINT16*) depthPix.getPixels(), DEPTH_SIZE, (ColorSpacePoint*) colorCoords.data()); // Loop through the depth image for (int y = 0; y < DEPTH_HEIGHT; y++) { for (int x = 0; x < DEPTH_WIDTH; x++) { int index = (y * DEPTH_WIDTH) + x; bodyIndexImg.setColor(x, y, ofColor::white); foregroundImg.setColor(x, y, ofColor::white); // This is the check to see if a given pixel is inside a tracked body or part of the background. // If it's part of a body, the value will be that body's id (0-5), or will > 5 if it's // part of the background // More info here: // https://msdn.microsoft.com/en-us/library/windowspreview.kinect.bodyindexframe.aspx float val = bodyIndexPix[index]; if (val >= bodies.size()) { continue; } // Give each tracked body a color value so we can tell // them apart on screen ofColor c = ofColor::fromHsb(val * 255 / bodies.size(), 200, 255); bodyIndexImg.setColor(x, y, c); // For a given (x,y) in the depth image, lets look up where that point would be // in the color image ofVec2f mappedCoord = colorCoords[index]; // Mapped x/y coordinates in the color can come out as floats since it's not a 1:1 mapping // between depth <-> color spaces i.e. a pixel at (100, 100) in the depth image could map // to (405.84637, 238.13828) in color space // So round the x/y values down to ints so that we can look up the nearest pixel mappedCoord.x = floor(mappedCoord.x); mappedCoord.y = floor(mappedCoord.y); // Make sure it's within some sane bounds, and skip it otherwise if (mappedCoord.x < 0 || mappedCoord.y < 0 || mappedCoord.x >= COLOR_WIDTH || mappedCoord.y >= COLOR_HEIGHT) { continue; } // Finally, pull the color from the color image based on its coords in // the depth image foregroundImg.setColor(x, y, colorPix.getColor(mappedCoord.x, mappedCoord.y)); } } // Update the images since we manipulated the pixels manually. This uploads to the // pixel data to the texture on the GPU so it can get drawn to screen bodyIndexImg.update(); foregroundImg.update(); } //-------------------------------------------------------------- void ofApp::draw() { bodyIndexImg.draw(0, 0); foregroundImg.draw(DEPTH_WIDTH, 0); stringstream ss; ss << "fps : " << ofGetFrameRate() << endl; ss << "Tracked bodies: " << numBodiesTracked; if (!bHaveAllStreams) ss << endl << "Not all streams detected!"; ofDrawBitmapStringHighlight(ss.str(), 20, 20); } //-------------------------------------------------------------- void ofApp::keyPressed(int key){ } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseEntered(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseExited(int x, int y){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ } ================================================ FILE: exampleBodyIndexColor/src/ofApp.h ================================================ #pragma once #include "ofxKinectForWindows2.h" #include "ofMain.h" class ofApp : public ofBaseApp{ public: void setup(); void update(); void draw(); void keyPressed(int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void mouseEntered(int x, int y); void mouseExited(int x, int y); void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); ofxKFW2::Device kinect; ICoordinateMapper* coordinateMapper; ofImage bodyIndexImg, foregroundImg; vector colorCoords; int numBodiesTracked; bool bHaveAllStreams; }; ================================================ FILE: exampleBodyIndexShader/addons.make ================================================ ================================================ FILE: exampleBodyIndexShader/example-bodyIndex.sln ================================================ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\..\libs\openFrameworksCompiled\project\vs\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ofxKinectForWindows2Lib", "..\ofxKinectForWindows2Lib\ofxKinectForWindows2Lib.vcxproj", "{F6008D6A-6D39-4B68-840E-E7AC8ED855DA}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-bodyIndex", "example-bodyIndex.vcxproj", "{7FD42DF7-442E-479A-BA76-D0022F99702A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.ActiveCfg = Debug|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.Build.0 = Debug|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.ActiveCfg = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.Build.0 = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.ActiveCfg = Release|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.Build.0 = Release|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.ActiveCfg = Release|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|Win32.ActiveCfg = Debug|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|Win32.Build.0 = Debug|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|x64.ActiveCfg = Debug|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|x64.Build.0 = Debug|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|Win32.ActiveCfg = Release|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|Win32.Build.0 = Release|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|x64.ActiveCfg = Release|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|x64.Build.0 = Release|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.ActiveCfg = Debug|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.Build.0 = Debug|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.ActiveCfg = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.Build.0 = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.ActiveCfg = Release|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.Build.0 = Release|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.ActiveCfg = Release|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal ================================================ FILE: exampleBodyIndexShader/example-bodyIndex.vcxproj ================================================  Debug Win32 Debug x64 Release Win32 Release x64 {7FD42DF7-442E-479A-BA76-D0022F99702A} Win32Proj example Application Unicode v140 Application Unicode v140 Application Unicode true v140 Application Unicode true v140 bin\ obj\$(Configuration)\ $(ProjectName)_debug true true $(ProjectName)_debug true true bin\ obj\$(Configuration)\ false false Disabled true EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 EditAndContinue ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) Disabled EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 ProgramDatabase ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) {5837595d-aca9-485c-8e76-729040ce4b0b} {f6008d6a-6d39-4b68-840e-e7ac8ed855da} /D_DEBUG %(AdditionalOptions) /D_DEBUG %(AdditionalOptions) ================================================ FILE: exampleBodyIndexShader/example-bodyIndex.vcxproj.filters ================================================  src src {d8376475-7454-4a24-b08a-aac121d3ad6f} {8112424a-9e0b-4e75-931f-a6d5cdf47e1f} {2875c5c0-c98f-40e0-bd5a-23769bd78f9a} src shaders shaders shaders_gl3 shaders_gl3 ================================================ FILE: exampleBodyIndexShader/icon.rc ================================================ // Icon Resource Definition #define MAIN_ICON 102 #if defined(_DEBUG) MAIN_ICON ICON "..\..\..\libs\openFrameworksCompiled\project\vs\icon_debug.ico" #else MAIN_ICON ICON "..\..\..\libs\openFrameworksCompiled\project\vs\icon.ico" #endif ================================================ FILE: exampleBodyIndexShader/src/main.cpp ================================================ #include "ofApp.h" //-------------------------------------------------------------- int main(){ #ifdef USE_PROGRAMMABLE_PIPELINE ofGLWindowSettings settings; settings.setGLVersion(4,3); settings.width = 1024; settings.height = 768; ofCreateWindow(settings); #else ofSetupOpenGL(1024, 768, OF_WINDOW); #endif ofRunApp(new ofApp()); } ================================================ FILE: exampleBodyIndexShader/src/ofApp.cpp ================================================ #include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup(){ kinect.open(); kinect.initDepthSource(); kinect.initColorSource(); kinect.initBodySource(); kinect.initBodyIndexSource(); bStitchFaces = false; bDrawBodies = true; if (ofIsGLProgrammableRenderer()) { shader.load("shaders_gl3/bodyIndex"); } else { shader.load("shaders/bodyIndex"); } } //-------------------------------------------------------------- void ofApp::update(){ kinect.update(); } //-------------------------------------------------------------- void ofApp::draw(){ cam.begin(); ofPushMatrix(); ofScale(100, 100, 100); shader.begin(); shader.setUniform1i("uWidth", kinect.getBodyIndexSource()->getWidth()); if (ofIsGLProgrammableRenderer()) { shader.setUniformTexture("uBodyIndexTex", kinect.getBodyIndexSource()->getTexture(), 1); shader.setUniformTexture("uColorTex", kinect.getColorSource()->getTexture(), 2); } else { // TEMP: Until OF master fixes texture binding for old pipeline. shader.setUniform1i("uBodyIndexTex", 1); kinect.getBodyIndexSource()->getTexture().bind(1); shader.setUniform1i("uColorTex", 2); kinect.getColorSource()->getTexture().bind(2); } ofSetColor(255); ofMesh mesh = kinect.getDepthSource()->getMesh(bStitchFaces, ofxKFW2::Source::Depth::PointCloudOptions::ColorCamera); mesh.draw(); if (!ofIsGLProgrammableRenderer()) { // TEMP: Until OF master fixes texture binding for old pipeline. kinect.getColorSource()->getTexture().unbind(2); kinect.getBodyIndexSource()->getTexture().unbind(1); } shader.end(); if (bDrawBodies) { kinect.getBodySource()->drawWorld(); } ofPopMatrix(); cam.end(); ofSetColor(0); stringstream ss; ss << ofToString(ofGetFrameRate(), 2) << " FPS" << endl; ss << "Stitch [F]aces: " << (bStitchFaces? "ON":"OFF") << endl; ss << "Draw [B]odies: " << (bDrawBodies? "ON":"OFF") << endl; ofDrawBitmapString(ss.str(), 10, 20); } //-------------------------------------------------------------- void ofApp::keyPressed(int key){ switch (key) { case 'b': bDrawBodies ^= 1; break; case 'f': bStitchFaces ^= 1; break; } } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ } ================================================ FILE: exampleBodyIndexShader/src/ofApp.h ================================================ #pragma once #define USE_PROGRAMMABLE_PIPELINE 1 #include "ofxKinectForWindows2.h" #include "ofMain.h" class ofApp : public ofBaseApp{ public: void setup(); void update(); void draw(); void keyPressed(int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); ofxKFW2::Device kinect; ofEasyCam cam; ofShader shader; bool bStitchFaces; bool bDrawBodies; }; ================================================ FILE: exampleDepthMeshShader/README.md ================================================ ofxKinectForWindows2 (exampleDepthMeshShader) ==================== ![exampleDepthMeshShader](screenshots/exampleDepthMeshShader.png) The author of this example and the accompanying shaders are made by Lesley van Hoek\ https://github.com/lshoek ## Description This example showcases how to build a mesh from the depth source using shaders. It is able to realize a full-resolution, textured and filtered depth mesh in a steady +/- 1ms on a GTX 1050. This is significantly faster than the `Depth::getDepthMesh()` call, which can quickly become a big bottleneck depending on your application. So this is great if you're looking to get around this! ## How does it work? The vertices, indices and texture coordinates of the (VBO) mesh are generated on the GPU using compute shaders. First, a depth texture is acquired from the Kinect using the `ofxKinectForWindows2` API. This is then sent to a shader program that transforms each pixel to camera space and writes them to a vertex buffer. This is fast because this data resides on the GPU, so it does not have to be copied to/from the CPU. Another shader program filters the mesh by manipulating the mesh indices in the index buffer. The color frame texture coordinates are also queried from `ofxKinectForWindows2` and sent directly to the texture coordinate buffer of the mesh. ## Notes If you have any questions or issues running this you're welcome to report them here or to me. ## License MIT License http://en.wikipedia.org/wiki/MIT_License ================================================ FILE: exampleDepthMeshShader/addons.make ================================================ ================================================ FILE: exampleDepthMeshShader/exampleDepthMeshShader.sln ================================================ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30114.105 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exampleDepthMeshShader", "exampleDepthMeshShader.vcxproj", "{7FD42DF7-442E-479A-BA76-D0022F99702A}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\..\libs\openFrameworksCompiled\project\vs\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ofxKinectForWindows2Lib", "..\ofxKinectForWindows2Lib\ofxKinectForWindows2Lib.vcxproj", "{F6008D6A-6D39-4B68-840E-E7AC8ED855DA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.ActiveCfg = Debug|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.Build.0 = Debug|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.ActiveCfg = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.Build.0 = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.ActiveCfg = Release|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.Build.0 = Release|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.ActiveCfg = Release|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.Build.0 = Release|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.ActiveCfg = Debug|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.Build.0 = Debug|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.ActiveCfg = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.Build.0 = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.ActiveCfg = Release|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.Build.0 = Release|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.ActiveCfg = Release|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.Build.0 = Release|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|Win32.ActiveCfg = Debug|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|Win32.Build.0 = Debug|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|x64.ActiveCfg = Debug|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|x64.Build.0 = Debug|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|Win32.ActiveCfg = Release|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|Win32.Build.0 = Release|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|x64.ActiveCfg = Release|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4C20F4FB-30B0-45D7-B223-78E22E27E7FC} EndGlobalSection EndGlobal ================================================ FILE: exampleDepthMeshShader/exampleDepthMeshShader.vcxproj ================================================  Debug Win32 Debug x64 Release Win32 Release x64 {7FD42DF7-442E-479A-BA76-D0022F99702A} Win32Proj exampleDepthMeshShader 10.0 Application Unicode v140 Application Unicode v140 Application Unicode true v140 Application Unicode true v140 bin\ obj\$(Configuration)\ $(ProjectName)_debug true true bin\ obj\$(Configuration)\ $(ProjectName)_debug true true bin\ obj\$(Configuration)\ false bin\ obj\$(Configuration)\ false Disabled EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 %(AdditionalIncludeDirectories) CompileAsCpp true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) Disabled EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 %(AdditionalIncludeDirectories) CompileAsCpp true true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 %(AdditionalIncludeDirectories) CompileAsCpp true false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 %(AdditionalIncludeDirectories) CompileAsCpp false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) {5837595d-aca9-485c-8e76-729040ce4b0b} {f6008d6a-6d39-4b68-840e-e7ac8ed855da} /D_DEBUG %(AdditionalOptions) /D_DEBUG %(AdditionalOptions) $(OF_ROOT)\libs\openFrameworksCompiled\project\vs ================================================ FILE: exampleDepthMeshShader/exampleDepthMeshShader.vcxproj.filters ================================================ src src {d8376475-7454-4a24-b08a-aac121d3ad6f} {184c96a8-f47b-482b-a0f2-764d8d7e6429} src src ================================================ FILE: exampleDepthMeshShader/icon.rc ================================================ // Icon Resource Definition #define MAIN_ICON 102 #if defined(_DEBUG) MAIN_ICON ICON "icon_debug.ico" #else MAIN_ICON ICON "icon.ico" #endif ================================================ FILE: exampleDepthMeshShader/src/MeshUtils.h ================================================ #include "ofMesh.h" // uses normalized texcoords static ofMesh gridMesh(int w, int h, float scale) { ofMesh mesh; mesh.setMode(OF_PRIMITIVE_TRIANGLES); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { float x_mesh = x * scale; float y_mesh = y * scale; mesh.addVertex(glm::vec3(x_mesh, y_mesh, 0)); mesh.addTexCoord(glm::vec2((float)x / (float)w, (float)y / (float)h)); } } for (int y = 0; y < h - 1; y++) { for (int x = 0; x < w - 1; x++) { mesh.addIndex(x + y * w); // a mesh.addIndex((x + 1) + (y + 1) * w); // c mesh.addIndex(x + (y + 1) * w); // d mesh.addIndex(x + y * w); // a mesh.addIndex((x + 1) + y * w); // b mesh.addIndex((x + 1) + (y + 1) * w); // c } } return mesh; } ================================================ FILE: exampleDepthMeshShader/src/main.cpp ================================================ #include "ofApp.h" //======================================================================== int main() { ofGLFWWindowSettings settings; settings.setGLVersion(4, 5); settings.setSize(1024, 768); ofCreateWindow(settings); ofRunApp(new ofApp()); } ================================================ FILE: exampleDepthMeshShader/src/ofApp.cpp ================================================ /* Author: Lesley van Hoek https://github.com/lshoek */ #include "ofApp.h" #include "MeshUtils.h" void ofApp::setup() { ofSetVerticalSync(true); ofLogToConsole(); ofBackground(0x222222); ofSetHexColor(0xffffff); ofFill(); kinect.open(); bIsKinectOpen = kinect.isOpen(); ofLog() << (bIsKinectOpen ? "Kinect found!" : "Kinect not found!"); if (bIsKinectOpen) { kinect.initColorSource(); kinect.initDepthSource(); kinect.getSensor()->get_CoordinateMapper(&coordMapper); } else { OF_EXIT_APP(0); } // pointcloud options pointCloudOpts.textureCoordinates = ofxKFW2::Source::Depth::PointCloudOptions::TextureCoordinates::ColorCamera; pointCloudOpts.facesMaxLength = 0.0003f; pointCloudOpts.stitchFaces = true; pointCloudOpts.steps = 1; // init cam cam.setNearClip(0.0001f); cam.setFarClip(10.0f); cam.setPosition(0, 0, -.01f); cam.lookAt(glm::vec3(0)); cam.setUpAxis(glm::vec3(0, 1, 0)); cam.setAutoDistance(false); meshShader.setupShaderFromFile(GL_COMPUTE_SHADER, "shaders/mesh.glsl"); meshShader.linkProgram(); indexShader.setupShaderFromFile(GL_COMPUTE_SHADER, "shaders/indices.glsl"); indexShader.linkProgram(); } void ofApp::update() { kinect.update(); if (kinect.isFrameNew()) { auto depthSrc = kinect.getDepthSource(); auto colorSrc = kinect.getColorSource(); // update textures colorTexture = colorSrc->getTexture(); depthTexture = depthSrc->getTexture(); const int width = depthSrc->getWidth(); const int height = depthSrc->getHeight(); auto frameSize = width * height; const int w = depthSrc->getWidth() / pointCloudOpts.steps; const int h = depthSrc->getHeight() / pointCloudOpts.steps; meshWidth = w; meshHeight = h; // do all this once if (!bMeshDataInitialized) { // get depth-to-camera transform table depthSrc->getDepthToWorldTable(depthToCameraSpaceTable); // start with a base grid depthVboMesh = gridMesh(w, h, 1.0f); // allocate buffers depthToCameraSpaceBuffer.allocate(); depthToCameraSpaceBuffer.setData(frameSize * sizeof(glm::vec2), depthToCameraSpaceTable.getData(), GL_STATIC_READ); vertexBuffer.allocate(w * h * sizeof(glm::vec4), GL_DYNAMIC_DRAW); indexBuffer.allocate(w * h * 6 * sizeof(int), GL_DYNAMIC_DRAW); // set buffers to vbo mesh (vec4 vertices) depthVboMesh.getVbo().setVertexBuffer(vertexBuffer, 4, 0); depthVboMesh.getVbo().setIndexBuffer(indexBuffer); // bind buffers (binding 2 is for depth tex) depthToCameraSpaceBuffer.bindBase(GL_SHADER_STORAGE_BUFFER, 0); depthVboMesh.getVbo().getVertexBuffer().bindBase(GL_SHADER_STORAGE_BUFFER, 1); depthVboMesh.getVbo().getIndexBuffer().bindBase(GL_SHADER_STORAGE_BUFFER, 3); ofLog() << "\nverts: " << depthVboMesh.getNumVertices() << "\nindices:" << depthVboMesh.getNumIndices(); bMeshDataInitialized = true; } // start timing here uint64_t start; start = ofGetElapsedTimeMillis(); // update color-in-depth table depthSrc->getColorInDepthFrameMapping(colorToDepthSpaceTable); depthVboMesh.getVbo().updateTexCoordData((glm::vec2*) &colorToDepthSpaceTable[0], w * h); // update points depthTexture.bindAsImage(2, GL_READ_ONLY); meshShader.begin(); meshShader.setUniform1i("steps", pointCloudOpts.steps); meshShader.setUniform2f("size", glm::vec2(w, h)); meshShader.setUniform2f("size_full", glm::vec2(width, height)); meshShader.dispatchCompute(w/32, h/32, 1); meshShader.end(); depthTexture.unbind(); // update indices indexShader.begin(); indexShader.setUniform1f("faces_maxlen", pointCloudOpts.facesMaxLength); indexShader.setUniform2f("size", glm::vec2(w, h)); indexShader.dispatchCompute(w/32, h/32, 1); indexShader.end(); // end timer gpuMeshUpdateTimer = ofGetElapsedTimeMillis() - start; // Compare other approaches if (bCompareMeshUpdates) { start = ofGetElapsedTimeMillis(); depthMesh = kinect.getDepthSource()->getMesh(pointCloudOpts); cpuMeshUpdateTimer = ofGetElapsedTimeMillis() - start; } } } void ofApp::draw() { ofSetHexColor(0xffffff); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glPrimitiveRestartIndex(0xffffffff); cam.begin(); ofPushMatrix(); // with texture if (bFull) { bool bTex = colorTexture.isAllocated(); if (bTex) { colorTexture.setTextureWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER); colorTexture.bind(); } depthVboMesh.draw(); if (bTex) { colorTexture.unbind(); } } // wireframe and points if (bWireFrame) { depthVboMesh.draw(ofPolyRenderMode::OF_MESH_WIREFRAME); } if (bPoints) { depthVboMesh.draw(ofPolyRenderMode::OF_MESH_POINTS); } ofPopMatrix(); cam.end(); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); ofSetColor(ofColor::fromHex(0x222222), 0x88);; ofDrawRectangle(0, 0, 512, 128); ofSetHexColor(0x00ffff); ofDrawBitmapString("[f] full mesh, [w] wireframe, [p] points, [t] time cpu mesh", margin, margin); ofDrawBitmapString("cam: " + ofToString(cam.getPosition()), margin, margin * 2); ofDrawBitmapString("fps: " + ofToString(ofGetFrameRate()), margin, margin * 3); ofDrawBitmapString("gpu: " + ofToString(gpuMeshUpdateTimer) + "ms", margin, margin * 4); if (bCompareMeshUpdates) { ofDrawBitmapString("cpu: " + ofToString(cpuMeshUpdateTimer) + "ms", margin, margin * 5); } } void ofApp::keyPressed(int key) { if (key == 'f') { bFull = !bFull; } if (key == 'w') { bWireFrame = !bWireFrame; } if (key == 'p') { bPoints = !bPoints; } if (key == 't') { bCompareMeshUpdates = !bCompareMeshUpdates; } } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseEntered(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseExited(int x, int y){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ } ================================================ FILE: exampleDepthMeshShader/src/ofApp.h ================================================ /* Author: Lesley van Hoek https://github.com/lshoek */ #pragma once #include "ofxKinectForWindows2.h" #include "ofMain.h" class ofApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed(int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void mouseEntered(int x, int y); void mouseExited(int x, int y); void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); ofxKFW2::Device kinect; ofxKFW2::Source::Depth::PointCloudOptions pointCloudOpts; ICoordinateMapper* coordMapper; ofFloatPixels depthToCameraSpaceTable; ofFloatPixels colorToDepthSpaceTable; ofTexture colorTexture; ofTexture depthTexture; ofShader meshShader; ofShader indexShader; ofBufferObject depthToCameraSpaceBuffer; ofBufferObject vertexBuffer; ofBufferObject indexBuffer; ofVboMesh depthVboMesh; ofMesh depthMesh; ofEasyCam cam; uint64_t gpuMeshUpdateTimer; uint64_t cpuMeshUpdateTimer; int meshWidth; int meshHeight; // config bool bFull = true; bool bWireFrame = false; bool bPoints = false; bool bCompareMeshUpdates = false; // app bool bIsKinectOpen = false; bool bMeshDataInitialized = false; const int margin = 20; }; ================================================ FILE: exampleDepthToCameraTable/addons.make ================================================ ================================================ FILE: exampleDepthToCameraTable/exampleDepthToCameraTable.sln ================================================ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exampleDepthToCameraTable", "exampleDepthToCameraTable.vcxproj", "{7FD42DF7-442E-479A-BA76-D0022F99702A}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\..\libs\openFrameworksCompiled\project\vs\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ofxKinectForWindows2Lib", "..\ofxKinectForWindows2Lib\ofxKinectForWindows2Lib.vcxproj", "{F6008D6A-6D39-4B68-840E-E7AC8ED855DA}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ofxCvGuiLib", "..\..\ofxCvGui\ofxCvGuiLib\ofxCvGuiLib.vcxproj", "{6F0DDB4F-4014-4433-919B-9D956C034BAD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.ActiveCfg = Debug|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.Build.0 = Debug|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.ActiveCfg = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.Build.0 = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.ActiveCfg = Release|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.Build.0 = Release|Win32 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.ActiveCfg = Release|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.Build.0 = Release|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.ActiveCfg = Debug|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.Build.0 = Debug|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.ActiveCfg = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.Build.0 = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.ActiveCfg = Release|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.Build.0 = Release|Win32 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.ActiveCfg = Release|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.Build.0 = Release|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|Win32.ActiveCfg = Debug|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|Win32.Build.0 = Debug|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|x64.ActiveCfg = Debug|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|x64.Build.0 = Debug|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|Win32.ActiveCfg = Release|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|Win32.Build.0 = Release|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|x64.ActiveCfg = Release|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|x64.Build.0 = Release|x64 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Debug|Win32.ActiveCfg = Debug|Win32 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Debug|Win32.Build.0 = Debug|Win32 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Debug|x64.ActiveCfg = Debug|x64 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Debug|x64.Build.0 = Debug|x64 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Release|Win32.ActiveCfg = Release|Win32 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Release|Win32.Build.0 = Release|Win32 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Release|x64.ActiveCfg = Release|x64 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal ================================================ FILE: exampleDepthToCameraTable/exampleDepthToCameraTable.vcxproj ================================================  Debug Win32 Debug x64 Release Win32 Release x64 {7FD42DF7-442E-479A-BA76-D0022F99702A} Win32Proj exampleDepthToCameraTable Application Unicode v140 Application Unicode v140 Application Unicode true v140 Application Unicode true v140 bin\ obj\$(Configuration)\ $(ProjectName)_debug true true bin\ obj\$(Configuration)\ $(ProjectName)_debug true true bin\ obj\$(Configuration)\ false bin\ obj\$(Configuration)\ false Disabled EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 %(AdditionalIncludeDirectories) CompileAsCpp true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) Disabled EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 %(AdditionalIncludeDirectories) CompileAsCpp true true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 %(AdditionalIncludeDirectories) CompileAsCpp true false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 %(AdditionalIncludeDirectories) CompileAsCpp false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) {5837595d-aca9-485c-8e76-729040ce4b0b} {6f0ddb4f-4014-4433-919b-9d956c034bad} {f6008d6a-6d39-4b68-840e-e7ac8ed855da} /D_DEBUG %(AdditionalOptions) /D_DEBUG %(AdditionalOptions) $(OF_ROOT)\libs\openFrameworksCompiled\project\vs ================================================ FILE: exampleDepthToCameraTable/exampleDepthToCameraTable.vcxproj.filters ================================================ src src {d8376475-7454-4a24-b08a-aac121d3ad6f} src ================================================ FILE: exampleDepthToCameraTable/icon.rc ================================================ // Icon Resource Definition #define MAIN_ICON 102 #if defined(_DEBUG) MAIN_ICON ICON "icon_debug.ico" #else MAIN_ICON ICON "icon.ico" #endif ================================================ FILE: exampleDepthToCameraTable/src/main.cpp ================================================ #include "ofApp.h" //======================================================================== int main( ){ ofSetupOpenGL(1920,1080,OF_WINDOW); // <-------- setup the GL context // this kicks off the running of my app // can be OF_WINDOW or OF_FULLSCREEN // pass in width and height too: ofRunApp(new ofApp()); } ================================================ FILE: exampleDepthToCameraTable/src/ofApp.cpp ================================================ #include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup(){ //suggest running this in Release only (very slow in Debug) kinect.open(); kinect.initColorSource(); kinect.initDepthSource(); gui.init(); auto mainStrip = gui.addStrip(); mainStrip->setDirection(ofxCvGui::Panels::Groups::Strip::Direction::Vertical); mainStrip->setCellSizes({ 33, 66 }); auto widgets = ofxCvGui::Panels::makeWidgets(); { widgets->addFps(); widgets->addToggle(drawNativeWorld); widgets->addToggle(drawCalculatedWorld); } auto leftStrip = ofxCvGui::Panels::Groups::makeStrip(); mainStrip->add(leftStrip); { leftStrip->add(widgets); leftStrip->add(ofxCvGui::Panels::makeBaseDraws(*kinect.getColorSource(), "Color")); leftStrip->add(ofxCvGui::Panels::makeBaseDraws(*kinect.getDepthSource(), "Depth")); leftStrip->add(ofxCvGui::Panels::makeBaseDraws(depthToWorldPreview, "Depth to World table")); } auto world = ofxCvGui::Panels::makeWorld(); mainStrip->add(world); world->onDrawWorld += [this](ofCamera &) { if (this->drawNativeWorld) { ofPushStyle(); { ofSetColor(ofColor::white); this->nativeWorld.drawVertices(); } ofPopStyle(); } if (this->drawCalculatedWorld) { ofPushStyle(); { ofSetColor(ofColor::red); this->calculatedWorld.drawVertices(); } ofPopStyle(); } }; world->getCamera().setPosition(-1, +1, -2); world->getCamera().lookAt(ofVec3f(0, 0, 3)); world->getCamera().setCursorDrawEnabled(true); } //-------------------------------------------------------------- void ofApp::update(){ kinect.update(); if (kinect.isFrameNew()) { auto depth = kinect.getDepthSource(); //this next part only needs to happen once { //load the depth to world table depth->getDepthToWorldTable(depthToWorldTable); //load it into our preview depthToWorldPreview.loadData(depthToWorldTable); } //get the usual mesh nativeWorld = depth->getMesh(); //build a mesh using the depthToWorldTable { auto size = depth->getWidth() * depth->getHeight(); auto depthPixel = depth->getPixels().getData(); auto depthToWorldRay = (ofVec2f*)depthToWorldTable.getData(); this->calculatedWorld.clear(); for (int i = 0; i < size; i++) { auto z = (float)*depthPixel / 1000.0f; ofVec3f vertex{ depthToWorldRay->x * z, depthToWorldRay->y * z, z }; calculatedWorld.addVertex(vertex); depthPixel++; depthToWorldRay++; } } } } //-------------------------------------------------------------- void ofApp::draw(){ } //-------------------------------------------------------------- void ofApp::keyPressed(int key){ } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseEntered(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseExited(int x, int y){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ } ================================================ FILE: exampleDepthToCameraTable/src/ofApp.h ================================================ #pragma once #include "ofxKinectForWindows2.h" #include "ofxCvGui.h" #include "ofMain.h" class ofApp : public ofBaseApp{ public: void setup(); void update(); void draw(); void keyPressed(int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void mouseEntered(int x, int y); void mouseExited(int x, int y); void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); ofxKinectForWindows2::Device kinect; ofxCvGui::Builder gui; ofFloatPixels depthToWorldTable; ofTexture depthToWorldPreview; ofMesh nativeWorld; ofMesh calculatedWorld; ofParameter drawNativeWorld{ "Draw native world", false }; ofParameter drawCalculatedWorld{ "Draw calculated world", true }; }; ================================================ FILE: exampleWithGui/addons.make ================================================ ================================================ FILE: exampleWithGui/example.sln ================================================ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example", "example.vcxproj", "{7FD42DF7-442E-479A-BA76-D0022F99702A}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\..\libs\openFrameworksCompiled\project\vs\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ofxCvGuiLib", "..\..\..\addons\ofxCvGui\ofxCvGuiLib\ofxCvGuiLib.vcxproj", "{6F0DDB4F-4014-4433-919B-9D956C034BAD}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ofxKinectForWindows2Lib", "..\ofxKinectForWindows2Lib\ofxKinectForWindows2Lib.vcxproj", "{F6008D6A-6D39-4B68-840E-E7AC8ED855DA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.ActiveCfg = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.Build.0 = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.ActiveCfg = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.Build.0 = Debug|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.ActiveCfg = Release|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.Build.0 = Release|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.ActiveCfg = Release|x64 {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.Build.0 = Release|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.ActiveCfg = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.Build.0 = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.ActiveCfg = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.Build.0 = Debug|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.ActiveCfg = Release|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.Build.0 = Release|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.ActiveCfg = Release|x64 {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.Build.0 = Release|x64 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Debug|Win32.ActiveCfg = Debug|x64 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Debug|Win32.Build.0 = Debug|x64 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Debug|x64.ActiveCfg = Debug|x64 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Debug|x64.Build.0 = Debug|x64 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Release|Win32.ActiveCfg = Release|x64 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Release|Win32.Build.0 = Release|x64 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Release|x64.ActiveCfg = Release|x64 {6F0DDB4F-4014-4433-919B-9D956C034BAD}.Release|x64.Build.0 = Release|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|Win32.ActiveCfg = Debug|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|Win32.Build.0 = Debug|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|x64.ActiveCfg = Debug|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Debug|x64.Build.0 = Debug|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|Win32.ActiveCfg = Release|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|Win32.Build.0 = Release|Win32 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|x64.ActiveCfg = Release|x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal ================================================ FILE: exampleWithGui/example.vcxproj ================================================  Debug Win32 Debug x64 Release Win32 Release x64 {7FD42DF7-442E-479A-BA76-D0022F99702A} Win32Proj example 8.1 Application Unicode v140 Application Unicode v140 Application Unicode true v140 Application Unicode true v140 $(SolutionDir)bin\ $(Platform)\$(Configuration)\ $(ProjectName)_debug true true $(ProjectName)_debug true true $(SolutionDir)bin\ $(Platform)\$(Configuration)\ false false Disabled true EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 EditAndContinue ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) %(IgnoreSpecificDefaultLibraries) Disabled EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 ProgramDatabase ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) {5837595d-aca9-485c-8e76-729040ce4b0b} {6f0ddb4f-4014-4433-919b-9d956c034bad} {f6008d6a-6d39-4b68-840e-e7ac8ed855da} /D_DEBUG %(AdditionalOptions) /D_DEBUG %(AdditionalOptions) ================================================ FILE: exampleWithGui/example.vcxproj.filters ================================================ src src {d8376475-7454-4a24-b08a-aac121d3ad6f} src ================================================ FILE: exampleWithGui/icon.rc ================================================ // Icon Resource Definition #define MAIN_ICON 102 #if defined(_DEBUG) MAIN_ICON ICON "..\..\..\libs\openFrameworksCompiled\project\vs\icon_debug.ico" #else MAIN_ICON ICON "..\..\..\libs\openFrameworksCompiled\project\vs\icon.ico" #endif ================================================ FILE: exampleWithGui/src/main.cpp ================================================ #include "ofApp.h" //======================================================================== int main( ){ ofGLFWWindowSettings windowSettings; windowSettings.setGLVersion(3, 2); windowSettings.width = 1920; windowSettings.height = 1080; auto window = ofCreateWindow(windowSettings); ofRunApp(new ofApp()); } ================================================ FILE: exampleWithGui/src/ofApp.cpp ================================================ #include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup(){ kinect.open(); kinect.initDepthSource(); kinect.initColorSource(); kinect.initInfraredSource(); kinect.initBodyIndexSource(); kinect.initBodySource(); gui.init(); //setup a gui panel for the widgets at top-left auto widgets = gui.addWidgets(); widgets->addTitle("ofxKinectForWindows2"); widgets->addFps(); widgets->addMemoryUsage(); //setup a gui panel for the 3D view auto worldView = gui.addWorld("World"); worldView->onDrawWorld += [this](ofCamera &) { this->kinect.drawWorld(); }; //setup a gui panel for every kinect source auto sources = kinect.getSources(); for(auto source : sources) { auto sourceWithTexture = dynamic_pointer_cast(source); if (sourceWithTexture) { auto panel = gui.add(sourceWithTexture->getTexture(), source->getTypeName()); //if it's the colour panel, let's do something special by writing some info on top auto colorSource = dynamic_pointer_cast(source); if (colorSource) { panel->onDraw += [colorSource] (ofxCvGui::DrawArguments &) { stringstream message; message << "Exposure : " << colorSource->getExposure() << "us" << endl; message << "FrameInterval : " << colorSource->getFrameInterval() << "us" << endl; message << "Gain : " << colorSource->getGain() << endl; message << "Gamma : " << colorSource->getGamma() << endl; ofxCvGui::Utils::drawText(message.str(), 20, 60); }; } //if it's the depth panel, set some scaling auto depthSource = dynamic_pointer_cast(source); if (depthSource) { auto style = make_shared(); style->rangeMaximum = 0.25f; panel->setStyle(style); } //if it's the body index panel, let's draw the joints on top auto bodyIndexSource = dynamic_pointer_cast(source); if(bodyIndexSource) { panel->onDrawImage += [this](ofxCvGui::DrawImageArguments & args) { auto bodySource = this->kinect.getBodySource(); const auto & bodies = bodySource->getBodies(); ofPushStyle(); { ofColor color(200, 100, 100); int index = 0; for (const auto & body : bodies) { color.setHueAngle((index * 50) % 360); ofSetColor(color); for (const auto & joint : body.joints) { ofDrawCircle(joint.second.getPositionInDepthMap(), 5); } index++; } } ofPopStyle(); }; } } //add an 'isFrameNew' widget to the panel widgets->addIndicatorBool(source->getTypeName() + " frame new", [source]() { return source->isFrameNew(); }); } //if we press the 'c' key on the World panel, then toggle the camera's cursor. This works best when you fullscreen that panel worldView->onKeyboard += [this, worldView] (ofxCvGui::KeyboardArguments & args) { if (args.action == ofxCvGui::KeyboardArguments::Action::Pressed && args.key =='c') { worldView->getCamera().toggleCursorDrawEnabled(); } }; } //-------------------------------------------------------------- void ofApp::update(){ kinect.update(); mesh = kinect.getDepthSource()->getMesh(true, ofxKinectForWindows2::Source::Depth::PointCloudOptions::TextureCoordinates::ColorCamera); } //-------------------------------------------------------------- void ofApp::draw(){ } //-------------------------------------------------------------- void ofApp::keyPressed(int key){ } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ } ================================================ FILE: exampleWithGui/src/ofApp.h ================================================ #pragma once #include "ofxKinectForWindows2.h" #include "ofxCvGui.h" #include "ofMain.h" class ofApp : public ofBaseApp{ public: void setup(); void update(); void draw(); void keyPressed(int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); ofxKFW2::Device kinect; ofxCvGui::Builder gui; ofMesh mesh; }; ================================================ FILE: exampleWithGui/~AutoRecover.example.vcxproj ================================================  Debug Win32 Debug x64 Release Win32 Release x64 {7FD42DF7-442E-479A-BA76-D0022F99702A} Win32Proj example Application Unicode v110 Application Unicode v120 Application Unicode true v120 Application Unicode true v120 bin\ obj\$(Configuration)\ $(ProjectName)_debug true true $(ProjectName)_debug true true bin\ obj\$(Configuration)\ false false Disabled true EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 EditAndContinue ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) %(IgnoreSpecificDefaultLibraries) Disabled EnableFastChecks %(PreprocessorDefinitions) MultiThreadedDebugDLL Level3 ProgramDatabase ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp true Console false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) false %(PreprocessorDefinitions) MultiThreadedDLL Level3 ..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) CompileAsCpp false false Console true true false %(AdditionalDependencies) %(AdditionalLibraryDirectories) {5837595d-aca9-485c-8e76-729040ce4b0b} {6f0ddb4f-4014-4433-919b-9d956c034bad} {f6008d6a-6d39-4b68-840e-e7ac8ed855da} /D_DEBUG %(AdditionalOptions) /D_DEBUG %(AdditionalOptions) ================================================ FILE: ofxKinectForWindows2.props ================================================  $(KINECTSDK20_DIR)\inc;..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories) $(IntDir)\%(Directory)\ ================================================ FILE: ofxKinectForWindows2Lib/ofxKinectForWindows2Lib.vcxproj ================================================  Debug Win32 Debug x64 Release Win32 Release x64 {F6008D6A-6D39-4B68-840E-E7AC8ED855DA} ofxKinectForWindows2Lib 10.0 StaticLibrary true v142 MultiByte StaticLibrary true v142 MultiByte StaticLibrary false v142 true MultiByte StaticLibrary false v142 true MultiByte $(ProjectName)d Level3 Disabled true false true true kinect20.lib;%(AdditionalDependencies) $(KINECTSDK20_DIR)Lib\x86;%(AdditionalLibraryDirectories) Level3 Disabled true false true kinect20.lib;%(AdditionalDependencies) $(KINECTSDK20_DIR)Lib\x64;%(AdditionalLibraryDirectories) Level3 MaxSpeed true true true true true true true kinect20.lib;%(AdditionalDependencies) $(KINECTSDK20_DIR)Lib\x86;%(AdditionalLibraryDirectories) Level3 MaxSpeed true true true true true true kinect20.lib;%(AdditionalDependencies) $(KINECTSDK20_DIR)Lib\x64;%(AdditionalLibraryDirectories) ================================================ FILE: ofxKinectForWindows2Lib/ofxKinectForWindows2Lib.vcxproj.filters ================================================  {6233ced8-5481-4a0d-a271-976452c0370e} {86806939-f359-440c-b989-432997725320} {ef038ac8-52e4-450d-b04c-489f6aba359a} {eeab42d3-af56-4576-8e45-79e3ea5610f5} src src\ofxKinectForWindows2 src\ofxKinectForWindows2 src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Data src\ofxKinectForWindows2\Data src\ofxKinectForWindows2 src\ofxKinectForWindows2 src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Source src\ofxKinectForWindows2\Data src\ofxKinectForWindows2\Data ================================================ FILE: src/ofxKinectForWindows2/Data/Body.cpp ================================================ #include "Body.h" #include "ofGraphics.h" namespace ofxKinectForWindows2 { namespace Data { //---------- std::vector > * Body::bonesAtlas = 0; //---------- Body::Body() { this->bodyId = -1; this->trackingId = -1; this->tracked = false; this->leftHandState = HandState::HandState_Unknown; this->rightHandState = HandState::HandState_Unknown; } //---------- void Body::drawWorld() const { if (!this->tracked) { return; } const auto & boneAtlas = this->getBonesAtlas(); for(auto & bone : boneAtlas) { try { const auto & firstJoint = this->joints.at(bone.first); const auto & secondJoint = this->joints.at(bone.second); if (firstJoint.getTrackingState() != TrackingState::TrackingState_NotTracked && secondJoint.getTrackingState() != TrackingState::TrackingState_NotTracked) { ofDrawLine(firstJoint.getPosition(), secondJoint.getPosition()); } } catch (...) { } } } //---------- void Body::clear() { joints.clear(); leftHandState = HandState_Unknown; rightHandState = HandState_Unknown; tracked = false; } //---------- Body Body::operator*(const ofMatrix4x4 & transform) const { auto copy = *this; for (auto & joint : copy.joints) { joint.second = joint.second * transform; } return copy; } //---------- const std::vector > & Body::getBonesAtlas() { //if pointer isn't valid, let's initialise the atlas if (!bonesAtlas) { initBonesAtlas(); } return * Body::bonesAtlas; } //---------- void Body::initBonesAtlas() { Body::bonesAtlas = new std::vector >(); #define BONEDEF_ADD(J1, J2) Body::bonesAtlas->push_back( std::make_pair(JointType_ ## J1, JointType_ ## J2) ) // Torso BONEDEF_ADD (Head, Neck); BONEDEF_ADD (Neck, SpineShoulder); BONEDEF_ADD (SpineShoulder, SpineMid); BONEDEF_ADD (SpineMid, SpineBase); BONEDEF_ADD (SpineShoulder, ShoulderRight); BONEDEF_ADD (SpineShoulder, ShoulderLeft); BONEDEF_ADD (SpineBase, HipRight); BONEDEF_ADD (SpineBase, HipLeft); // Right Arm BONEDEF_ADD (ShoulderRight, ElbowRight); BONEDEF_ADD (ElbowRight, WristRight); BONEDEF_ADD (WristRight, HandRight); BONEDEF_ADD (HandRight, HandTipRight); BONEDEF_ADD (WristRight, ThumbRight); // Left Arm BONEDEF_ADD (ShoulderLeft, ElbowLeft); BONEDEF_ADD (ElbowLeft, WristLeft); BONEDEF_ADD (WristLeft, HandLeft); BONEDEF_ADD (HandLeft, HandTipLeft); BONEDEF_ADD (WristLeft, ThumbLeft); // Right Leg BONEDEF_ADD (HipRight, KneeRight); BONEDEF_ADD (KneeRight, AnkleRight); BONEDEF_ADD (AnkleRight, FootRight); // Left Leg BONEDEF_ADD (HipLeft, KneeLeft); BONEDEF_ADD (KneeLeft, AnkleLeft); BONEDEF_ADD (AnkleLeft, FootLeft); #undef BONEDEF_ADD } } } ================================================ FILE: src/ofxKinectForWindows2/Data/Body.h ================================================ #pragma once #include "Joint.h" #include #include #include namespace ofxKinectForWindows2 { namespace Data { class Body { public: Body(); uint8_t bodyId; uint64_t trackingId; bool tracked; HandState leftHandState; HandState rightHandState; std::map joints; std::map activity; void drawWorld() const; void clear(); Body operator*(const ofMatrix4x4 &) const; static const std::vector > & getBonesAtlas(); protected: static void initBonesAtlas(); static std::vector > * bonesAtlas; }; } } ================================================ FILE: src/ofxKinectForWindows2/Data/Joint.cpp ================================================ #include "Joint.h" namespace ofxKinectForWindows2 { namespace Data { //---------- Joint::Joint(const _Joint& joint, const _JointOrientation& jointOrientation, ICoordinateMapper * coordinateMapper) { this->set(joint, jointOrientation, coordinateMapper); } //---------- Joint::Joint(const _Joint& joint, const _JointOrientation& jointOrientation, const ofVec2f & jointInDepthSpace) { this->set(joint, jointOrientation, jointInDepthSpace); } //---------- void Joint::set(const _Joint& joint, const _JointOrientation& jointOrientation, ICoordinateMapper * coordinateMapper) { DepthSpacePoint depthSpacePoint; coordinateMapper->MapCameraPointsToDepthSpace(1, &joint.Position, 1, &depthSpacePoint); ofVec2f positionInDepthMap(depthSpacePoint.X, depthSpacePoint.Y); this->set(joint, jointOrientation, positionInDepthMap); } //---------- void Joint::set(const _Joint& joint, const _JointOrientation& jointOrientation, const ofVec2f & positionInDepthMap) { this->joint = joint; this->positionInWorld.set(joint.Position.X, joint.Position.Y, joint.Position.Z); this->positionInDepthMap = positionInDepthMap; this->type = joint.JointType; this->trackingState = joint.TrackingState; this->jointOrientation = jointOrientation; this->orientation.set(jointOrientation.Orientation.x, jointOrientation.Orientation.y, jointOrientation.Orientation.z, jointOrientation.Orientation.w); } //---------- JointType Joint::getType() const { return type; } //---------- ofVec3f Joint::getPositionInWorld() const { return positionInWorld; } //---------- ofVec2f Joint::getPositionInDepthMap() const { return this->positionInDepthMap; } //---------- ofVec2f Joint::getProjected(ICoordinateMapper * coordinateMapper, ProjectionCoordinates proj) const { switch (proj) { case ColorCamera: { ColorSpacePoint projected = { 0 }; coordinateMapper->MapCameraPointToColorSpace(joint.Position, &projected); return ofVec2f(projected.X, projected.Y); } case DepthCamera: { DepthSpacePoint projected = { 0 }; coordinateMapper->MapCameraPointToDepthSpace(joint.Position, &projected); return ofVec2f(projected.X, projected.Y); } default: return ofVec2f(); } } //---------- ofQuaternion Joint::getOrientation() const { return orientation; } //---------- TrackingState Joint::getTrackingState() const { return trackingState; } //---------- _Joint Joint::getRawJoint() const { return this->joint; } //---------- _JointOrientation Joint::getRawJointOrientation() const { return this->jointOrientation; } //---------- Joint Joint::operator*(const ofMatrix4x4 & transform) const { auto copy = *this; copy.positionInWorld = copy.positionInWorld * transform; ofQuaternion rotationTransform; rotationTransform.set(transform); copy.orientation = copy.orientation * rotationTransform; return copy; } } } ================================================ FILE: src/ofxKinectForWindows2/Data/Joint.h ================================================ #pragma once #define _HAS_STD_BYTE 0 #include "ofVectorMath.h" // If your compiler is complaining that it can't find Kinect.h, then please make sure: // 1) You have installed the Kinect SDK (e.g. v2.0_1409 is the latest version as of October 2015) // 2) You have rebooted since installing the SDK. Some environment variables (e.g. the Kinect SDK folder) are only set after restarting. #include namespace ofxKinectForWindows2 { enum ProjectionCoordinates { DepthCamera, ColorCamera }; namespace Data { class Joint { public: Joint(){} Joint(const _Joint& joint, const _JointOrientation& jointOrientation, ICoordinateMapper *); Joint(const _Joint& joint, const _JointOrientation& jointOrientation, const ofVec2f & positionInDepthMap); void set(const _Joint& joint, const _JointOrientation& jointOrientation, ICoordinateMapper *); void set(const _Joint& joint, const _JointOrientation& jointOrientation, const ofVec2f & positionInDepthMap); JointType getType() const; ofVec3f getPositionInWorld() const; ofVec2f getPositionInDepthMap() const; ofVec3f getPosition() const { return this->getPositionInWorld(); } ofVec2f getProjected(ICoordinateMapper * coordinateMapper, ProjectionCoordinates proj = ColorCamera) const; ofQuaternion getOrientation() const; TrackingState getTrackingState() const; _Joint getRawJoint() const; _JointOrientation getRawJointOrientation() const; Joint operator*(const ofMatrix4x4 &) const; protected: ofVec3f positionInWorld; ofVec2f positionInDepthMap; ofQuaternion orientation; JointType type; TrackingState trackingState; _Joint joint; _JointOrientation jointOrientation; }; } } ================================================ FILE: src/ofxKinectForWindows2/Device.cpp ================================================ #include "Device.h" #include "of3dUtils.h" #include "ofConstants.h" #include "ofGraphics.h" #if OF_VERSION_MAJOR > 0 || OF_VERSION_MINOR >= 10 #include "ofAppGLFWWindow.h" #endif #define CHECK_OPEN if(!this->sensor) { OFXKINECTFORWINDOWS2_ERROR << "Failed : Sensor is not open"; } namespace ofxKinectForWindows2 { //---------- Device::Device() { this->sensor = nullptr; this->reader = nullptr; this->isFrameNewFlag = false; } //---------- Device::~Device() { this->close(); } //---------- void Device::open() { try { if (FAILED(GetDefaultKinectSensor(&this->sensor))) { throw(Exception("Failed to find sensor")); } if (FAILED(this->sensor->Open())) { throw(Exception("Failed to open sensor")); } } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); this->sensor = nullptr; } } //---------- void Device::close() { SafeRelease(this->reader); if (!this->sensor) { return; } //release all sources. this->sources.clear(); this->sensor->Close(); SafeRelease(this->sensor); } //---------- bool Device::isOpen() const { if (!this->sensor) { return false; } BOOLEAN result; if (!FAILED(this->sensor->get_IsOpen(&result))) { return result; } else { OFXKINECTFORWINDOWS2_ERROR << "Failed to check if sensor is open"; return false; } } //---------- void Device::initMultiSource(std::initializer_list frameSourceTypes) { CHECK_OPEN; if (!this->reader) { DWORD enabledFrameSourceTypes = 0; for (auto frameSourceType : frameSourceTypes) { enabledFrameSourceTypes |= frameSourceType; } try { if (!FAILED(this->sensor->OpenMultiSourceFrameReader(enabledFrameSourceTypes, &reader))) { if (enabledFrameSourceTypes & FrameSourceTypes_Color) { this->initSource(false); } if (enabledFrameSourceTypes & FrameSourceTypes_Infrared) { this->initSource(false); } if (enabledFrameSourceTypes & FrameSourceTypes_LongExposureInfrared) { this->initSource(false); } if (enabledFrameSourceTypes & FrameSourceTypes_Depth) { this->initSource(false); } if (enabledFrameSourceTypes & FrameSourceTypes_BodyIndex) { this->initSource(false); } if (enabledFrameSourceTypes & FrameSourceTypes_Body) { this->initSource(false); } } } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } } } //---------- template std::shared_ptr Device::initSource(bool initReader) { CHECK_OPEN; //first check if it already exists { auto source = this->getSource(); if (source) { OFXKINECTFORWINDOWS2_WARNING << "Source of type " << typeid(SourceType).name() << " already initialised."; return source; } } //if not then open it try { auto source = MAKE(SourceType); source->init(this->sensor, initReader); this->sources.push_back(source); return source; } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); return std::shared_ptr(); } } //---------- std::shared_ptr Device::initDepthSource() { return this->initSource(true); } //---------- std::shared_ptr Device::initColorSource() { return this->initSource(true); } //---------- std::shared_ptr Device::initInfraredSource() { return this->initSource(true); } //---------- std::shared_ptr Device::initLongExposureInfraredSource() { return this->initSource(true); } //---------- std::shared_ptr Device::initBodyIndexSource() { return this->initSource(true); } //---------- std::shared_ptr Device::initBodySource() { return this->initSource(true); } //---------- bool Device::releaseMultiSource() { // look for sources initialized with MultiSource (those without their own reader) // and erase them. They are consecutive in the vector auto first = this->sources.begin(); while (first != this->sources.end() && (*first)->hasReader()) first++; if (first == this->sources.end()) { OFXKINECTFORWINDOWS2_WARNING << "No sources initialized with MultiSource."; return false; } auto last = first; while (last != this->sources.end() && !(*last)->hasReader()) last++; this->sources.erase(first, last); return true; } //---------- template bool Device::releaseSource() { CHECK_OPEN; //check if it already exists auto source = this->getSource(); if (source && source->hasReader()) { this->sources.erase(std::remove(this->sources.begin(), this->sources.end(), source), this->sources.end()); return true; } //does not exist OFXKINECTFORWINDOWS2_WARNING << "Source of type " << typeid(SourceType).name() << " not initialised, or in a MultiSource."; return false; } //---------- bool Device::releaseDepthSource() { return this->releaseSource(); } //---------- bool Device::releaseColorSource() { return this->releaseSource(); } //---------- bool Device::releaseInfraredSource() { return this->releaseSource(); } //---------- bool Device::releaseLongExposureInfraredSource() { return this->releaseSource(); } //---------- bool Device::releaseBodyIndexSource() { return this->releaseSource(); } //---------- bool Device::releaseBodySource() { return this->releaseSource(); } //---------- void Device::update() { this->isFrameNewFlag = false; IMultiSourceFrame * frame = NULL; if (this->reader) { try { //acquire frame if (FAILED(this->reader->AcquireLatestFrame(&frame))) { SafeRelease(frame); return; // we often throw here when no new frame is available } } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } } for (auto source : this->sources) { if (frame && !source->hasReader()) source->update(frame); else source->update(); this->isFrameNewFlag |= source->isFrameNew(); } SafeRelease(frame); } //---------- bool Device::isFrameNew() const { return this->isFrameNewFlag; } //---------- const std::vector> & Device::getSources() const { return this->sources; } //---------- std::shared_ptr Device::getDepthSource() const { return this->getSource(); } //---------- std::shared_ptr Device::getColorSource() const { return this->getSource(); } //---------- std::shared_ptr Device::getInfraredSource() const { return this->getSource(); } //---------- std::shared_ptr Device::getLongExposureInfraredSource() const { return this->getSource(); } //---------- std::shared_ptr Device::getBodyIndexSource() const { return this->getSource(); } //---------- std::shared_ptr Device::getBodySource() const { return this->getSource(); } //---------- IKinectSensor * Device::getSensor() { return this->sensor; } //---------- void Device::drawWorld() { auto colorSource = this->getColorSource(); auto depthSource = this->getDepthSource(); auto bodySource = this->getBodySource(); if (!depthSource) { ofLogError("ofxKinectForWindows2::Device::drawPrettyMesh") << "No depth source initialised"; return; } //point cloud { //setup some point cloud properties for kicks bool usePointSize = true; #if OF_VERSION_MAJOR > 0 || OF_VERSION_MINOR >= 10 auto mainWindow = std::static_pointer_cast(ofGetCurrentWindow()); usePointSize = mainWindow ? mainWindow->getSettings().glVersionMajor <= 2 : false; #endif usePointSize = false; if (usePointSize) { glPushAttrib(GL_POINT_BIT); glPointSize(5.0f); glEnable(GL_POINT_SMOOTH); } ofPushStyle(); bool useColor = colorSource.get(); if (useColor) { useColor &= colorSource->getTexture().isAllocated(); } if (useColor) { //bind kinect color camera texture and draw mesh from depth (which has texture coordinates) colorSource->getTexture().bind(); } auto opts = Source::Depth::PointCloudOptions(true, Source::Depth::PointCloudOptions::TextureCoordinates::ColorCamera); auto mesh = depthSource->getMesh(opts); //draw point cloud mesh.drawVertices(); //draw triangles ofSetColor(255, 150); mesh.drawWireframe(); //draw fills faded ofSetColor(255, 50); mesh.drawFaces(); if (useColor) { //unbind colour camera colorSource->getTexture().unbind(); } ofPopStyle(); //clear the point cloud drawing attributes if (usePointSize) { glPopAttrib(); } } //bodies and floor if (bodySource) { bodySource->drawWorld(); ofPushMatrix(); ofRotateDeg(90, 0, 0, 1); ofMultMatrix(bodySource->getFloorTransform()); ofDrawGridPlane(5.0f); ofPopMatrix(); } //draw the view cones of depth and colour cameras ofPushStyle(); ofNoFill(); ofSetLineWidth(2.0f); ofSetColor(100, 200, 100); depthSource->drawFrustum(); if (colorSource) { ofSetColor(200, 100, 100); colorSource->drawFrustum(); } ofPopStyle(); } //---------- void Device::setUseTextures(bool useTexture) { auto sources = this->getSources(); for (auto source : sources) { auto imageSource = std::dynamic_pointer_cast(source); if (imageSource) { imageSource->setUseTexture(useTexture); } } } } ================================================ FILE: src/ofxKinectForWindows2/Device.h ================================================ #pragma once #include "Utils.h" #include "Source/Depth.h" #include "Source/Color.h" #include "Source/Infrared.h" #include "Source/LongExposureInfrared.h" #include "Source/BodyIndex.h" #include "Source/Body.h" #include #include namespace ofxKinectForWindows2 { class Device { public: Device(); virtual ~Device(); void open(); void close(); bool isOpen() const; void initMultiSource(std::initializer_list frameSourceTypes); std::shared_ptr initDepthSource(); std::shared_ptr initColorSource(); std::shared_ptr initInfraredSource(); std::shared_ptr initLongExposureInfraredSource(); std::shared_ptr initBodyIndexSource(); std::shared_ptr initBodySource(); bool releaseMultiSource(); bool releaseDepthSource(); bool releaseColorSource(); bool releaseInfraredSource(); bool releaseLongExposureInfraredSource(); bool releaseBodyIndexSource(); bool releaseBodySource(); void update(); bool isFrameNew() const; template bool hasSource() const { if (this->getSource()) { return true; } else { return false; } } template std::shared_ptr getSource() const { for(auto source : this->sources) { auto castSource = std::dynamic_pointer_cast(source); if (castSource) { return castSource; } } return std::shared_ptr(); } const std::vector> & getSources() const; std::shared_ptr getDepthSource() const; std::shared_ptr getColorSource() const; std::shared_ptr getInfraredSource() const; std::shared_ptr getLongExposureInfraredSource() const; std::shared_ptr getBodyIndexSource() const; std::shared_ptr getBodySource() const; IKinectSensor * getSensor(); void drawWorld(); void setUseTextures(bool); protected: template std::shared_ptr initSource(bool initReader); template bool releaseSource(); IKinectSensor * sensor; IMultiSourceFrameReader * reader; std::vector> sources; bool isFrameNewFlag; }; } ================================================ FILE: src/ofxKinectForWindows2/Source/Base.h ================================================ #pragma once #include #include namespace ofxKinectForWindows2 { namespace Source { class Base { public: virtual std::string getTypeName() const = 0; virtual void init(IKinectSensor *, bool) = 0; virtual void update() = 0; virtual void update(IMultiSourceFrame *) = 0; virtual bool isFrameNew() const = 0; virtual bool hasReader() const = 0; }; } } ================================================ FILE: src/ofxKinectForWindows2/Source/BaseImage.cpp ================================================ #include "BaseImage.h" #include "ofGraphics.h" #include "ofMesh.h" #define CHECK_OPEN if(!this->reader) { OFXKINECTFORWINDOWS2_ERROR << "Failed : Reader is not open"; } namespace ofxKinectForWindows2 { namespace Source { #pragma mark BaseFrame //---------- template BaseFrame::BaseFrame() { this->reader = NULL; this->isFrameNewFlag = false; } //---------- template BaseFrame::~BaseFrame() { SafeRelease(this->reader); } //---------- template void BaseFrame ::init(IKinectSensor * sensor, bool reader) { if (reader) initReader(sensor); } //---------- template bool BaseFrame ::isFrameNew() const { return this->isFrameNewFlag; } //---------- template bool BaseFrame ::hasReader() const { if (this->reader) return true; else return false; } //---------- template void BaseFrame::update() { CHECK_OPEN this->isFrameNewFlag = false; FrameType * frame = NULL; try { //acquire frame if (FAILED(this->reader->AcquireLatestFrame(&frame))) { SafeRelease(frame); return; // we often throw here when no new frame is available } update(frame); } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } SafeRelease(frame); } #pragma mark BaseImage //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS ofMesh BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::frustumMesh; //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::BaseImage() { this->useTexture = true; this->diagonalFieldOfView = 0.0f; this->horizontalFieldOfView = 0.0f; this->verticalFieldOfView = 0.0f; this->lastFrameTime = 0; if (this->frustumMesh.getVertices().empty()) { this->frustumMesh.addVertex(ofVec3f(0.0f, 0.0f, 0.0f)); this->frustumMesh.addVertex(ofVec3f(-1.0f, -1.0f, 1.0f)); this->frustumMesh.addVertex(ofVec3f(-1.0f, +1.0f, 1.0f)); this->frustumMesh.addVertex(ofVec3f(+1.0f, +1.0f, 1.0f)); this->frustumMesh.addVertex(ofVec3f(+1.0f, -1.0f, 1.0f)); const ofIndexType indices[6] = {0, 1, 2, 3, 4, 1}; this->frustumMesh.addIndices(indices, 6); this->frustumMesh.setMode(ofPrimitiveMode::OF_PRIMITIVE_TRIANGLE_FAN); } } //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS ofTexture & BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::getTexture() { return this->texture; } //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS const ofTexture & BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::getTexture() const { return this->texture; } //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS void BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::setUseTexture(bool useTexture) { this->useTexture = useTexture; if (!useTexture) { this->texture.clear(); } } //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS ofPixels_ & BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::getPixels() { return this->pixels; } //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS const ofPixels_ & BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::getPixels() const { return this->pixels; } //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS void BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::draw(float x, float y) const { this->texture.draw(x, y); } //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS void BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::draw(float x, float y, float width, float height) const { this->texture.draw(x, y, width, height); } //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS float BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::getWidth() const { return this->pixels.getWidth(); } //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS float BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::getHeight() const { return this->pixels.getHeight(); } //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS float BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::getDiagonalFieldOfView() const { return this->diagonalFieldOfView; } //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS float BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::getHorizontalFieldOfView() const { return this->horizontalFieldOfView; } //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS float BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::getVerticalFieldOfView() const { return this->verticalFieldOfView; } //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS void BaseImage OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::drawFrustum() const { ofPushMatrix(); ofScale(tan(DEG_TO_RAD * this->getHorizontalFieldOfView() / 2.0f), tan(DEG_TO_RAD * this->getVerticalFieldOfView() / 2.0f), 1.0f); if (ofGetStyle().bFill) { this->frustumMesh.drawFaces(); } else { this->frustumMesh.drawWireframe(); } ofPopMatrix(); } #pragma mark BaseImageSimple //---------- template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS void BaseImageSimple OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM::update(FrameType * frame) { this->isFrameNewFlag = true; IFrameDescription * frameDescription = NULL; try { INT64 relativeTime = 0; if (FAILED(frame->get_RelativeTime(&relativeTime))) { throw Exception("Failed to get relative time"); } if (relativeTime > this->lastFrameTime) { relativeTime = this->lastFrameTime; } else { return; } //allocate pixels and texture if we need to if (FAILED(frame->get_FrameDescription(&frameDescription))) { throw Exception("Failed to get frame description"); } int width, height; if (FAILED(frameDescription->get_Width(&width)) || FAILED(frameDescription->get_Height(&height))) { throw Exception("Failed to get width and height of frame"); } if (width != this->pixels.getWidth() || height != this->texture.getHeight()) { this->pixels.allocate(width, height, OF_IMAGE_GRAYSCALE); this->texture.allocate(this->pixels); } //update local assets if (FAILED(frame->CopyFrameDataToArray(width * height, this->pixels.getData()))) { throw Exception("Couldn't pull pixel buffer "); } if (this->useTexture) { this->texture.loadData(this->pixels); } //update field of view if (FAILED(frameDescription->get_HorizontalFieldOfView(&this->horizontalFieldOfView))) { throw Exception("Failed to get horizonal field of view"); } if (FAILED(frameDescription->get_VerticalFieldOfView(&this->verticalFieldOfView))) { throw Exception("Failed to get vertical field of view"); } if (FAILED(frameDescription->get_DiagonalFieldOfView(&this->diagonalFieldOfView))) { throw Exception("Failed to get diagonal field of view"); } } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } SafeRelease(frameDescription); } //--------- template class BaseImageSimple; template class BaseImageSimple; template class BaseImageSimple; template class BaseImageSimple; template class BaseImage; template class BaseImage; template class BaseImage; template class BaseImage; template class BaseImage; template class BaseFrame; } } ================================================ FILE: src/ofxKinectForWindows2/Source/BaseImage.h ================================================ #pragma once #include "../Utils.h" #include "ofBaseTypes.h" #include "ofTexture.h" #include "ofPixels.h" #include "Base.h" namespace ofxKinectForWindows2 { namespace Source { #define OFXKFW2_BaseImageSimple_TEMPLATE_ARGS #define OFXKFW2_BaseImageSimple_TEMPLATE_ARGS_TRIM template class BaseFrame : public Base { public: BaseFrame(); ~BaseFrame(); virtual void update(FrameType *) = 0; void init(IKinectSensor *, bool) override; void update() override; bool isFrameNew() const override; bool hasReader() const override; protected: virtual void initReader(IKinectSensor *) = 0; ReaderType * reader; bool isFrameNewFlag; }; template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS class BaseImage : public BaseFrame, public ofBaseHasTexture, public ofBaseHasPixels_, public ofBaseDraws { public: BaseImage(); //ofBaseHasTexture ofTexture & getTexture() override; const ofTexture & getTexture() const override; void setUseTexture(bool) override; bool isUsingTexture() const override { return useTexture; } //ofBaseHasPixels ofPixels_ & getPixels() override; const ofPixels_ & getPixels() const override; //ofBaseDraws void draw(float, float) const override; void draw(float, float, float, float) const override; float getWidth() const override; float getHeight() const override; float getDiagonalFieldOfView() const; float getHorizontalFieldOfView() const; float getVerticalFieldOfView() const; void drawFrustum() const; protected: static ofMesh frustumMesh; bool useTexture; ofTexture texture; ofPixels_ pixels; float diagonalFieldOfView; float horizontalFieldOfView; float verticalFieldOfView; long lastFrameTime; }; template OFXKFW2_BaseImageSimple_TEMPLATE_ARGS class BaseImageSimple : public BaseImage { public: void update(FrameType *) override; }; }; } ================================================ FILE: src/ofxKinectForWindows2/Source/Body.cpp ================================================ #include "Body.h" #include "ofGraphics.h" #include "ofNode.h" namespace ofxKinectForWindows2 { namespace Source { //---------- std::string Body::getTypeName() const { return "Body"; } //---------- const std::vector & Body::getBodies() const { return bodies; } //---------- ofMatrix4x4 Body::getFloorTransform() { ofNode helper; helper.lookAt(ofVec3f(floorClipPlane.x, floorClipPlane.z, -floorClipPlane.y)); helper.boom(-floorClipPlane.w); ofMatrix4x4 transform = glm::inverse(helper.getGlobalTransformMatrix()); return transform; } //---------- void Body::initReader(IKinectSensor * sensor) { this->reader = NULL; try { IBodyFrameSource * source = NULL; if (FAILED(sensor->get_BodyFrameSource(&source))) { throw(Exception("Failed to initialise BodyFrame source")); } if (FAILED(source->OpenReader(&this->reader))) { throw(Exception("Failed to initialise BodyFrame reader")); } SafeRelease(source); } catch (std::exception & e) { SafeRelease(this->reader); throw (e); } } //---------- void Body::init(IKinectSensor * sensor, bool reader) { try { BaseFrame::init(sensor, reader); if (FAILED(sensor->get_CoordinateMapper(&this->coordinateMapper))) { throw(Exception("Failed to acquire coordinate mapper")); } bodies.resize(BODY_COUNT); } catch (std::exception & e) { SafeRelease(this->reader); throw (e); } } //---------- void Body::update(IMultiSourceFrame * multiFrame) { this->isFrameNewFlag = false; IBodyFrame * frame = NULL; IBodyFrameReference * reference; try { //acquire frame if (FAILED(multiFrame->get_BodyFrameReference(&reference))) { return; // we often throw here when no new frame is available } if (FAILED(reference->AcquireFrame(&frame))) { return; // we often throw here when no new frame is available } update(frame); } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } SafeRelease(reference); SafeRelease(frame); } //---------- void Body::update(IBodyFrame * frame) { this->isFrameNewFlag = true; IFrameDescription * frameDescription = NULL; try { INT64 nTime = 0; if (FAILED(frame->get_RelativeTime(&nTime))) { throw Exception("Failed to get relative time"); } if (FAILED(frame->get_FloorClipPlane(&floorClipPlane))) { throw(Exception("Failed to get floor clip plane")); } IBody* ppBodies[BODY_COUNT] = {0}; if (FAILED(frame->GetAndRefreshBodyData(_countof(ppBodies), ppBodies))) { throw Exception("Failed to refresh body data"); } for (int i = 0; i < BODY_COUNT; ++i) { auto & body = bodies[i]; body.clear(); IBody* pBody = ppBodies[i]; if (pBody) { BOOLEAN bTracked = false; if (FAILED(pBody->get_IsTracked(&bTracked))) { throw Exception("Failed to get tracking status"); } body.tracked = bTracked; body.bodyId = i; if (bTracked) { // retrieve tracking id UINT64 trackingId = -1; if (FAILED(pBody->get_TrackingId(&trackingId))) { throw Exception("Failed to get tracking id"); } body.trackingId = trackingId; // retrieve joint position & orientation _Joint joints[JointType_Count]; _JointOrientation jointsOrient[JointType_Count]; if (FAILED(pBody->GetJoints(JointType_Count, joints))){ throw Exception("Failed to get joints"); } if (FAILED(pBody->GetJointOrientations(JointType_Count, jointsOrient))){ throw Exception("Failed to get joints orientation"); } for (int j = 0; j < JointType_Count; ++j) { body.joints[joints[j].JointType] = Data::Joint(joints[j], jointsOrient[j], this->getCoordinateMapper()); } // retrieve hand states HandState leftHandState = HandState_Unknown; HandState rightHandState = HandState_Unknown; if (FAILED(pBody->get_HandLeftState(&leftHandState))){ throw Exception("Failed to get left hand state"); } if (FAILED(pBody->get_HandRightState(&rightHandState))){ throw Exception("Failed to get right hand state"); } body.leftHandState = leftHandState; body.rightHandState = rightHandState; } } } for (int i = 0; i < _countof(ppBodies); ++i) { SafeRelease(ppBodies[i]); } } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } SafeRelease(frameDescription); } //---------- std::map Body::getProjectedJoints(int bodyIdx, ProjectionCoordinates proj) { std::map result; const auto & body = bodies[bodyIdx]; if (!body.tracked) return result; for (auto & joint : body.joints) { ofVec2f & position = result[joint.second.getType()] = ofVec2f(); TrackingState state = joint.second.getTrackingState(); if (state == TrackingState_NotTracked) { continue; } position.set(joint.second.getProjected(coordinateMapper, proj)); } return result; } //---------- void Body::drawProjected(int x, int y, int width, int height, ProjectionCoordinates proj) { ofPushStyle(); int w, h; switch (proj) { case ColorCamera: w = 1920; h = 1080; break; case DepthCamera: w = 512; h = 424; break; } const auto & bonesAtlas = Data::Body::getBonesAtlas(); for (auto & body : bodies) { if (!body.tracked) continue; std::map jntsProj; for (auto & j : body.joints) { ofVec2f & p = jntsProj[j.second.getType()] = ofVec2f(); TrackingState state = j.second.getTrackingState(); if (state == TrackingState_NotTracked) continue; p.set(j.second.getProjected(coordinateMapper, proj)); p.x = x + p.x / w * width; p.y = y + p.y / h * height; int radius = (state == TrackingState_Inferred) ? 2 : 8; ofSetColor(0, 255, 0); ofDrawCircle(p.x, p.y, radius); } for (auto & bone : bonesAtlas) { drawProjectedBone(body.joints, jntsProj, bone.first, bone.second); } drawProjectedHand(body.leftHandState, jntsProj[JointType_HandLeft]); drawProjectedHand(body.rightHandState, jntsProj[JointType_HandRight]); } ofPopStyle(); } //---------- void Body::drawWorld() { auto bodies = this->getBodies(); int bodyIndex = 0; for (auto & body : bodies) { //draw black lines ofPushStyle(); ofSetLineWidth(10.0f); ofSetColor(0); body.drawWorld(); //draw coloured lines ofSetLineWidth(8.0f); ofColor col(200, 100, 100); col.setHue(255.0f / this->getBodies().size() * bodyIndex); ofSetColor(col); body.drawWorld(); ofPopStyle(); bodyIndex++; } } //---------- ICoordinateMapper * Body::getCoordinateMapper() { return this->coordinateMapper; } //---------- void Body::drawProjectedBone(std::map & pJoints, std::map & pJointPoints, JointType joint0, JointType joint1){ TrackingState ts1 = pJoints[joint0].getTrackingState(); TrackingState ts2 = pJoints[joint1].getTrackingState(); if (ts1 == TrackingState_NotTracked || ts2 == TrackingState_NotTracked) return; if (ts1 == TrackingState_Inferred && ts2 == TrackingState_Inferred) return; int thickness = 5; ofSetColor(0, 255, 0); if (ts1 == TrackingState_Inferred || ts2 == TrackingState_Inferred) { thickness = 2; ofSetColor(0, 128, 0); } ofSetLineWidth(thickness); ofDrawLine(pJointPoints[joint0], pJointPoints[joint1]); } //---------- void Body::drawProjectedHand(HandState handState, ofVec2f & handPos){ ofColor color; switch (handState) { case HandState_Unknown: case HandState_NotTracked: return; case HandState_Open: color = ofColor(0, 255, 0, 80); break; case HandState_Closed : color = ofColor(255, 255, 0, 80); break; case HandState_Lasso: color = ofColor(0, 255, 255, 80); break; } ofEnableAlphaBlending(); ofSetColor(color); ofDrawCircle(handPos, 50); ofDisableAlphaBlending(); } } } ================================================ FILE: src/ofxKinectForWindows2/Source/Body.h ================================================ #pragma once #include "ofVectorMath.h" #include "BaseImage.h" #include "../Utils.h" #include "../Data/Body.h" #include "../Data/Joint.h" namespace ofxKinectForWindows2 { namespace Source { // ------- class Body : public BaseFrame { public: std::string getTypeName() const override; void init(IKinectSensor *, bool) override; void update(IBodyFrame *) override; void update(IMultiSourceFrame *) override; void drawProjected(int x, int y, int width, int height, ProjectionCoordinates proj = ColorCamera); void drawWorld(); ICoordinateMapper * getCoordinateMapper(); const std::vector & getBodies() const; std::map getProjectedJoints(int bodyIdx, ProjectionCoordinates proj = ColorCamera); const Vector4 getFloorClipPlane() { return floorClipPlane; } ofMatrix4x4 getFloorTransform(); static void drawProjectedBone(std::map & pJoints, std::map & pJointPoints, JointType joint0, JointType joint1); static void drawProjectedHand(HandState handState, ofVec2f & handPos); protected: void initReader(IKinectSensor *) override; ICoordinateMapper * coordinateMapper; Vector4 floorClipPlane; std::vector bodies; }; } } ================================================ FILE: src/ofxKinectForWindows2/Source/BodyIndex.cpp ================================================ #include "BodyIndex.h" namespace ofxKinectForWindows2 { namespace Source { //---------- std::string BodyIndex::getTypeName() const { return "BodyIndex"; } //---------- void BodyIndex::initReader(IKinectSensor * sensor) { this->reader = NULL; try { IBodyIndexFrameSource * source = NULL; if (FAILED(sensor->get_BodyIndexFrameSource(&source))) { throw(Exception("Failed to initialise BodyIndex source")); } if (FAILED(source->OpenReader(&this->reader))) { throw(Exception("Failed to initialise BodyIndex reader")); } SafeRelease(source); } catch (std::exception & e) { SafeRelease(this->reader); throw (e); } } //---------- void BodyIndex::update(IMultiSourceFrame * multiFrame) { this->isFrameNewFlag = false; IBodyIndexFrame * frame = NULL; IBodyIndexFrameReference * reference; try { //acquire frame if (FAILED(multiFrame->get_BodyIndexFrameReference(&reference))) { return; // we often throw here when no new frame is available } if (FAILED(reference->AcquireFrame(&frame))) { return; // we often throw here when no new frame is available } BaseImageSimple::update(frame); } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } SafeRelease(reference); SafeRelease(frame); } } } ================================================ FILE: src/ofxKinectForWindows2/Source/BodyIndex.h ================================================ #pragma once #include "BaseImage.h" namespace ofxKinectForWindows2 { namespace Source { class BodyIndex : public BaseImageSimple { public: std::string getTypeName() const override; void update(IMultiSourceFrame *) override; protected: void initReader(IKinectSensor *) override; }; } } ================================================ FILE: src/ofxKinectForWindows2/Source/Color.cpp ================================================ #include "Color.h" namespace ofxKinectForWindows2 { namespace Source { //---------- Color::Color() { } //---------- std::string Color::getTypeName() const { return "Color"; } //---------- void Color::initReader(IKinectSensor * sensor) { this->reader = NULL; try { IColorFrameSource * source = NULL; if (FAILED(sensor->get_ColorFrameSource(&source))) { throw(Exception("Failed to initialise Color source")); } if (FAILED(source->OpenReader(&this->reader))) { throw(Exception("Failed to initialise Color reader")); } SafeRelease(source); } catch (std::exception & e) { SafeRelease(this->reader); throw (e); } } //---------- void Color::update(IColorFrame * frame) { this->isFrameNewFlag = true; IFrameDescription * frameDescription = NULL; try { //allocate pixels and texture if we need to if (FAILED(frame->get_FrameDescription(&frameDescription))) { throw Exception("Failed to get frame description"); } int width, height; if (FAILED(frameDescription->get_Width(&width)) || FAILED(frameDescription->get_Height(&height))) { throw Exception("Failed to get width and height of frame"); } if (width != this->pixels.getWidth() || height != this->texture.getHeight()) { this->pixels.allocate(width, height, OF_IMAGE_COLOR_ALPHA); this->texture.allocate(this->pixels); } //update local rgba image if (this->rgbaPixelsEnabled) { if (FAILED(frame->CopyConvertedFrameDataToArray(this->pixels.size(), this->pixels.getData(), ColorImageFormat_Rgba))) { throw Exception("Couldn't pull pixel buffer to converted rgba pixels"); } if (this->useTexture) { this->texture.loadData(this->pixels); } } //update yuv if (this->yuvPixelsEnabled) { if (width != this->yuvPixels.getWidth() || height != this->yuvPixels.getHeight()) { this->yuvPixels.allocate(width, height, OF_PIXELS_YUY2); } if (FAILED(frame->CopyRawFrameDataToArray(this->yuvPixels.size(), this->yuvPixels.getData()))) { throw Exception("Couldn't pull raw YUV pixel buffer"); } } //update field of view if (FAILED(frameDescription->get_HorizontalFieldOfView(&this->horizontalFieldOfView))) { throw Exception("Failed to get horizontal field of view"); } if (FAILED(frameDescription->get_VerticalFieldOfView(&this->verticalFieldOfView))) { throw Exception("Failed to get vertical field of view"); } if (FAILED(frameDescription->get_DiagonalFieldOfView(&this->diagonalFieldOfView))) { throw Exception("Failed to get diagonal field of view"); } IColorCameraSettings * cameraSettings; if (FAILED(frame->get_ColorCameraSettings(&cameraSettings))) { throw Exception("Failed to get color camera settings"); } cameraSettings->get_ExposureTime(&this->exposure); cameraSettings->get_FrameInterval(&this->frameInterval); cameraSettings->get_Gain(&this->gain); cameraSettings->get_Gamma(&this->gamma); } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } SafeRelease(frameDescription); } //---------- void Color::update(IMultiSourceFrame * multiFrame) { this->isFrameNewFlag = false; IColorFrame * frame = NULL; IColorFrameReference * reference; try { //acquire frame if (FAILED(multiFrame->get_ColorFrameReference(&reference))) { return; // we often throw here when no new frame is available } if (FAILED(reference->AcquireFrame(&frame))) { return; // we often throw here when no new frame is available } update(frame); } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } SafeRelease(reference); SafeRelease(frame); } //---------- long int Color::getExposure() const { return this->exposure; } //---------- long int Color::getFrameInterval() const { return this->frameInterval; } //---------- float Color::getGain() const { return this->gain; } //---------- float Color::getGamma() const { return this->gamma; } //---------- void Color::setRgbaPixelsEnabled(bool rgbPixelsEnabled) { this->rgbaPixelsEnabled = rgbPixelsEnabled; } //---------- bool Color::getRgbaPixelsEnabled() const { return this->rgbaPixelsEnabled; } //---------- void Color::setYuvPixelsEnabled(bool yuvPixelsEnabled) { this->yuvPixelsEnabled = yuvPixelsEnabled; } //---------- bool Color::getYuvPixelsEnabled() const { return this->yuvPixelsEnabled; } //---------- const ofPixels & Color::getYuvPixels() const { return this->yuvPixels; } } } ================================================ FILE: src/ofxKinectForWindows2/Source/Color.h ================================================ #pragma once #include "BaseImage.h" #include "../Utils.h" #include "ofBaseTypes.h" #include "ofPixels.h" #include "ofTexture.h" namespace ofxKinectForWindows2 { namespace Source { class Color : public BaseImage { public: Color(); std::string getTypeName() const override; void update(IColorFrame *) override; void update(IMultiSourceFrame *) override; long int getExposure() const; long int getFrameInterval() const; float getGain() const; float getGamma() const; void setRgbaPixelsEnabled(bool rgbaPixelsEnabled); bool getRgbaPixelsEnabled() const; void setYuvPixelsEnabled(bool yuvPixelsEnabled); bool getYuvPixelsEnabled() const; const ofPixels & getYuvPixels() const; protected: void initReader(IKinectSensor *) override; TIMESPAN exposure = 0; TIMESPAN frameInterval = 0; float gain = 0; float gamma = 0; bool rgbaPixelsEnabled = true; bool yuvPixelsEnabled = false; ofPixels yuvPixels; }; } } ================================================ FILE: src/ofxKinectForWindows2/Source/Depth.cpp ================================================ #include "Depth.h" namespace ofxKinectForWindows2 { namespace Source { //---------- Depth::PointCloudOptions::PointCloudOptions() { this->stitchFaces = true; this->textureCoordinates = TextureCoordinates::None; this->steps = 1; this->facesMaxLength = 0.3f; } //---------- Depth::PointCloudOptions::PointCloudOptions(bool stitchFaces, TextureCoordinates textureCoordinates) { this->stitchFaces = stitchFaces; this->textureCoordinates = textureCoordinates; this->steps = 1; this->facesMaxLength = 0.3f; } //---------- std::string Depth::getTypeName() const { return "Depth"; } //---------- void Depth::initReader(IKinectSensor * sensor) { this->reader = NULL; try { IDepthFrameSource * source = NULL; if (FAILED(sensor->get_DepthFrameSource(&source))) { throw(Exception("Failed to initialise Depth source")); } if (FAILED(source->OpenReader(&this->reader))) { throw(Exception("Failed to initialise Depth reader")); } SafeRelease(source); } catch (std::exception & e) { SafeRelease(this->reader); throw (e); } } //---------- void Depth::init(IKinectSensor * sensor, bool reader) { try { BaseFrame::init(sensor, reader); if (FAILED(sensor->get_CoordinateMapper(&this->coordinateMapper))) { throw(Exception("Failed to acquire coordinate mapper")); } // Try and get color frame size from frame description. // Quietly ignore any possible error, but correctly release any // resource already acquired. In this case default values are kept IColorFrameSource * source = NULL; if (SUCCEEDED(sensor->get_ColorFrameSource(&source))) { IFrameDescription * frameDescription = NULL; if (SUCCEEDED(source->get_FrameDescription(&frameDescription))) { if (SUCCEEDED(frameDescription->get_Width(&this->colorFrameWidth)) && SUCCEEDED(frameDescription->get_Height(&this->colorFrameHeight))) { this->colorFrameSize = this->colorFrameWidth * this->colorFrameHeight; } else { OFXKINECTFORWINDOWS2_WARNING << "Failed to get color frame size during depth frame init"; } SafeRelease(frameDescription); } SafeRelease(source); } } catch (std::exception & e) { SafeRelease(this->reader); throw (e); } } //---------- void Depth::update(IMultiSourceFrame * multiFrame) { this->isFrameNewFlag = false; IDepthFrame * frame = NULL; IDepthFrameReference * reference; try { //acquire frame if (FAILED(multiFrame->get_DepthFrameReference(&reference))) { return; // we often throw here when no new frame is available } if (FAILED(reference->AcquireFrame(&frame))) { return; // we often throw here when no new frame is available } BaseImageSimple::update(frame); } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } SafeRelease(reference); SafeRelease(frame); } //---------- ofMesh Depth::getMesh(const PointCloudOptions &opts) { const int width = this->getWidth(); const int height = this->getHeight(); const auto frameSize = width * height; ofMesh mesh; mesh.setMode(opts.stitchFaces ? ofPrimitiveMode::OF_PRIMITIVE_TRIANGLES : ofPrimitiveMode::OF_PRIMITIVE_POINTS); mesh.getVertices().resize(frameSize); auto vertices = mesh.getVerticesPointer(); this->coordinateMapper->MapDepthFrameToCameraSpace(frameSize, this->pixels.getData(), frameSize, (CameraSpacePoint*) mesh.getVerticesPointer()); if (opts.stitchFaces) { int steps = opts.steps; for(int i=0; i 0 && vTR.z > 0 && vBL.z > 0 && abs(vTL.z - vBR.z) < opts.facesMaxLength && abs(vTL.z - vBL.z) < opts.facesMaxLength) { const ofIndexType indices[3] = {topLeft, bottomRight, bottomLeft}; mesh.addIndices(indices, 3); } //bottom right triangle if (vBR.z > 0 && vTR.z > 0 && vBL.z > 0 && abs(vBR.z - vTL.z) < opts.facesMaxLength && abs(vBR.z - vTR.z) < opts.facesMaxLength) { const ofIndexType indices[3] = {topLeft, topRight, bottomRight}; mesh.addIndices(indices, 3); } } } } switch(opts.textureCoordinates) { case PointCloudOptions::TextureCoordinates::ColorCamera: { mesh.getTexCoords().resize(frameSize); this->coordinateMapper->MapDepthFrameToColorSpace(frameSize, this->pixels.getData(), frameSize, (ColorSpacePoint*) mesh.getTexCoordsPointer()); } break; case PointCloudOptions::TextureCoordinates::DepthCamera: { mesh.getTexCoords().resize(frameSize); auto texCoords = mesh.getTexCoordsPointer(); for(int i=0; igetMesh(PointCloudOptions(stitchFaces, textureCoordinates)); } //---------- ofVbo Depth::getVbo(const PointCloudOptions & pointCloudOptions) { //this function should be a more optimised version of getMesh(). But we keep this here for compatability right now. auto mesh = this->getMesh(pointCloudOptions); ofVbo vbo; vbo.setIndexData(mesh.getIndexPointer(), mesh.getNumIndices(), GL_STATIC_DRAW); vbo.setVertexData(mesh.getVerticesPointer(), mesh.getNumVertices(), GL_STATIC_DRAW); vbo.setVertexData(mesh.getTexCoordsPointer(), mesh.getNumTexCoords(), GL_STATIC_DRAW); return vbo; } //---------- void Depth::getWorldInColorFrame(ofFloatPixels & world) const { world.allocate(this->colorFrameWidth, this->colorFrameHeight, ofPixelFormat::OF_PIXELS_RGB); this->coordinateMapper->MapColorFrameToCameraSpace( this->pixels.size(), this->pixels.getData(), this->colorFrameSize, reinterpret_cast(world.getData())); } //---------- void Depth::getWorldInDepthFrame(ofFloatPixels & world) const { world.allocate(this->getWidth(), this->getHeight(), ofPixelFormat::OF_PIXELS_RGB); this->coordinateMapper->MapDepthFrameToCameraSpace( this->pixels.size(), this->pixels.getData(), this->pixels.size(), reinterpret_cast(world.getData())); } //---------- void Depth::getColorInDepthFrameMapping(ofFloatPixels & colorInDepthFrameMapping) const { colorInDepthFrameMapping.allocate(this->getWidth(), this->getHeight(), OF_PIXELS_RG); this->coordinateMapper->MapDepthFrameToColorSpace( this->pixels.size(), this->pixels.getData(), this->pixels.size(), reinterpret_cast(colorInDepthFrameMapping.getData())); } //---------- void Depth::getDepthInColorFrameMapping(ofFloatPixels & depthInColorFrameMapping) const { depthInColorFrameMapping.allocate(this->colorFrameWidth, this->colorFrameHeight, OF_PIXELS_RG); this->coordinateMapper->MapColorFrameToDepthSpace( this->pixels.size(), this->pixels.getData(), this->colorFrameSize, reinterpret_cast(depthInColorFrameMapping.getData())); } //---------- void Depth::getDepthToWorldTable(ofFloatPixels & world) const { UINT32 tableEntryCount; PointF * tableEntries; if (FAILED(this->coordinateMapper->GetDepthFrameToCameraSpaceTable(&tableEntryCount, &tableEntries))) { OFXKINECTFORWINDOWS2_ERROR << "GetDepthFrameToCameraSpaceTable failed"; return; } if (tableEntryCount != this->getWidth() * this->getHeight()) { OFXKINECTFORWINDOWS2_ERROR << "wrong tableEntryCount"; } else { world.setFromPixels((float*) tableEntries, this->getWidth(), this->getHeight(), 2); } // The table of camera space points must be released with a call to CoTaskMemFree CoTaskMemFree(tableEntries); } //---------- ICoordinateMapper * Depth::getCoordinateMapper() const { return this->coordinateMapper; } } } ================================================ FILE: src/ofxKinectForWindows2/Source/Depth.h ================================================ #pragma once #include "ofMesh.h" #include "ofPixels.h" #include "ofVbo.h" #include "BaseImage.h" namespace ofxKinectForWindows2 { namespace Source { class Depth : public BaseImageSimple { public: struct PointCloudOptions { enum TextureCoordinates { None, DepthCamera, ColorCamera }; PointCloudOptions(); PointCloudOptions(bool stitchFaces, TextureCoordinates textureCoordinates); int steps; bool stitchFaces; float facesMaxLength; TextureCoordinates textureCoordinates; }; std::string getTypeName() const override; void init(IKinectSensor *, bool) override; void update(IMultiSourceFrame *) override; ofMesh getMesh(const PointCloudOptions & pointCloudOptions = PointCloudOptions()); ofMesh getMesh(bool stitchFaces, PointCloudOptions::TextureCoordinates textureCoordinates); ofVbo getVbo(const PointCloudOptions & pointCloudOptions = PointCloudOptions()); void getWorldInColorFrame(ofFloatPixels & world) const; void getWorldInDepthFrame(ofFloatPixels & world) const; void getColorInDepthFrameMapping(ofFloatPixels & colorInDepthFrameMapping) const; void getDepthInColorFrameMapping(ofFloatPixels & depthInColorFrameMapping) const; void getDepthToWorldTable(ofFloatPixels & world) const; ICoordinateMapper * getCoordinateMapper() const; protected: void initReader(IKinectSensor *) override; ICoordinateMapper * coordinateMapper; int colorFrameWidth = 1920; int colorFrameHeight = 1080; int colorFrameSize = colorFrameWidth * colorFrameHeight; }; } } ================================================ FILE: src/ofxKinectForWindows2/Source/Infrared.cpp ================================================ #include "Infrared.h" namespace ofxKinectForWindows2 { namespace Source { //---------- std::string Infrared::getTypeName() const { return "Infrared"; } //---------- void Infrared::initReader(IKinectSensor * sensor) { this->reader = NULL; try { IInfraredFrameSource * source = NULL; if (FAILED(sensor->get_InfraredFrameSource(&source))) { throw(Exception("Failed to initialise Infrared source")); } if (FAILED(source->OpenReader(&this->reader))) { throw(Exception("Failed to initialise Infrared reader")); } SafeRelease(source); } catch (std::exception & e) { SafeRelease(this->reader); throw (e); } } //---------- void Infrared::update(IMultiSourceFrame * multiFrame) { this->isFrameNewFlag = false; IInfraredFrame * frame = NULL; IInfraredFrameReference * reference; try { //acquire frame if (FAILED(multiFrame->get_InfraredFrameReference(&reference))) { return; // we often throw here when no new frame is available } if (FAILED(reference->AcquireFrame(&frame))) { return; // we often throw here when no new frame is available } BaseImageSimple::update(frame); } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } SafeRelease(reference); SafeRelease(frame); } } } ================================================ FILE: src/ofxKinectForWindows2/Source/Infrared.h ================================================ #pragma once #include "BaseImage.h" namespace ofxKinectForWindows2 { namespace Source { class Infrared : public BaseImageSimple { public: std::string getTypeName() const override; void update(IMultiSourceFrame *) override; protected: void initReader(IKinectSensor *) override; }; } } ================================================ FILE: src/ofxKinectForWindows2/Source/LongExposureInfraRed.cpp ================================================ #include "LongExposureInfrared.h" namespace ofxKinectForWindows2 { namespace Source { //---------- std::string LongExposureInfrared::getTypeName() const { return "LongExposureInfrared"; } //---------- void LongExposureInfrared::initReader(IKinectSensor* sensor) { this->reader = NULL; try { ILongExposureInfraredFrameSource* source = NULL; if (FAILED(sensor->get_LongExposureInfraredFrameSource(&source))) { throw(Exception("Failed to initialise LongExposureInfrared source")); } if (FAILED(source->OpenReader(&this->reader))) { throw(Exception("Failed to initialise LongExposureInfrared reader")); } SafeRelease(source); } catch (std::exception& e) { SafeRelease(this->reader); throw (e); } } //---------- void LongExposureInfrared::update(IMultiSourceFrame* multiFrame) { this->isFrameNewFlag = false; ILongExposureInfraredFrame* frame = NULL; ILongExposureInfraredFrameReference* reference; try { //acquire frame if (FAILED(multiFrame->get_LongExposureInfraredFrameReference(&reference))) { return; // we often throw here when no new frame is available } if (FAILED(reference->AcquireFrame(&frame))) { return; // we often throw here when no new frame is available } BaseImageSimple::update(frame); } catch (std::exception& e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } SafeRelease(reference); SafeRelease(frame); } } } ================================================ FILE: src/ofxKinectForWindows2/Source/LongExposureInfrared.h ================================================ #pragma once #include "BaseImage.h" namespace ofxKinectForWindows2 { namespace Source { class LongExposureInfrared : public BaseImageSimple { public: std::string getTypeName() const override; void update(IMultiSourceFrame *) override; protected: void initReader(IKinectSensor *) override; }; } } ================================================ FILE: src/ofxKinectForWindows2/Utils.cpp ================================================ #include "Utils.h" using namespace std; namespace ofxKinectForWindows2 { //---------- Exception::Exception(const std::string & message) { this->message = message; } //---------- const char * Exception::what() const { return this->message.c_str(); } //---------- #define TO_STRING_CASE(TYPE, VALUE) \ case TYPE ## :: ## TYPE ## _ ## VALUE ## : { \ return #VALUE; \ } string toString(const JointType & jointType) { switch (jointType) { TO_STRING_CASE(JointType, SpineBase) TO_STRING_CASE(JointType, SpineMid) TO_STRING_CASE(JointType, Neck) TO_STRING_CASE(JointType, Head) TO_STRING_CASE(JointType, ShoulderLeft) TO_STRING_CASE(JointType, ElbowLeft) TO_STRING_CASE(JointType, WristLeft) TO_STRING_CASE(JointType, HandLeft) TO_STRING_CASE(JointType, ShoulderRight) TO_STRING_CASE(JointType, ElbowRight) TO_STRING_CASE(JointType, WristRight) TO_STRING_CASE(JointType, HandRight) TO_STRING_CASE(JointType, HipLeft) TO_STRING_CASE(JointType, KneeLeft) TO_STRING_CASE(JointType, AnkleLeft) TO_STRING_CASE(JointType, FootLeft) TO_STRING_CASE(JointType, HipRight) TO_STRING_CASE(JointType, KneeRight) TO_STRING_CASE(JointType, AnkleRight) TO_STRING_CASE(JointType, FootRight) TO_STRING_CASE(JointType, SpineShoulder) TO_STRING_CASE(JointType, HandTipLeft) TO_STRING_CASE(JointType, ThumbLeft) TO_STRING_CASE(JointType, HandTipRight) TO_STRING_CASE(JointType, ThumbRight) default: return "Unknown"; } } } ================================================ FILE: src/ofxKinectForWindows2/Utils.h ================================================ #pragma once // Fix for C++17 #define _HAS_STD_BYTE 0 #ifndef __func__ #define __func__ __FUNCTION__ #endif #include "ofLog.h" #define OFXKINECTFORWINDOWS2_WARNING ofLogWarning(std::string(__func__)) #define OFXKINECTFORWINDOWS2_ERROR ofLogError(std::string(__func__)) #define OFXKINECTFORWINDOWS2_FATAL ofLogFatalError(std::string(__func__)) #define MAKE(T, ...) std::shared_ptr(new T(__VA_ARGS__)) #include #include "ofxKinectForWindows2/Data/Joint.h" namespace ofxKinectForWindows2 { class Exception : public std::exception { public: Exception(const std::string &); const char * what() const override; protected: std::string message; }; // Safe release for COM interfaces template inline void SafeRelease(Interface *& pInterfaceToRelease) { if (pInterfaceToRelease != NULL) { pInterfaceToRelease->Release(); pInterfaceToRelease = NULL; } } std::string toString(const JointType &); } ================================================ FILE: src/ofxKinectForWindows2.h ================================================ #pragma once #include "ofxKinectForWindows2/Device.h" #define ofxKFW2 ofxKinectForWindows2