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
====================

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:

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.:

Check that the `.props` file has been added correctly, e.g.:

## 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
================================================
DebugWin32Debugx64ReleaseWin32Releasex64{7FD42DF7-442E-479A-BA76-D0022F99702A}Win32Projexample10.0ApplicationUnicodev142ApplicationUnicodev142ApplicationUnicodetruev142ApplicationUnicodetruev142bin\obj\$(Configuration)\$(ProjectName)_debugtruetrue$(ProjectName)_debugtruetruebin\obj\$(Configuration)\falsefalseDisabledtrueEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3EditAndContinue..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCpptrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)DisabledEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3ProgramDatabase..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCpptrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCppfalsefalseConsoletruetruefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCppfalsefalseConsoletruetruefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories){5837595d-aca9-485c-8e76-729040ce4b0b}{f6008d6a-6d39-4b68-840e-e7ac8ed855da}/D_DEBUG %(AdditionalOptions)/D_DEBUG %(AdditionalOptions)
================================================
FILE: example/example.vcxproj.filters
================================================
srcsrc{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
================================================
DebugWin32Debugx64ReleaseWin32Releasex64{7FD42DF7-442E-479A-BA76-D0022F99702A}Win32ProjexampleBodyIndexColorApplicationUnicodev140ApplicationUnicodev140ApplicationUnicodetruev140ApplicationUnicodetruev140bin\obj\$(Configuration)\$(ProjectName)_debugtruetruebin\obj\$(Configuration)\$(ProjectName)_debugtruetruebin\obj\$(Configuration)\falsebin\obj\$(Configuration)\falseDisabledEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3%(AdditionalIncludeDirectories)CompileAsCpptrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)DisabledEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3%(AdditionalIncludeDirectories)CompileAsCpptruetrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3%(AdditionalIncludeDirectories)CompileAsCpptruefalsefalseConsoletruetruefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3%(AdditionalIncludeDirectories)CompileAsCppfalsefalseConsoletruetruefalse%(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
================================================
srcsrc{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
================================================
DebugWin32Debugx64ReleaseWin32Releasex64{7FD42DF7-442E-479A-BA76-D0022F99702A}Win32ProjexampleApplicationUnicodev140ApplicationUnicodev140ApplicationUnicodetruev140ApplicationUnicodetruev140bin\obj\$(Configuration)\$(ProjectName)_debugtruetrue$(ProjectName)_debugtruetruebin\obj\$(Configuration)\falsefalseDisabledtrueEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3EditAndContinue..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCpptrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)DisabledEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3ProgramDatabase..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCpptrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCppfalsefalseConsoletruetruefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCppfalsefalseConsoletruetruefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories){5837595d-aca9-485c-8e76-729040ce4b0b}{f6008d6a-6d39-4b68-840e-e7ac8ed855da}/D_DEBUG %(AdditionalOptions)/D_DEBUG %(AdditionalOptions)
================================================
FILE: exampleBodyIndexShader/example-bodyIndex.vcxproj.filters
================================================
srcsrc{d8376475-7454-4a24-b08a-aac121d3ad6f}{8112424a-9e0b-4e75-931f-a6d5cdf47e1f}{2875c5c0-c98f-40e0-bd5a-23769bd78f9a}srcshadersshadersshaders_gl3shaders_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)
====================

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
================================================
DebugWin32Debugx64ReleaseWin32Releasex64{7FD42DF7-442E-479A-BA76-D0022F99702A}Win32ProjexampleDepthMeshShader10.0ApplicationUnicodev140ApplicationUnicodev140ApplicationUnicodetruev140ApplicationUnicodetruev140bin\obj\$(Configuration)\$(ProjectName)_debugtruetruebin\obj\$(Configuration)\$(ProjectName)_debugtruetruebin\obj\$(Configuration)\falsebin\obj\$(Configuration)\falseDisabledEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3%(AdditionalIncludeDirectories)CompileAsCpptrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)DisabledEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3%(AdditionalIncludeDirectories)CompileAsCpptruetrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3%(AdditionalIncludeDirectories)CompileAsCpptruefalsefalseConsoletruetruefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3%(AdditionalIncludeDirectories)CompileAsCppfalsefalseConsoletruetruefalse%(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
================================================
srcsrc{d8376475-7454-4a24-b08a-aac121d3ad6f}{184c96a8-f47b-482b-a0f2-764d8d7e6429}srcsrc
================================================
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
================================================
DebugWin32Debugx64ReleaseWin32Releasex64{7FD42DF7-442E-479A-BA76-D0022F99702A}Win32ProjexampleDepthToCameraTableApplicationUnicodev140ApplicationUnicodev140ApplicationUnicodetruev140ApplicationUnicodetruev140bin\obj\$(Configuration)\$(ProjectName)_debugtruetruebin\obj\$(Configuration)\$(ProjectName)_debugtruetruebin\obj\$(Configuration)\falsebin\obj\$(Configuration)\falseDisabledEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3%(AdditionalIncludeDirectories)CompileAsCpptrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)DisabledEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3%(AdditionalIncludeDirectories)CompileAsCpptruetrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3%(AdditionalIncludeDirectories)CompileAsCpptruefalsefalseConsoletruetruefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3%(AdditionalIncludeDirectories)CompileAsCppfalsefalseConsoletruetruefalse%(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
================================================
srcsrc{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
================================================
DebugWin32Debugx64ReleaseWin32Releasex64{7FD42DF7-442E-479A-BA76-D0022F99702A}Win32Projexample8.1ApplicationUnicodev140ApplicationUnicodev140ApplicationUnicodetruev140ApplicationUnicodetruev140$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName)_debugtruetrue$(ProjectName)_debugtruetrue$(SolutionDir)bin\$(Platform)\$(Configuration)\falsefalseDisabledtrueEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3EditAndContinue..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCpptrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)%(IgnoreSpecificDefaultLibraries)DisabledEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3ProgramDatabase..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCpptrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCppfalsefalseConsoletruetruefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCppfalsefalseConsoletruetruefalse%(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
================================================
srcsrc{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
================================================
DebugWin32Debugx64ReleaseWin32Releasex64{7FD42DF7-442E-479A-BA76-D0022F99702A}Win32ProjexampleApplicationUnicodev110ApplicationUnicodev120ApplicationUnicodetruev120ApplicationUnicodetruev120bin\obj\$(Configuration)\$(ProjectName)_debugtruetrue$(ProjectName)_debugtruetruebin\obj\$(Configuration)\falsefalseDisabledtrueEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3EditAndContinue..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCpptrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)%(IgnoreSpecificDefaultLibraries)DisabledEnableFastChecks%(PreprocessorDefinitions)MultiThreadedDebugDLLLevel3ProgramDatabase..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCpptrueConsolefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCppfalsefalseConsoletruetruefalse%(AdditionalDependencies)%(AdditionalLibraryDirectories)false%(PreprocessorDefinitions)MultiThreadedDLLLevel3..\..\..\addons\ofxKinectForWindows2\src;%(AdditionalIncludeDirectories)CompileAsCppfalsefalseConsoletruetruefalse%(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
================================================
DebugWin32Debugx64ReleaseWin32Releasex64{F6008D6A-6D39-4B68-840E-E7AC8ED855DA}ofxKinectForWindows2Lib10.0StaticLibrarytruev142MultiByteStaticLibrarytruev142MultiByteStaticLibraryfalsev142trueMultiByteStaticLibraryfalsev142trueMultiByte$(ProjectName)dLevel3Disabledtruefalsetruetruekinect20.lib;%(AdditionalDependencies)$(KINECTSDK20_DIR)Lib\x86;%(AdditionalLibraryDirectories)Level3Disabledtruefalsetruekinect20.lib;%(AdditionalDependencies)$(KINECTSDK20_DIR)Lib\x64;%(AdditionalLibraryDirectories)Level3MaxSpeedtruetruetruetruetruetruetruekinect20.lib;%(AdditionalDependencies)$(KINECTSDK20_DIR)Lib\x86;%(AdditionalLibraryDirectories)Level3MaxSpeedtruetruetruetruetruetruekinect20.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}srcsrc\ofxKinectForWindows2src\ofxKinectForWindows2src\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Datasrc\ofxKinectForWindows2\Datasrc\ofxKinectForWindows2src\ofxKinectForWindows2src\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Sourcesrc\ofxKinectForWindows2\Datasrc\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