├── Shooting
├── bin
│ └── data
│ │ ├── .gitkeep
│ │ ├── .gitignore
│ │ ├── heightmap.frag
│ │ ├── ofxbraitsch
│ │ ├── fonts
│ │ │ └── Verdana.ttf
│ │ └── ofxdatgui
│ │ │ ├── icon-dropdown.png
│ │ │ ├── icon-radio-on.png
│ │ │ ├── icon-group-open.png
│ │ │ ├── icon-radio-off.png
│ │ │ ├── picker-rainbow.png
│ │ │ └── icon-group-closed.png
│ │ ├── ir.frag
│ │ ├── point.frag
│ │ ├── calibration.xml
│ │ ├── calibration_bak.xml
│ │ ├── calibration_0807.xml
│ │ ├── calibration_new.xml
│ │ ├── calibration_new2.xml
│ │ ├── calibration_new3.xml
│ │ ├── depth.frag
│ │ ├── point.vert
│ │ ├── settings.json
│ │ └── heightmap.vert
├── addons.make
├── src
│ ├── Shooting.h
│ ├── main.cpp
│ ├── Config.h
│ ├── ofxImageSequenceLoader.h
│ ├── ofxStopwatch.h
│ ├── DiscController.h
│ ├── ofxMultiKinectV2Mod.h
│ ├── ofApp.h
│ ├── ofxMultiKinectV2Mod.cpp
│ └── ofApp.cpp
├── Makefile
├── Project.xcconfig
├── openFrameworks-Info.plist
├── Shooting.xcodeproj
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── Shooting Debug.xcscheme
│ │ └── Shooting Release.xcscheme
└── config.make
├── Calibration
├── bin
│ └── data
│ │ ├── .gitkeep
│ │ └── calibration.xml
├── addons.make
├── src
│ ├── main.cpp
│ ├── ofApp.h
│ └── ofApp.cpp
├── Makefile
├── Project.xcconfig
├── openFrameworks-Info.plist
├── calibration.xcodeproj
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── calibration Debug.xcscheme
│ │ └── calibration Release.xcscheme
└── config.make
├── KinectRecorder
├── bin
│ └── data
│ │ ├── .gitkeep
│ │ ├── .gitignore
│ │ ├── ofxbraitsch
│ │ ├── fonts
│ │ │ └── Verdana.ttf
│ │ └── ofxdatgui
│ │ │ ├── icon-dropdown.png
│ │ │ ├── icon-radio-off.png
│ │ │ ├── icon-radio-on.png
│ │ │ └── picker-rainbow.png
│ │ ├── depth.frag
│ │ ├── filled.frag
│ │ ├── point.frag
│ │ ├── settings.xml
│ │ └── point.vert
├── addons.make
├── src
│ ├── Config.h
│ ├── main.cpp
│ ├── ofApp.h
│ ├── DepthFiller.h
│ ├── PostProcessing.h
│ └── ofApp.cpp
├── Makefile
├── Project.xcconfig
├── openFrameworks-Info.plist
├── KinectRecorder.xcodeproj
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── Kinect2Test Debug.xcscheme
│ │ └── Kinect2Test Release.xcscheme
└── config.make
├── HeightmapGenerator
├── bin
│ └── data
│ │ ├── .gitkeep
│ │ ├── ofxbraitsch
│ │ ├── fonts
│ │ │ └── Verdana.ttf
│ │ └── ofxdatgui
│ │ │ ├── icon-dropdown.png
│ │ │ ├── icon-radio-on.png
│ │ │ ├── icon-group-open.png
│ │ │ ├── icon-radio-off.png
│ │ │ ├── picker-rainbow.png
│ │ │ └── icon-group-closed.png
│ │ ├── settings.xml
│ │ ├── heightmap.frag
│ │ └── heightmap.vert
├── addons.make
├── src
│ ├── main.cpp
│ ├── Config.h
│ ├── ofApp.h
│ ├── HeightmapExporter.h
│ ├── HeightmapRenderer.h
│ └── ofApp.cpp
├── Makefile
├── Project.xcconfig
├── openFrameworks-Info.plist
├── HeightmapGenerator.xcodeproj
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── HeightmapGenerator Debug.xcscheme
│ │ └── HeightmapGenerator Release.xcscheme
└── config.make
├── thumb.jpg
├── LICENSE
├── readme.md
└── .gitignore
/Shooting/bin/data/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Calibration/bin/data/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/KinectRecorder/bin/data/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Shooting/bin/data/.gitignore:
--------------------------------------------------------------------------------
1 | saved
--------------------------------------------------------------------------------
/HeightmapGenerator/bin/data/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/KinectRecorder/bin/data/.gitignore:
--------------------------------------------------------------------------------
1 | saved
--------------------------------------------------------------------------------
/thumb.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/thumb.jpg
--------------------------------------------------------------------------------
/HeightmapGenerator/addons.make:
--------------------------------------------------------------------------------
1 | ofxCv
2 | ofxDatGui
3 | ofxImageSequenceRecorder
4 | ofxOpenCv
5 | ofxXmlSettings
6 |
--------------------------------------------------------------------------------
/Calibration/addons.make:
--------------------------------------------------------------------------------
1 | ofxCv
2 | ofxKinectProjectorToolkitV2
3 | ofxMultiKinectV2
4 | ofxOpenCv
5 | ofxSecondWindow
6 | ofxTurboJpeg
7 |
--------------------------------------------------------------------------------
/Shooting/bin/data/heightmap.frag:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 | varying vec4 color;
4 |
5 | void main()
6 | {
7 | gl_FragColor = vec4(color);
8 | }
--------------------------------------------------------------------------------
/KinectRecorder/addons.make:
--------------------------------------------------------------------------------
1 | ofxCv
2 | ofxDatGui
3 | ofxImageSequenceRecorder
4 | ofxMultiKinectV2
5 | ofxOpenCv
6 | ofxTurboJpeg
7 | ofxXmlSettings
8 |
--------------------------------------------------------------------------------
/Shooting/bin/data/ofxbraitsch/fonts/Verdana.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/Shooting/bin/data/ofxbraitsch/fonts/Verdana.ttf
--------------------------------------------------------------------------------
/KinectRecorder/bin/data/ofxbraitsch/fonts/Verdana.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/KinectRecorder/bin/data/ofxbraitsch/fonts/Verdana.ttf
--------------------------------------------------------------------------------
/HeightmapGenerator/bin/data/ofxbraitsch/fonts/Verdana.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/HeightmapGenerator/bin/data/ofxbraitsch/fonts/Verdana.ttf
--------------------------------------------------------------------------------
/Shooting/bin/data/ofxbraitsch/ofxdatgui/icon-dropdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/Shooting/bin/data/ofxbraitsch/ofxdatgui/icon-dropdown.png
--------------------------------------------------------------------------------
/Shooting/bin/data/ofxbraitsch/ofxdatgui/icon-radio-on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/Shooting/bin/data/ofxbraitsch/ofxdatgui/icon-radio-on.png
--------------------------------------------------------------------------------
/Shooting/bin/data/ofxbraitsch/ofxdatgui/icon-group-open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/Shooting/bin/data/ofxbraitsch/ofxdatgui/icon-group-open.png
--------------------------------------------------------------------------------
/Shooting/bin/data/ofxbraitsch/ofxdatgui/icon-radio-off.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/Shooting/bin/data/ofxbraitsch/ofxdatgui/icon-radio-off.png
--------------------------------------------------------------------------------
/Shooting/bin/data/ofxbraitsch/ofxdatgui/picker-rainbow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/Shooting/bin/data/ofxbraitsch/ofxdatgui/picker-rainbow.png
--------------------------------------------------------------------------------
/Shooting/bin/data/ofxbraitsch/ofxdatgui/icon-group-closed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/Shooting/bin/data/ofxbraitsch/ofxdatgui/icon-group-closed.png
--------------------------------------------------------------------------------
/KinectRecorder/bin/data/ofxbraitsch/ofxdatgui/icon-dropdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/KinectRecorder/bin/data/ofxbraitsch/ofxdatgui/icon-dropdown.png
--------------------------------------------------------------------------------
/KinectRecorder/bin/data/ofxbraitsch/ofxdatgui/icon-radio-off.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/KinectRecorder/bin/data/ofxbraitsch/ofxdatgui/icon-radio-off.png
--------------------------------------------------------------------------------
/KinectRecorder/bin/data/ofxbraitsch/ofxdatgui/icon-radio-on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/KinectRecorder/bin/data/ofxbraitsch/ofxdatgui/icon-radio-on.png
--------------------------------------------------------------------------------
/KinectRecorder/bin/data/ofxbraitsch/ofxdatgui/picker-rainbow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/KinectRecorder/bin/data/ofxbraitsch/ofxdatgui/picker-rainbow.png
--------------------------------------------------------------------------------
/HeightmapGenerator/bin/data/ofxbraitsch/ofxdatgui/icon-dropdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/HeightmapGenerator/bin/data/ofxbraitsch/ofxdatgui/icon-dropdown.png
--------------------------------------------------------------------------------
/HeightmapGenerator/bin/data/ofxbraitsch/ofxdatgui/icon-radio-on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/HeightmapGenerator/bin/data/ofxbraitsch/ofxdatgui/icon-radio-on.png
--------------------------------------------------------------------------------
/HeightmapGenerator/bin/data/ofxbraitsch/ofxdatgui/icon-group-open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/HeightmapGenerator/bin/data/ofxbraitsch/ofxdatgui/icon-group-open.png
--------------------------------------------------------------------------------
/HeightmapGenerator/bin/data/ofxbraitsch/ofxdatgui/icon-radio-off.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/HeightmapGenerator/bin/data/ofxbraitsch/ofxdatgui/icon-radio-off.png
--------------------------------------------------------------------------------
/HeightmapGenerator/bin/data/ofxbraitsch/ofxdatgui/picker-rainbow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/HeightmapGenerator/bin/data/ofxbraitsch/ofxdatgui/picker-rainbow.png
--------------------------------------------------------------------------------
/HeightmapGenerator/bin/data/ofxbraitsch/ofxdatgui/icon-group-closed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baku89/depthcope-tools/HEAD/HeightmapGenerator/bin/data/ofxbraitsch/ofxdatgui/icon-group-closed.png
--------------------------------------------------------------------------------
/KinectRecorder/bin/data/depth.frag:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 | uniform sampler2DRect tex;
4 |
5 | void main()
6 | {
7 | float d = texture2DRect(tex, gl_TexCoord[0].xy).r;
8 | gl_FragColor = vec4(vec3(d), 1.0);
9 | }
--------------------------------------------------------------------------------
/KinectRecorder/bin/data/filled.frag:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 | uniform sampler2DRect tex;
4 |
5 | void main()
6 | {
7 | float d = texture2DRect(tex, gl_TexCoord[0].xy).b;
8 | gl_FragColor = vec4(vec3(d), 1.0);
9 | }
--------------------------------------------------------------------------------
/KinectRecorder/bin/data/point.frag:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 |
4 | varying float opacity;
5 | varying float luminance;
6 |
7 | void main() {
8 |
9 | gl_FragColor = vec4(luminance, luminance, luminance, opacity);
10 | }
--------------------------------------------------------------------------------
/Shooting/addons.make:
--------------------------------------------------------------------------------
1 | ofxCv
2 | ofxDatGui
3 | ofxDmx
4 | ofxGrabCam
5 | ofxJSON
6 | ofxKinectProjectorToolkitV2
7 | ofxMultiKinectV2
8 | ofxOpenCv
9 | ofxOsc
10 | ofxSecondWindow
11 | ofxTurboJpeg
12 | ofxXmlSettings
13 |
--------------------------------------------------------------------------------
/Shooting/src/Shooting.h:
--------------------------------------------------------------------------------
1 | //
2 | // Shooting.h
3 | // Shooting
4 | //
5 | // Created by Baku Hashimoto on 7/30/16.
6 | //
7 | //
8 |
9 | #ifndef Shooting_h
10 | #define Shooting_h
11 |
12 |
13 | #endif /* Shooting_h */
14 |
--------------------------------------------------------------------------------
/KinectRecorder/bin/data/settings.xml:
--------------------------------------------------------------------------------
1 | 50.000000000
2 | 120.000000000
3 | 10.300000191
4 | 0
5 | 1
6 | 1
7 |
--------------------------------------------------------------------------------
/Shooting/bin/data/ir.frag:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 | uniform sampler2DRect tex;
4 |
5 | void main()
6 | {
7 | vec4 col = texture2DRect(tex, gl_TexCoord[0].xy);
8 | float value = col.r / 65535.0;
9 | gl_FragColor = vec4(vec3(value), 1.0);
10 | }
--------------------------------------------------------------------------------
/KinectRecorder/src/Config.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define DEPTH_WIDTH 512
4 | #define DEPTH_HEIGHT 424
5 |
6 | #define GUI_WIDTH 320
7 |
8 | #define SAVED_DIR (string)"../../../saved"
9 |
10 | #define RAW_NAME (string)"raw"
11 | #define INPAINTED_NAME (string)"inpainted"
12 |
13 | #define LINE_WIDTH 2
--------------------------------------------------------------------------------
/Shooting/bin/data/point.frag:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 |
4 | varying float opacity;
5 | varying float luminance;
6 | varying float velocity;
7 |
8 | void main() {
9 |
10 | vec4 color = vec4(1.0, 1.0, 1.0, opacity);
11 |
12 | if (velocity > 0) {
13 | color.gb -= velocity;
14 | } else {
15 | color.rg += velocity;
16 | }
17 |
18 | gl_FragColor = color;
19 | }
--------------------------------------------------------------------------------
/Calibration/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
7 |
8 | // this kicks off the running of my app
9 | // can be OF_WINDOW or OF_FULLSCREEN
10 | // pass in width and height too:
11 | ofRunApp(new ofApp());
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/HeightmapGenerator/bin/data/settings.xml:
--------------------------------------------------------------------------------
1 | 2016-07-22-18-43-53
2 | 55.860000610
3 | 97.239997864
4 | 743.590026855
5 | 633.630004883
6 | -0.070000000
7 | -0.070000000
8 | 12.000000000
9 | 1
10 |
--------------------------------------------------------------------------------
/HeightmapGenerator/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
7 |
8 | // this kicks off the running of my app
9 | // can be OF_WINDOW or OF_FULLSCREEN
10 | // pass in width and height too:
11 | ofRunApp(new ofApp());
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/Shooting/bin/data/calibration.xml:
--------------------------------------------------------------------------------
1 |
2 | 0.0185794
3 | -0.00142211
4 | 0.00441894
5 | 0.656368
6 | 0.00128052
7 | -0.034669
8 | 0.00201528
9 | 1.1086
10 | 0.000776873
11 | -0.00366654
12 | 0.0106775
13 |
14 |
--------------------------------------------------------------------------------
/Calibration/bin/data/calibration.xml:
--------------------------------------------------------------------------------
1 |
2 | 0.0185794
3 | -0.00142211
4 | 0.00441894
5 | 0.656368
6 | 0.00128052
7 | -0.034669
8 | 0.00201528
9 | 1.1086
10 | 0.000776873
11 | -0.00366654
12 | 0.0106775
13 |
14 |
--------------------------------------------------------------------------------
/HeightmapGenerator/bin/data/heightmap.frag:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 | uniform int isPreview;
4 |
5 | varying float luminance;
6 |
7 | void main() {
8 |
9 | vec4 color = vec4(vec3(luminance), 1.0);
10 |
11 | if (isPreview == 1) {
12 | if (luminance > 0.99) {
13 | color.rgb = vec3(1.0, 0.0, 0.0);
14 | } else if (luminance < 0.01) {
15 | color.rgb = vec3(0.0, 0.0, 1.0);
16 | }
17 | }
18 |
19 | gl_FragColor = color;
20 | }
--------------------------------------------------------------------------------
/Shooting/bin/data/calibration_bak.xml:
--------------------------------------------------------------------------------
1 |
2 | 0.0200394
3 | -0.00144198
4 | 0.00621492
5 | 0.754733
6 | 0.000281119
7 | -0.0370234
8 | 0.00393322
9 | 1.19556
10 | 0.0005091
11 | -0.00271259
12 | 0.0128299
13 |
14 |
--------------------------------------------------------------------------------
/Shooting/bin/data/calibration_0807.xml:
--------------------------------------------------------------------------------
1 |
2 | 0.0214194
3 | -0.00158405
4 | 0.00629716
5 | 0.66643
6 | 0.00108519
7 | -0.0399362
8 | 0.00308034
9 | 1.23002
10 | 0.000745585
11 | -0.00381393
12 | 0.0142597
13 |
14 |
--------------------------------------------------------------------------------
/Shooting/bin/data/calibration_new.xml:
--------------------------------------------------------------------------------
1 |
2 | 0.0195268
3 | -0.0023561
4 | 0.00643263
5 | 0.742106
6 | -0.000504753
7 | -0.0379373
8 | 0.00109586
9 | 1.16808
10 | -0.000728622
11 | -0.00483793
12 | 0.0127108
13 |
14 |
--------------------------------------------------------------------------------
/Shooting/bin/data/calibration_new2.xml:
--------------------------------------------------------------------------------
1 |
2 | 0.016431
3 | -0.00115183
4 | 0.00429654
5 | 0.705561
6 | 1.69558e-05
7 | -0.0308277
8 | 0.00231382
9 | 1.07793
10 | 1.34546e-05
11 | -0.002078
12 | 0.00878546
13 |
14 |
--------------------------------------------------------------------------------
/Shooting/bin/data/calibration_new3.xml:
--------------------------------------------------------------------------------
1 |
2 | 0.0194845
3 | -0.00135232
4 | 0.00408918
5 | 0.641656
6 | 0.00137109
7 | -0.0351763
8 | 0.00087011
9 | 1.11964
10 | 0.00161461
11 | -0.00304333
12 | 0.00956608
13 |
14 |
--------------------------------------------------------------------------------
/Calibration/Makefile:
--------------------------------------------------------------------------------
1 | # Attempt to load a config.make file.
2 | # If none is found, project defaults in config.project.make will be used.
3 | ifneq ($(wildcard config.make),)
4 | include config.make
5 | endif
6 |
7 | # make sure the the OF_ROOT location is defined
8 | ifndef OF_ROOT
9 | OF_ROOT=../../..
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/Shooting/Makefile:
--------------------------------------------------------------------------------
1 | # Attempt to load a config.make file.
2 | # If none is found, project defaults in config.project.make will be used.
3 | ifneq ($(wildcard config.make),)
4 | include config.make
5 | endif
6 |
7 | # make sure the the OF_ROOT location is defined
8 | ifndef OF_ROOT
9 | OF_ROOT=$(realpath ../../..)
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/KinectRecorder/Makefile:
--------------------------------------------------------------------------------
1 | # Attempt to load a config.make file.
2 | # If none is found, project defaults in config.project.make will be used.
3 | ifneq ($(wildcard config.make),)
4 | include config.make
5 | endif
6 |
7 | # make sure the the OF_ROOT location is defined
8 | ifndef OF_ROOT
9 | OF_ROOT=$(realpath ../../..)
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/HeightmapGenerator/Makefile:
--------------------------------------------------------------------------------
1 | # Attempt to load a config.make file.
2 | # If none is found, project defaults in config.project.make will be used.
3 | ifneq ($(wildcard config.make),)
4 | include config.make
5 | endif
6 |
7 | # make sure the the OF_ROOT location is defined
8 | ifndef OF_ROOT
9 | OF_ROOT=$(realpath ../../..)
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/Shooting/bin/data/depth.frag:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 | uniform sampler2DRect tex;
4 |
5 | void main()
6 | {
7 | vec4 col = texture2DRect(tex, gl_TexCoord[0].xy);
8 | float value = col.r;
9 | float low1 = 500.0;
10 | float high1 = 5000.0;
11 | float low2 = 1.0;
12 | float high2 = 0.0;
13 | float d = clamp(low2 + (value - low1) * (high2 - low2) / (high1 - low1), 0.0, 1.0);
14 | if (d == 1.0) {
15 | d = 0.0;
16 | }
17 | gl_FragColor = vec4(vec3(d), 1.0);
18 | }
--------------------------------------------------------------------------------
/Shooting/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | // ofGLWindowSettings settings;
7 | // settings.setGLVersion(2,2);
8 | // ofCreateWindow(settings);
9 |
10 |
11 | // this kicks off the running of my app
12 | // can be OF_WINDOW or OF_FULLSCREEN
13 | // pass in width and height too:
14 | ofSetupOpenGL(1600, 800, OF_WINDOW);
15 | ofRunApp(new ofApp());
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/KinectRecorder/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | // ofGLWindowSettings settings;
7 | // settings.setGLVersion(2,2);
8 | // ofCreateWindow(settings);
9 |
10 |
11 | // this kicks off the running of my app
12 | // can be OF_WINDOW or OF_FULLSCREEN
13 | // pass in width and height too:
14 | ofSetupOpenGL(1600, 800, OF_WINDOW);
15 | ofRunApp(new ofApp());
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/HeightmapGenerator/src/Config.h:
--------------------------------------------------------------------------------
1 | //
2 | // Config.h
3 | // HeightmapGenerator
4 | //
5 | // Created by Baku Hashimoto on 7/22/16.
6 | //
7 | //
8 |
9 | #pragma once
10 |
11 | #define DEPTH_WIDTH 512
12 | #define DEPTH_HEIGHT 424
13 |
14 | #define GUI_WIDTH 320
15 |
16 | #define SAVED_DIR (string)"../../../saved"
17 | #define SETTINGS_PATH (string)"settings.xml"
18 |
19 | #define RAW_NAME (string)"raw"
20 | #define INPAINTED_NAME (string)"inpainted"
21 | #define HEIGHTMAP_NAME (string)"heightmap"
22 |
23 | #define LINE_WIDTH 2
--------------------------------------------------------------------------------
/Shooting/src/Config.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define DEPTH_WIDTH 512
4 | #define DEPTH_HEIGHT 424
5 |
6 | #define COLOR_WIDTH 1920
7 | #define COLOR_HEIGHT 1080
8 | #define CW 640
9 | #define CH 360
10 |
11 | #define COLOR_SCALE 0.3925925926f
12 |
13 | #define GUI_WIDTH 240
14 |
15 | #define SAVED_DIR (string)"../../../saved"
16 |
17 | #define RAW_NAME (string)"raw"
18 | #define INPAINTED_NAME (string)"inpainted"
19 |
20 | #define LINE_WIDTH 2
21 |
22 | #define CALIB_FRAMES 30
23 |
24 | #define HEIGHTMAP_DEPTH 30
25 |
26 | #define HEIGHTMAP_WIDTH 1024
27 |
28 | #define LIGHT_STEP 0.05
--------------------------------------------------------------------------------
/KinectRecorder/bin/data/point.vert:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 | uniform sampler2DRect depth;
4 | uniform float near;
5 | uniform float far;
6 | uniform vec2 focus;
7 |
8 | varying float opacity;
9 | varying float luminance;
10 |
11 | void main() {
12 |
13 | vec2 uv = gl_Vertex.xy + vec2(256.0, 212.0);
14 | uv.x = 512.0 - uv.x;
15 | uv.y = 424.0 - uv.y;
16 | vec4 color = texture2DRect(depth, uv);
17 |
18 | luminance = color.r;
19 | float d = (1.0 - luminance) * (far - near) + near;
20 | opacity = 1.0 - color.g;
21 |
22 | vec4 position = vec4(
23 | gl_Vertex.x * d / focus.x,
24 | gl_Vertex.y * d / focus.y,
25 | d,
26 | 1.0
27 | );
28 |
29 | gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * position;
30 | }
--------------------------------------------------------------------------------
/Shooting/Project.xcconfig:
--------------------------------------------------------------------------------
1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT.
2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED
3 | OF_PATH = ../../..
4 |
5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE
6 | #include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig"
7 |
8 | //ICONS - NEW IN 0072
9 | ICON_NAME_DEBUG = icon-debug.icns
10 | ICON_NAME_RELEASE = icon.icns
11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/
12 |
13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to:
14 | //ICON_FILE_PATH = bin/data/
15 |
16 | OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS)
17 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS)
18 |
--------------------------------------------------------------------------------
/Calibration/Project.xcconfig:
--------------------------------------------------------------------------------
1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT.
2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED
3 | OF_PATH = ../../..
4 |
5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE
6 | #include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig"
7 |
8 | //ICONS - NEW IN 0072
9 | ICON_NAME_DEBUG = icon-debug.icns
10 | ICON_NAME_RELEASE = icon.icns
11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/
12 |
13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to:
14 | //ICON_FILE_PATH = bin/data/
15 |
16 | OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS)
17 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS)
18 |
--------------------------------------------------------------------------------
/KinectRecorder/Project.xcconfig:
--------------------------------------------------------------------------------
1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT.
2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED
3 | OF_PATH = ../../..
4 |
5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE
6 | #include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig"
7 |
8 | //ICONS - NEW IN 0072
9 | ICON_NAME_DEBUG = icon-debug.icns
10 | ICON_NAME_RELEASE = icon.icns
11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/
12 |
13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to:
14 | //ICON_FILE_PATH = bin/data/
15 |
16 | OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS)
17 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS)
18 |
--------------------------------------------------------------------------------
/HeightmapGenerator/Project.xcconfig:
--------------------------------------------------------------------------------
1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT.
2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED
3 | OF_PATH = ../../..
4 |
5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE
6 | #include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig"
7 |
8 | //ICONS - NEW IN 0072
9 | ICON_NAME_DEBUG = icon-debug.icns
10 | ICON_NAME_RELEASE = icon.icns
11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/
12 |
13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to:
14 | //ICON_FILE_PATH = bin/data/
15 |
16 | OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS)
17 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS)
18 |
--------------------------------------------------------------------------------
/Calibration/openFrameworks-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | cc.openFrameworks.ofapp
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | APPL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | CFBundleIconFile
20 | ${ICON}
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Shooting/openFrameworks-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | cc.openFrameworks.ofapp
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | APPL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | CFBundleIconFile
20 | ${ICON}
21 |
22 |
23 |
--------------------------------------------------------------------------------
/KinectRecorder/openFrameworks-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | cc.openFrameworks.ofapp
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | APPL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | CFBundleIconFile
20 | ${ICON}
21 |
22 |
23 |
--------------------------------------------------------------------------------
/HeightmapGenerator/openFrameworks-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | cc.openFrameworks.ofapp
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | APPL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | CFBundleIconFile
20 | ${ICON}
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Shooting/bin/data/point.vert:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 | uniform sampler2DRect depth;
4 | uniform sampler2DRect irTex;
5 | uniform float near;
6 | uniform float far;
7 | uniform vec2 focus;
8 | uniform float planeMaskThreshold;
9 |
10 | varying float opacity;
11 | varying float velocity;
12 |
13 | void main() {
14 |
15 | vec2 uv = gl_Vertex.xy + vec2(256.0, 212.0);
16 | uv.x = 512.0 - uv.x;
17 | uv.y = 424.0 - uv.y;
18 | vec4 color = texture2DRect(depth, uv);
19 |
20 | float d = (1.0 - color.r) * (far - near) + near;
21 | opacity = 1.0 - color.g;
22 |
23 | if (texture2DRect(irTex, uv).r < planeMaskThreshold) {
24 | opacity = 0.0;
25 | }
26 |
27 | velocity = color.b / 100.0;
28 |
29 | vec4 position = vec4(
30 | gl_Vertex.x * d / focus.x,
31 | gl_Vertex.y * d / focus.y,
32 | -d,
33 | 1.0
34 | );
35 |
36 | gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * position;
37 | }
--------------------------------------------------------------------------------
/HeightmapGenerator/bin/data/heightmap.vert:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 | #define DEPTH_WIDTH 512.0
4 | #define DEPTH_HEIGHT 424.0
5 | uniform sampler2DRect depth;
6 | uniform float near;
7 | uniform float far;
8 | uniform float scale;
9 | uniform float captureNear;
10 | uniform float captureFar;
11 | uniform vec2 focus;
12 | uniform vec2 captureSize;
13 | uniform vec2 translation;
14 |
15 | // varying float opacity;
16 | varying float luminance;
17 |
18 |
19 |
20 | void main() {
21 |
22 | vec2 uv = gl_Vertex.xy + vec2(DEPTH_WIDTH / 2, DEPTH_HEIGHT / 2);
23 | vec4 color = texture2DRect(depth, uv);
24 |
25 | float d = (1.0 - color.r) * (far - near) + near;
26 | luminance = 1.0 - (d - captureNear) / (captureFar - captureNear);
27 |
28 | vec2 position = vec2(
29 | gl_Vertex.x * d / focus.x,
30 | gl_Vertex.y * d / focus.y
31 | );
32 |
33 | gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(position * vec2(scale) + (0.5 + translation) * captureSize, 0.0, 1.0);
34 | }
--------------------------------------------------------------------------------
/Shooting/bin/data/settings.json:
--------------------------------------------------------------------------------
1 | {"disc":{"axisX":{"kinect":[395,170],"world":[35.45894241333008,10.01558876037598,-95.55180358886719]},"axisY":{"kinect":[274,73],"world":[4.11524486541748,38.19612121582031,-103.1423721313477]},"maskMargin":3.670000076293945,"maskThreshold":0,"mat":[0.99923175573349,0.02841246128082275,-0.02699328027665615,0,-0.03176111355423927,0.9600467085838318,-0.2780314981937408,0,0.01801533438265324,0.2786765098571777,0.9602160453796387,0,5.076118946075439,9.151674270629883,-94.73104095458984,1],"origin":{"kinect":[279.2999572753906,173.3000030517578],"world":[5.076118946075439,9.151674270629883,-94.73104095458984]}},"mode":2,"scene":{"far":150,"isDisplayIr":false,"near":33.09999847412109,"showScene":false},"shooting":{"currentFrame":695,"enableTimer":true,"feedbackRate":0.3300000131130219,"forceDisplay":false,"hudOrigin":[600,630],"isDisplayHeightmap":true,"isPreviewLight":true,"lightBack":0.8999999761581421,"lightFront":0.5199999809265137,"rotateStep":90,"showHeightmap":true,"showOverlay":true}}
2 |
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | Copyright (c) 2016 Baku Hashimoto
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/Shooting/src/ofxImageSequenceLoader.h:
--------------------------------------------------------------------------------
1 | //
2 | // ofxImageSequenceLoader.cpp
3 | // Shooting
4 | //
5 | // Created by Baku Hashimoto on 7/28/16.
6 | //
7 | //
8 |
9 | #pragma once
10 |
11 | #include
12 | #include
13 |
14 | #include "ofMain.h"
15 |
16 | class ofxImageSequenceLoader {
17 | public:
18 |
19 | void setup(string pattern) {
20 |
21 | std::regex re("^(.*?)(#+)(.*)$");
22 | std::smatch match;
23 | regex_match(pattern, match, re);
24 |
25 |
26 | prefix = match[1];
27 | numWidth = ((string)match[2]).size();
28 | suffix = match[3];
29 |
30 | /*
31 | glob_t globbuf;
32 | int ret = glob((prefix + "*" + suffix).c_str(), 0, NULL, &globbuf);
33 | // glob(const char *, int, int (*)(const char *, int), glob_t *);
34 |
35 | for (int i = 0; i < globbuf.gl_pathc; i++) {
36 | files.push_back(globbuf.gl_pathv[i]);
37 | ofLogNotice() << files[i];
38 | }
39 |
40 | globfree(&globbuf);
41 | */
42 |
43 | }
44 |
45 | bool load(ofFloatPixels &pix, int frame) {
46 | ss.str("");
47 | ss << prefix << setw(numWidth) << setfill('0') << frame << suffix;
48 |
49 | string path = ss.str();
50 | ofLogNotice() << "loading: " << path;
51 | bLoaded = ofLoadImage(pix, path);
52 | return bLoaded;
53 | }
54 |
55 | bool isLoaded() {
56 | return bLoaded;
57 | }
58 |
59 |
60 | private:
61 | stringstream ss;
62 | string prefix, suffix;
63 | int numWidth;
64 | bool bLoaded = false;
65 | };
66 |
--------------------------------------------------------------------------------
/HeightmapGenerator/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 |
5 | #include "ofxXmlSettings.h"
6 | #include "ofxDatGui.h"
7 | #include "ofxImageSequenceRecorder.h"
8 |
9 | #include "Config.h"
10 | #include "HeightmapRenderer.h"
11 | #include "HeightmapExporter.h"
12 |
13 | class ofApp : public ofBaseApp{
14 |
15 | public:
16 | void setup();
17 | void update();
18 | void draw();
19 | void exit();
20 |
21 | void loadGui();
22 | void saveGui();
23 |
24 | void loadFrame();
25 |
26 | void loadTake();
27 | void loadTakeWithDialog();
28 |
29 | void exportTake();
30 |
31 | void onSliderEvent(ofxDatGuiSliderEvent e);
32 | void onToggleEvent(ofxDatGuiToggleEvent e);
33 |
34 | void keyPressed(int key);
35 | void keyReleased(int key);
36 | void mouseMoved(int x, int y );
37 | void mouseDragged(int x, int y, int button);
38 | void mousePressed(int x, int y, int button);
39 | void mouseReleased(int x, int y, int button);
40 | void mouseEntered(int x, int y);
41 | void mouseExited(int x, int y);
42 | void windowResized(int w, int h);
43 | void dragEvent(ofDragInfo dragInfo);
44 | void gotMessage(ofMessage msg);
45 |
46 | // util
47 | stringstream ss;
48 |
49 | // objects
50 | HeightmapRenderer hmr;
51 | HeightmapExporter exporter;
52 |
53 | // status
54 | string takeName;
55 | vector frameList;
56 | int currentFrame = 0;
57 | int totalFrame = 0;
58 | bool needsUpdate = false;
59 |
60 | // gui
61 | ofxDatGui* gui;
62 | ofxDatGuiLabel* guiTakeName;
63 |
64 | };
65 |
--------------------------------------------------------------------------------
/HeightmapGenerator/src/HeightmapExporter.h:
--------------------------------------------------------------------------------
1 | //
2 | // HeightmapExporter.h
3 | // Kinect2Test
4 | //
5 | // Created by Baku Hashimoto on 7/21/16.
6 | //
7 | //
8 |
9 | #pragma once
10 |
11 | #include "ofMain.h"
12 | #include "HeightmapRenderer.h"
13 |
14 | #include "Config.h"
15 |
16 | class HeightmapExporter {
17 | private:
18 | ofDirectory srcDir;
19 | string takeName;
20 | HeightmapRenderer hmr;
21 | ofFloatPixels rendereredImage;
22 |
23 | public:
24 |
25 |
26 | void start(const HeightmapRenderer _hmr, const string _takeName) {
27 | takeName = _takeName;
28 | srcDir = ofDirectory(ofToDataPath(SAVED_DIR + "/" + takeName + "/" + INPAINTED_NAME));
29 | srcDir.allowExt("exr");
30 |
31 | hmr.captureNear = _hmr.captureNear;
32 | hmr.captureFar = _hmr.captureFar;
33 | hmr.near = _hmr.near;
34 | hmr.far = _hmr.far;
35 | hmr.scale = _hmr.scale;
36 |
37 | hmr.captureSize.set(_hmr.captureSize);
38 | hmr.focus.set(_hmr.focus);
39 | hmr.translation.set(_hmr.translation);
40 |
41 | hmr.isPreview = false;
42 |
43 | // load
44 | int i = 0;
45 |
46 | for (auto file : srcDir.getFiles()) {
47 | processImage(file);
48 | }
49 | }
50 |
51 | void processImage(ofFile file) {
52 | // load image
53 | string path = file.getAbsolutePath();
54 | hmr.loadTexture(path);
55 | hmr.render();
56 | hmr.getTexture().readToPixels(rendereredImage);
57 |
58 |
59 | ofStringReplace(path, (const string &)INPAINTED_NAME, (const string &)HEIGHTMAP_NAME);
60 | ofSaveImage(rendereredImage, path);
61 | }
62 |
63 |
64 | };
--------------------------------------------------------------------------------
/KinectRecorder/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxMultiKinectV2.h"
5 | #include "ofxDatGui.h"
6 | #include "ofxImageSequenceRecorder.h"
7 | #include "ofxXmlSettings.h"
8 |
9 | #include "PostProcessing.h"
10 | #include "DepthFiller.h"
11 |
12 | #include "Config.h"
13 |
14 |
15 | class ofApp : public ofBaseApp{
16 |
17 | public:
18 | void setup();
19 | void update();
20 | void draw();
21 | void exit();
22 |
23 | void initScene();
24 | void drawScene();
25 | void drawUi();
26 |
27 | void loadGui();
28 | void saveGui();
29 |
30 | void doPostProcessing();
31 |
32 | string getTakeName();
33 |
34 | void keyPressed(int key);
35 |
36 | // mesh
37 | ofEasyCam camera;
38 | ofCamera orthoCamera;
39 | ofShader pointShader;
40 | ofMesh mesh;
41 |
42 | ofShader depthShader, filledShader;
43 |
44 | // kinect
45 | ofxMultiKinectV2 kinect;
46 |
47 | DepthFiller depthFiller;
48 | ofFloatPixels depthPixels, testPixels, testFilledPixels;
49 | ofFloatImage depthImage, testImage, testFilledImage;
50 |
51 | ofxImageSequenceRecorder recorder;
52 |
53 | PostProcessing postProcessing;
54 |
55 | ofPolyline guide;
56 |
57 |
58 | stringstream ss;
59 | bool isRecording = false;
60 | bool willStopRecording = false;
61 | bool isPreviewHeight = false;
62 | bool isPreviewThumb = true;
63 | bool isFlipHorizontal = true;
64 | string takeName;
65 |
66 |
67 | // parameters
68 | ofxDatGui* gui;
69 | float near, far; // cm
70 | int cropWidth, cropHeight;
71 | ofVec2f focus;
72 |
73 |
74 | };
75 |
--------------------------------------------------------------------------------
/Calibration/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxMultiKinectV2.h"
5 | #include "ofxKinectProjectorToolkitV2.h"
6 | #include "ofxOpenCv.h"
7 | #include "ofxCv.h"
8 | #include "ofxSecondWindow.h"
9 |
10 |
11 | // this must match the display resolution of your projector
12 | #define PROJECTOR_RESOLUTION_X 1280
13 | #define PROJECTOR_RESOLUTION_Y 720
14 |
15 |
16 | class ofApp : public ofBaseApp{
17 |
18 | public:
19 | void setup();
20 | void update();
21 | void draw();
22 |
23 | void keyPressed(int key);
24 | void keyReleased(int key);
25 | void mouseMoved(int x, int y );
26 | void mouseDragged(int x, int y, int button);
27 | void mousePressed(int x, int y, int button);
28 | void mouseReleased(int x, int y, int button);
29 | void windowResized(int w, int h);
30 | void dragEvent(ofDragInfo dragInfo);
31 | void gotMessage(ofMessage msg);
32 |
33 | void drawChessboard(int x, int y, int chessboardSize);
34 | void drawTestingPoint(ofVec2f projectedPoint);
35 | void addPointPair();
36 |
37 | ofxKinectProjectorToolkitV2 kpt;
38 | ofxMultiKinectV2 kinect;
39 | ofxSecondWindow secondWindow;
40 |
41 | ofShader depthShader;
42 | ofTexture colorTex;
43 | ofTexture depthTex;
44 | GpuRegistration gr;
45 | ofFbo fboChessboard;
46 | ofxCvColorImage rgbImage;
47 | cv::Mat cvRgbImage;
48 | ofPixels pix;
49 | ofFbo fbo;
50 |
51 | vector currentProjectorPoints;
52 | vector cvPoints;
53 | vector pairsKinect;
54 | vector pairsProjector;
55 |
56 | string resultMessage;
57 | ofColor resultMessageColor;
58 | ofVec2f testPoint;
59 |
60 | int chessboardSize;
61 | int chessboardX;
62 | int chessboardY;
63 | bool searching;
64 | bool testing;
65 | bool saved;
66 | };
67 |
--------------------------------------------------------------------------------
/KinectRecorder/src/DepthFiller.h:
--------------------------------------------------------------------------------
1 | //
2 | // Utils.h
3 | // Kinect2Test
4 | //
5 | // Created by 麦 on 7/22/16.
6 | //
7 | //
8 |
9 | #pragma once
10 |
11 | #include "ofMain.h"
12 | #include "ofxCv.h"
13 |
14 | #include
15 |
16 | class DepthFiller {
17 | private:
18 |
19 | int w, h;
20 | ofPixels depthPixels, maskPixels, inpaintedPixels;
21 | cv::Mat depthImage;
22 | cv::Mat maskImage;
23 |
24 | public:
25 |
26 | float radius = 3.0;
27 |
28 | void allocate(int _w, int _h) {
29 | w = _w;
30 | h = _h;
31 |
32 | depthPixels.allocate(w, h, OF_IMAGE_GRAYSCALE);
33 | maskPixels.allocate(w, h, OF_IMAGE_GRAYSCALE);
34 | inpaintedPixels.allocate(w, h, OF_IMAGE_GRAYSCALE);
35 | }
36 |
37 | ofFloatPixels inpaint(ofFloatPixels srcPixels) {
38 |
39 | int x, y, offset;
40 |
41 | // copy to cv context
42 | for (y = 0; y < h; y++) {
43 | for (x = 0; x < w; x++) {
44 | offset = y * w + x;
45 | depthPixels[offset] = srcPixels[offset * 3] * 255;
46 | maskPixels[offset] = srcPixels[offset * 3 + 1] > 0.5 ? 255 : 0;
47 | }
48 | }
49 | depthImage = ofxCv::toCv(depthPixels);
50 | maskImage = ofxCv::toCv(maskPixels);
51 |
52 | cv::inpaint(depthImage, maskImage, depthImage, (double)radius, cv::INPAINT_TELEA);
53 | ofxCv::toOf(depthImage, inpaintedPixels);
54 |
55 | // composite with original image
56 | for (y = 0; y < h; y++) {
57 | for (x = 0; x < w; x++) {
58 | offset = y * w + x;
59 | if (maskPixels[offset] > 0.5) {
60 | srcPixels[offset * 3 ] = inpaintedPixels[offset] / 255.0f;
61 | srcPixels[offset * 3 + 1] = inpaintedPixels[offset] / 255.0f;
62 | srcPixels[offset * 3 + 2] = inpaintedPixels[offset] / 255.0f;
63 | } else {
64 | srcPixels[offset * 3 ] = srcPixels[offset * 3];
65 | srcPixels[offset * 3 + 1] = srcPixels[offset * 3];
66 | srcPixels[offset * 3 + 2] = srcPixels[offset * 3];
67 | }
68 | }
69 | }
70 |
71 | return srcPixels;
72 | }
73 | };
--------------------------------------------------------------------------------
/Shooting/src/ofxStopwatch.h:
--------------------------------------------------------------------------------
1 | //
2 | // ofxStopwatch.h
3 | // Shooting
4 | //
5 | // Created by Baku Hashimoto on 7/30/16.
6 | //
7 | //
8 |
9 | #pragma once
10 |
11 | #include "ofMain.h"
12 |
13 | class ofxStopwatch {
14 | public:
15 |
16 | ofxStopwatch() {
17 | prevTime = ofGetElapsedTimef();
18 | }
19 |
20 | void reset() {
21 | this->reset(0.0f);
22 | }
23 | void reset(float initialTime) {
24 | elapsedTime = initialTime;
25 | prevTime = ofGetElapsedTimef();
26 | }
27 |
28 | void stop() {
29 | enabled = false;
30 | }
31 |
32 | void start() {
33 | enabled = true;
34 | prevTime = ofGetElapsedTimef();
35 | }
36 |
37 | float getTime() {
38 | update();
39 | return elapsedTime;
40 | }
41 |
42 | string getTimeString() {
43 | update();
44 |
45 | int t = elapsedTime;
46 | int h, m, s;
47 | string str = "";
48 |
49 | h = floor(t / 3600);
50 | t -= h * 3600;
51 |
52 | m = floor(t / 60);
53 | t -= m * 60;
54 |
55 | s = t;
56 |
57 | if (h > 0) {
58 | str += ofToString(h) + ":";
59 | }
60 |
61 | str += ofToString(m, 2, '0') + ":" + ofToString(s, 2, '0');
62 |
63 | return str;
64 | }
65 |
66 | bool isEnabled() {
67 | return enabled;
68 | }
69 |
70 | void toggle(bool _enabled) {
71 | if (_enabled) {
72 | start();
73 | } else {
74 | stop();
75 | }
76 | }
77 |
78 | private:
79 |
80 | void update() {
81 | if (enabled) {
82 | float currentTime = ofGetElapsedTimef();
83 | elapsedTime += currentTime - prevTime;
84 | prevTime = currentTime;
85 | }
86 | }
87 |
88 | bool enabled = true;
89 | float elapsedTime = 0, prevTime;
90 |
91 | };
--------------------------------------------------------------------------------
/KinectRecorder/src/PostProcessing.h:
--------------------------------------------------------------------------------
1 | //
2 | // PostProcessing.h
3 | // Kinect2Test
4 | //
5 | // Created by Baku Hashimoto on 7/21/16.
6 | //
7 | //
8 |
9 | #pragma once
10 |
11 | #include "ofMain.h"
12 | #include "DepthFiller.h"
13 |
14 | #include "Config.h"
15 |
16 | //string replaceString(string subject, string search, string replace) {
17 | // string::size_type pos = subject.find(search);
18 | // while(pos != string::npos){
19 | // subject.replace(pos, search.size(), replace);
20 | // pos = subject.find(search, pos + replace.size());
21 | // }
22 | //
23 | // return subject;
24 | //}
25 |
26 | class PostProcessing : public ofThread {
27 | private:
28 | ofDirectory srcDir;
29 | stringstream ss;
30 | string takeName;
31 | DepthFiller depthFiller;
32 | ofFloatImage srcImage;
33 | ofFloatPixels srcPixels;
34 |
35 | public:
36 | float progress = 0.0;
37 | float radius = 3.0;
38 |
39 | PostProcessing() : ofThread() {
40 |
41 | depthFiller.allocate(DEPTH_WIDTH, DEPTH_HEIGHT);
42 | }
43 |
44 |
45 | void setup(string _takeName) {
46 | takeName = _takeName;
47 | srcDir = ofDirectory(ofToDataPath(SAVED_DIR + "/" + takeName + "/" + RAW_NAME));
48 | srcDir.allowExt("exr");
49 | }
50 |
51 | void threadedFunction() {
52 | int i = 0;
53 |
54 | int w = DEPTH_WIDTH;
55 | int h = DEPTH_HEIGHT;
56 |
57 | for (auto file : srcDir.getFiles()) {
58 | processImage(file);
59 | progress = (float)++i / srcDir.size();
60 | }
61 | }
62 |
63 | // https://github.com/mazbox/ofxKinectInpainter/blob/master/src/ofxKinectInpainter.h
64 | void processImage(ofFile file) {
65 |
66 | // load image
67 | ofLoadImage(srcImage, file.getAbsolutePath());
68 | srcPixels = srcImage.getPixels();
69 |
70 | depthFiller.radius = radius;
71 | srcPixels = depthFiller.inpaint(srcPixels);
72 |
73 | string basename = file.getBaseName();
74 |
75 | ofStringReplace(basename, (const string &)RAW_NAME, (const string &)INPAINTED_NAME);
76 |
77 | string path = SAVED_DIR + "/" + takeName + "/" + INPAINTED_NAME + "/" + (string)basename + ".exr";
78 |
79 | ofSaveImage(srcPixels, ofToDataPath(path));
80 | }
81 |
82 |
83 | };
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Shooting System for 'depthcope'
2 |
3 | 
4 |
5 | A set of tools for 'depthcope', which I tried 3d rotoscoping. This system uses a pair of Kinect and projector, and measures a height of each points of surface from a reference plane. Then comparing them to 'height map' of a target form, this app projects the point clouds of colours which represents whether the point is higher(red) or lower(blue) than the target height. If the difference between a target height and a measured height is less than specified torelance, it's represented as green. When all dots on the surface turn into green, the form on the plane is almost accurate comparing to target form.
6 |
7 | [depthcope](http://baku89.com/work/depthcope)
8 |
9 | As result it works like 'human-powered 3d printer'.
10 |
11 | ## Environments
12 |
13 | - openFrameworks v0.9.4 or newer
14 | - the environemnt which supports [ofxMultiKinectV2](https://github.com/hanasaan/ofxMultiKinectV2). I've checked the following environments work well.
15 | * MacBook Pro Mid 2012 (16GB RAM, 2.7GHz i7)
16 | * Mac Pro Late 2013 (64GB RAM, 8 cores)
17 |
18 | ## How to build
19 |
20 | This repo is a set of oF project, so you'll need to clone to one deeper directory from oF installed path. For example, `(OF_PATH)/apps/(THIS_REPO)`
21 |
22 | ## Dependencies
23 |
24 | ### Softwares
25 |
26 | - [Dragonframe](http://www.dragonframe.com/)
27 |
28 | ### oF Addons
29 |
30 | Please reference the each repo to setup.
31 |
32 | - [ofxMultiKinectV2](https://github.com/hanasaan/ofxMultiKinectV2)
33 | - [ofxTurboJpeg](https://github.com/armadillu/ofxTurboJpeg)
34 | - [ofxDatGui](https://github.com/braitsch/ofxDatGui)
35 | - [ofxSecondWindow](https://github.com/genekogan/ofxSecondWindow)
36 | - [ofxCv](https://github.com/kylemcdonald/ofxCv)
37 | - [ofxofxKinectProjectorToolkitV2](https://github.com/genekogan/ofxKinectProjectorToolkitV2)
38 | - [ofxJSON](https://github.com/jefftimesten/ofxJSON)
39 | - [ofxGrabCam](https://github.com/elliotwoods/ofxGrabCam)
40 |
41 | ### Others
42 |
43 | - [dragonframe-osc](https://github.com/baku89/dragonframe-osc): used to detect the events of Dragonframe to sync frame to shoot
44 |
45 | ## License
46 |
47 | This repository is published under a MIT License. See the included LICENSE file.
48 |
--------------------------------------------------------------------------------
/Shooting/src/DiscController.h:
--------------------------------------------------------------------------------
1 | //
2 | // DiscController.h
3 | // Shooting
4 | //
5 | // Created by Baku Hashimoto on 7/30/16.
6 | //
7 | //
8 |
9 | #pragma once
10 |
11 | #include "ofMain.h"
12 |
13 | #define DATA_LENGTH 3
14 |
15 | #define STEPPER_RPM 800
16 | #define ENCODER_RPM 360
17 |
18 | #define ENCODER_STEP 0.1481481481
19 |
20 | class DiscController {
21 | public:
22 |
23 | void setup(string port, float initialAngle) {
24 |
25 | serial.setup(port, 9600);
26 |
27 | currentAngle = initialAngle;
28 | }
29 |
30 | void update() {
31 |
32 | while (serial.available() >= 3) {
33 |
34 | char code = serial.readByte();
35 |
36 | if (code == 'H') {
37 | unsigned char low = serial.readByte();
38 | unsigned char high = serial.readByte();
39 |
40 | int value = (high << 8) | low;
41 | cout << "code=" << code << "\tvalue=" << value << endl;
42 |
43 | } else if (code == 'D') {
44 | bRotating = false;
45 | }
46 |
47 | }
48 | }
49 |
50 | void rotate(float degrees) {
51 | if (bRotating) {
52 | ofLogError() << "DiscController: cannot rotate while rotating";
53 | return;
54 | }
55 |
56 | currentAngle += degrees;
57 |
58 | float rotateDegrees = degrees;
59 |
60 | ofLogNotice() << "Rotating..." + ofToString(rotateDegrees, 2) + "deg";
61 |
62 | unsigned int minutes = rotateDegrees * 60;
63 | unsigned char buff[3] = {'R', (unsigned char)(minutes & 0xff), (unsigned char)((minutes >> 8) & 0xff)};
64 | serial.writeBytes(&buff[0], 3);
65 |
66 | bRotating = true;
67 | }
68 |
69 | float getAngle() {
70 | return currentAngle;
71 | }
72 |
73 | void setAngle(float degrees) {
74 | currentAngle = degrees;
75 | }
76 |
77 | bool isRotating() {
78 | return bRotating;
79 | }
80 |
81 | private:
82 |
83 | ofSerial serial;
84 |
85 | float currentAngle;
86 |
87 | bool bRotating = false;
88 |
89 |
90 |
91 | };
--------------------------------------------------------------------------------
/Shooting/src/ofxMultiKinectV2Mod.h:
--------------------------------------------------------------------------------
1 | //
2 | // ofxMultiKinectV2Mod
3 | //
4 | // Created by Yuya Hanai on 10/16/14.
5 | //
6 |
7 | #pragma once
8 | #include "ofMain.h"
9 |
10 | #define USE_OFX_TURBO_JPEG
11 |
12 | #ifdef USE_OFX_TURBO_JPEG
13 | #include "ofxTurboJpeg.h"
14 | #endif
15 |
16 | class ofProtonect2;
17 |
18 | class ofxMultiKinectV2Mod : public ofThread
19 | {
20 | public:
21 | ofxMultiKinectV2Mod();
22 | ~ofxMultiKinectV2Mod();
23 |
24 | static int getDeviceCount();
25 | void open(bool enableColor = true, bool enableIr = true, int deviceIndex = 0, int oclDeviceIndex = -1);
26 | void start();
27 | void update();
28 | void close();
29 |
30 | bool isFrameNew();
31 |
32 | ofPixels& getColorPixelsRef();
33 | ofFloatPixels& getDepthPixelsRef();
34 | ofFloatPixels& getIrPixelsRef();
35 |
36 | const vector& getJpegBuffer();
37 |
38 | void setEnableJpegDecode(bool b) {bEnableJpegDecode = b;}
39 | bool isEnableJpegDecode() {return bEnableJpegDecode;}
40 | void setEnableFlipBuffer(bool b) {bEnableFlipBuffer = b;}
41 | bool isEnableFlipBuffer() {return bEnableFlipBuffer;}
42 |
43 | ofProtonect2* getProtonect() {return protonect2;}
44 |
45 | float getDistanceAt(int x, int y);
46 | ofVec3f getWorldCoordinateAt(int x, int y);
47 | ofVec3f getWorldCoordinateAt(int x, int y, float z);
48 |
49 | ofVec2f getFocus();
50 |
51 | float feedbackRate = 0.1;
52 |
53 | protected:
54 | void threadedFunction();
55 |
56 | bool bEnableJpegDecode;
57 | bool bOpened;
58 | bool bNewBuffer;
59 | bool bNewFrame;
60 | bool bEnableFlipBuffer;
61 |
62 |
63 |
64 | ofPixels colorPix;
65 | ofPixels colorPixFront;
66 | ofPixels colorPixBack;
67 |
68 | vector jpeg;
69 | vector jpegFront;
70 | vector jpegBack;
71 |
72 | ofFloatPixels irPix;
73 | ofFloatPixels irPixFront;
74 | ofFloatPixels irPixBack;
75 |
76 | ofFloatPixels depthPix, depthPixDistance;
77 | ofFloatPixels depthPixFront;
78 | ofFloatPixels depthPixBack;
79 |
80 | ofProtonect2* protonect2;
81 |
82 | int lastFrameNo;
83 |
84 | #ifdef USE_OFX_TURBO_JPEG
85 | ofxTurboJpeg turbo;
86 | #endif
87 |
88 | };
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | saved
2 |
3 | #########################
4 | # openFrameworks patterns
5 | #########################
6 |
7 | # build files
8 | openFrameworks.a
9 | openFrameworksDebug.a
10 | openFrameworksUniversal.a
11 | libs/openFrameworksCompiled/lib/*/*
12 | !libs/openFrameworksCompiled/lib/*/.gitkeep
13 |
14 | # apothecary
15 | scripts/apothecary/build
16 |
17 | # rule to avoid non-official addons going into git
18 | # see addons/.gitignore
19 | addons/*
20 |
21 | # rule to avoid non-official apps going into git
22 | # see apps/.gitignore
23 | apps/*
24 |
25 | # also, see examples/.gitignore
26 |
27 | #########################
28 | # general
29 | #########################
30 |
31 | [Bb]uild/
32 | [Oo]bj/
33 | *.o
34 | examples/**/[Dd]ebug*/
35 | examples/**/[Rr]elease*/
36 | examples/**/gcc-debug/
37 | examples/**/gcc-release/
38 | tests/**/[Dd]ebug*/
39 | tests/**/[Rr]elease*/
40 | tests/**/gcc-debug/
41 | tests/**/gcc-release/
42 | *.mode*
43 | *.app/
44 | *.pyc
45 | .svn/
46 | *.log
47 | *.cpp.eep
48 | *.cpp.elf
49 | *.cpp.hex
50 |
51 | #########################
52 | # IDE
53 | #########################
54 |
55 | # XCode
56 | *.pbxuser
57 | *.perspective
58 | *.perspectivev3
59 | *.mode1v3
60 | *.mode2v3
61 | # XCode 4
62 | xcuserdata
63 | *.xcworkspace
64 |
65 | # Code::Blocks
66 | *.depend
67 | *.layout
68 |
69 | # Visual Studio
70 | *.sdf
71 | *.opensdf
72 | *.suo
73 | *.pdb
74 | *.ilk
75 | *.aps
76 | ipch/
77 |
78 | # Eclipse
79 | .metadata
80 | local.properties
81 | .externalToolBuilders
82 |
83 | # Android Studio
84 | .idea
85 | .gradle
86 | gradle
87 | gradlew
88 | gradlew.bat
89 |
90 | # QtCreator
91 | *.qbs.user
92 | *.pro.user
93 | *.pri
94 |
95 |
96 | #########################
97 | # operating system
98 | #########################
99 |
100 | # Linux
101 | *~
102 | # KDE
103 | .directory
104 | .AppleDouble
105 |
106 | # OSX
107 | .DS_Store
108 | *.swp
109 | *~.nib
110 | # Thumbnails
111 | ._*
112 | examples/ios/**/mediaAssets
113 |
114 | # Windows
115 | # Windows image file caches
116 | Thumbs.db
117 | # Folder config file
118 | Desktop.ini
119 |
120 | # Android
121 | .csettings
122 | /libs/openFrameworksCompiled/project/android/paths.make
123 |
124 | # Android Studio
125 | *.iml
126 |
127 | #########################
128 | # miscellaneous
129 | #########################
130 |
131 | .mailmap
132 | /apps*/
133 |
--------------------------------------------------------------------------------
/HeightmapGenerator/src/HeightmapRenderer.h:
--------------------------------------------------------------------------------
1 | //
2 | // HeightmapRenderer.h
3 | // HeightmapGenerator
4 | //
5 | // Created by Baku Hashimoto on 7/22/16.
6 | //
7 | //
8 |
9 | #pragma once
10 |
11 | #include "ofMain.h"
12 | #include "Config.h"
13 |
14 | class HeightmapRenderer {
15 | public:
16 |
17 | float captureNear, captureFar, near, far;
18 | float scale = 1;
19 | ofVec2f focus, captureSize, translation;
20 | bool isPreview;
21 |
22 | HeightmapRenderer() {
23 | captureSize.set(8, 8);
24 | focus.set(0, 0);
25 |
26 | shader.load("heightmap");
27 |
28 | plane.set(DEPTH_WIDTH, DEPTH_HEIGHT);
29 | plane.setResolution(DEPTH_WIDTH, DEPTH_HEIGHT);
30 | }
31 |
32 | void render() {
33 |
34 | if (fbo.getWidth() != captureSize.x || fbo.getHeight() != captureSize.y) {
35 | alloate();
36 | }
37 |
38 | fbo.begin();
39 | {
40 | ofBackground(0);
41 |
42 | if (depthImage.isAllocated()) {
43 | ofSetColor(255, 255, 255);
44 |
45 | shader.begin();
46 | {
47 | shader.setUniformTexture("depth", depthImage.getTexture(), 0);
48 | shader.setUniform1f("near", near);
49 | shader.setUniform1f("far", far);
50 | shader.setUniform1f("scale", scale);
51 | shader.setUniform1f("captureNear", captureNear);
52 | shader.setUniform1f("captureFar", captureFar);
53 | shader.setUniform2f("focus", focus.x, focus.y);
54 | shader.setUniform2f("translation", translation.x, translation.y);
55 | shader.setUniform2f("captureSize", captureSize.x, captureSize.y);
56 | shader.setUniform1i("isPreview", (int)isPreview);
57 |
58 | plane.draw();
59 | }
60 |
61 | shader.end();
62 | }
63 | }
64 | fbo.end();
65 | }
66 |
67 | void loadTexture(string path) {
68 | ofLogNotice() << "loading: " << path;
69 | depthImage.load(path);
70 | }
71 |
72 | ofTexture getTexture() {
73 | return fbo.getTexture();
74 | }
75 |
76 | int getWidth() {
77 | return (int)captureSize.x;
78 | }
79 | int getHeight() {
80 | return (int)captureSize.y;
81 | }
82 |
83 | private:
84 |
85 | ofFbo fbo;
86 | ofPlanePrimitive plane;
87 | ofShader shader;
88 | ofFloatImage depthImage;
89 |
90 | void alloate() {
91 | int w = getWidth();
92 | int h = getHeight();
93 | fbo.allocate(w, h, GL_RGBA32F);
94 | }
95 | };
--------------------------------------------------------------------------------
/Shooting/bin/data/heightmap.vert:
--------------------------------------------------------------------------------
1 | #version 120
2 |
3 | #define HEIGHTMAP_DEPTH 30.0
4 | #define HEIGHTMAP_WIDTH 1024.0
5 |
6 | uniform float coff0;
7 | uniform float coff1;
8 | uniform float coff2;
9 | uniform float coff3;
10 | uniform float coff4;
11 | uniform float coff5;
12 | uniform float coff6;
13 | uniform float coff7;
14 | uniform float coff8;
15 | uniform float coff9;
16 | uniform float coff10;
17 |
18 | uniform vec2 projectorSize;
19 | uniform vec2 projectorOffset;
20 | uniform float tolerance;
21 |
22 | uniform mat4 discInvMat;
23 |
24 | uniform sampler2DRect heightmap;
25 | uniform sampler2DRect overlay;
26 |
27 | uniform int showOverlay;
28 | uniform int showHeightmap;
29 |
30 | // uniform sampler2DRect depth;
31 | // uniform vec2 focus;
32 | // uniform float near;
33 | // uniform float far;
34 |
35 | varying vec4 color;
36 |
37 |
38 | // ------------------------------------------
39 |
40 | vec3 postMult(mat4 mat, vec3 v) {
41 | float d = 1.0 / (mat[3][0] * v.x + mat[3][1] * v.y + mat[3][2] * v.z + mat[3][3]);
42 | return vec3( (mat[0][0]*v.x + mat[0][1]*v.y + mat[0][2]*v.z + mat[0][3])*d,
43 | (mat[1][0]*v.x + mat[1][1]*v.y + mat[1][2]*v.z + mat[1][3])*d,
44 | (mat[2][0]*v.x + mat[2][1]*v.y + mat[2][2]*v.z + mat[2][3])*d );
45 | }
46 |
47 |
48 | float map(float value, float inMin, float inMax, float outMin, float outMax) {
49 | return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
50 | }
51 |
52 | vec2 map(vec2 value, vec2 inMin, vec2 inMax, vec2 outMin, vec2 outMax) {
53 | return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
54 | }
55 |
56 | // ------------------------------------------
57 |
58 |
59 | void main() {
60 |
61 | // ------------------------------------------
62 | // 0. get world coord
63 |
64 | // ------------------------------------------
65 | // 1. get height and calc color
66 |
67 | vec3 dc = postMult(discInvMat, gl_Vertex.xyz);
68 |
69 | vec2 duv = map(dc.xy, vec2(-30.0), vec2(30.0), vec2(0.0, HEIGHTMAP_WIDTH), vec2(HEIGHTMAP_WIDTH, 0.0));
70 | // duv.y = HEIGHTMAP_WIDTH - duv.y;
71 |
72 | float th = texture2DRect(heightmap, duv).r * 30.0;
73 | float h = dc.z;
74 |
75 | color = vec4(0.0, 0.0, 0.0, 1.0);
76 |
77 | if (0.0 <= h && h <= HEIGHTMAP_DEPTH) {
78 | if (showHeightmap == 1) {
79 | if (th < h) {
80 | float m = map(h, th, th + tolerance, 0.0, 1.0);
81 | color += vec4(m, 1.0 - m, 0.0, 1.0);
82 | } else {
83 | float m = map(h, th, th - tolerance, 0.0, 1.0);
84 | color += vec4(0.0, 1.0 - m, m, 1.0);
85 | }
86 | }
87 |
88 | if (showOverlay == 1) {
89 | color += vec4(texture2DRect(overlay, duv).g);
90 | }
91 |
92 | } else {
93 | color = vec4(0.0);
94 | }
95 |
96 |
97 | // ------------------------------------------
98 | // 2. project to projector coordinates
99 |
100 | // fron ofxKinectProjectorToolkitV2
101 | vec3 p = gl_Vertex.xyz * vec3(1.0, 1.0, -1.0);
102 |
103 | float a = coff0 * p.x + coff1 * p.y + coff2 * p.z + coff3;
104 | float b = coff4 * p.x + coff5 * p.y + coff6 * p.z + coff7;
105 | float c = coff8 * p.x + coff9 * p.y + coff10 * p.z + 1.0;
106 | vec2 pCoord = vec2(a / c, b / c) * projectorSize + projectorOffset;
107 |
108 | gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(pCoord, 0.0, 1.0);
109 | }
--------------------------------------------------------------------------------
/Shooting/Shooting.xcodeproj/xcshareddata/xcschemes/Shooting Debug.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/Shooting/Shooting.xcodeproj/xcshareddata/xcschemes/Shooting Release.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/Calibration/calibration.xcodeproj/xcshareddata/xcschemes/calibration Debug.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/Calibration/calibration.xcodeproj/xcshareddata/xcschemes/calibration Release.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/HeightmapGenerator/HeightmapGenerator.xcodeproj/xcshareddata/xcschemes/HeightmapGenerator Debug.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/HeightmapGenerator/HeightmapGenerator.xcodeproj/xcshareddata/xcschemes/HeightmapGenerator Release.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/KinectRecorder/KinectRecorder.xcodeproj/xcshareddata/xcschemes/Kinect2Test Debug.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/KinectRecorder/KinectRecorder.xcodeproj/xcshareddata/xcschemes/Kinect2Test Release.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/Shooting/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxMultiKinectV2Mod.h"
5 | #include "ofxDatGui.h"
6 | #include "ofxJSON.h"
7 | #include "ofxCv.h"
8 | #include "ofxOpenCv.h"
9 | #include "ofxSecondWindow.h"
10 | #include "ofxKinectProjectorToolkitV2.h"
11 | #include "ofxGrabCam.h"
12 | #include "ofxDmx.h"
13 | #include "ofxOsc.h"
14 | #include "ofxImageSequenceLoader.h"
15 | #include "ofxStopwatch.h"
16 |
17 | #include "DiscController.h"
18 |
19 | #include "Config.h"
20 |
21 | #define MODE_CALIBRATION 1
22 | #define MODE_SHOOTING 2
23 |
24 | #define F_ORIGIN 0
25 | #define F_AXIS_X 1
26 | #define F_AXIS_Y 2
27 | #define F_DISPLAY 3
28 |
29 | class ofApp : public ofBaseApp{
30 |
31 | public:
32 | void setup();
33 | void update();
34 |
35 | void initShooting();
36 |
37 | void initScene();
38 | void updateScene();
39 | void drawScene();
40 |
41 | void draw();
42 | void drawCalibration();
43 | void drawShooting();
44 |
45 | void exit();
46 |
47 | void loadGui();
48 | // void updateGui();
49 | void saveGui();
50 |
51 | void onSliderEvent(ofxDatGuiSliderEvent e);
52 | void onToggleEvent(ofxDatGuiToggleEvent e);
53 | void onButtonEvent(ofxDatGuiButtonEvent e);
54 | void on2dPadEvent(ofxDatGui2dPadEvent e);
55 |
56 | void keyPressed(int key);
57 | void keyReleased(int key);
58 |
59 | // calibration
60 | string getCurrentFeatureName();
61 | void moveFeature(float x, float y);
62 | void makeDiscMask();
63 |
64 | ofVec2f getProj(ofVec3f wc);
65 | ofVec3f getDisc(ofVec3f wc);
66 | ofVec3f getWorldFromDisc(ofVec2f dc);
67 | ofVec2f getProjFromDisc(ofVec2f dc);
68 | ofVec2f getProjFromDisc(float x, float y) { return getProjFromDisc(ofVec2f(x, y)); }
69 |
70 | // util
71 | string toString(ofVec2f val);
72 | string toString(ofVec3f val);
73 |
74 |
75 | // visualize
76 | ofFbo view3d;
77 | ofxGrabCam camera;
78 | ofShader pointShader;
79 | ofMesh depthPointCloud;
80 | ofFloatPixels depthPixels;
81 | ofFloatImage depthImage;
82 |
83 | // kinect
84 | ofxKinectProjectorToolkitV2 kpt;
85 | ofxMultiKinectV2Mod kinect;
86 |
87 | ofShader depthShader, irShader;
88 | ofTexture depthTex, irTex, colorTex;
89 |
90 | int mode = MODE_CALIBRATION;
91 | int currentFeature = F_ORIGIN;
92 |
93 | int restCalibrationFrames = -1;
94 | bool useCalibrated = false;
95 |
96 | // util
97 | stringstream ss;
98 | ofxSecondWindow secondWindow;
99 |
100 | // decorative key
101 | bool altPressed = false;
102 | bool shiftPressed = false;
103 |
104 |
105 | ofPixels discMaskPixels;
106 | ofImage discMaskImage;
107 |
108 | // parameters
109 | ofxDatGui* gui;
110 | float projectorWidth, projectorHeight;
111 | ofVec2f kOrigin, kAxisX, kAxisY;
112 | ofVec3f wOrigin, wAxisX, wAxisY;
113 | ofMatrix4x4 discMat, discInvMat;
114 | float discMaskMargin;
115 | bool isDisplayIr;
116 | bool showScene;
117 |
118 | float near, far; // cm
119 | ofVec2f focus;
120 |
121 | float discMaskThreshold;
122 |
123 | //------------------------------------
124 | // shooting
125 | void sendDmx();
126 | void enableLight();
127 | void disableLight();
128 |
129 | void doBeforeShoot();
130 | void doAfterShoot();
131 | void loadHeightmap();
132 |
133 | ofMesh heightmapMesh;
134 | ofShader heightmapShader;
135 |
136 | ofPath contour;
137 |
138 | ofVec2f hudOrigin;
139 |
140 | ofxImageSequenceLoader heightmapLoader;
141 | ofxImageSequenceLoader overlayLoader;
142 |
143 | float tolerance;
144 | int currentFrame = -1;
145 | bool isDisplayHeightmap;
146 | bool forceDisplay = true;
147 |
148 | ofFloatPixels heightmapPixels, overlayPixels;
149 | ofPixels heightmapU8Pixels;
150 | ofFloatImage heightmapImage, overlayImage;
151 | ofxCvGrayscaleImage heightmapCvImage;
152 |
153 | ofxCvContourFinder contourFinder;
154 |
155 | ofxDmx dmx;
156 | float lightFront, lightBack;
157 | bool isPreviewLight = false;
158 | bool showOverlay;
159 | bool showHeightmap;
160 |
161 | ofxOscReceiver dfReceiver;
162 |
163 | // DiscController discController;
164 | float heightmapRotation;
165 | float rotateStep; // degrees
166 |
167 | ofFbo hud;
168 |
169 | // timer
170 | ofxStopwatch timer;
171 | };
172 |
--------------------------------------------------------------------------------
/Calibration/config.make:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # CONFIGURE PROJECT MAKEFILE (optional)
3 | # This file is where we make project specific configurations.
4 | ################################################################################
5 |
6 | ################################################################################
7 | # OF ROOT
8 | # The location of your root openFrameworks installation
9 | # (default) OF_ROOT = ../../..
10 | ################################################################################
11 | # OF_ROOT = ../../..
12 |
13 | ################################################################################
14 | # PROJECT ROOT
15 | # The location of the project - a starting place for searching for files
16 | # (default) PROJECT_ROOT = . (this directory)
17 | #
18 | ################################################################################
19 | # PROJECT_ROOT = .
20 |
21 | ################################################################################
22 | # PROJECT SPECIFIC CHECKS
23 | # This is a project defined section to create internal makefile flags to
24 | # conditionally enable or disable the addition of various features within
25 | # this makefile. For instance, if you want to make changes based on whether
26 | # GTK is installed, one might test that here and create a variable to check.
27 | ################################################################################
28 | # None
29 |
30 | ################################################################################
31 | # PROJECT EXTERNAL SOURCE PATHS
32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder.
33 | # Like source folders in the PROJECT_ROOT, these paths are subject to
34 | # exlclusion via the PROJECT_EXLCUSIONS list.
35 | #
36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank)
37 | #
38 | # Note: Leave a leading space when adding list items with the += operator
39 | ################################################################################
40 | # PROJECT_EXTERNAL_SOURCE_PATHS =
41 |
42 | ################################################################################
43 | # PROJECT EXCLUSIONS
44 | # These makefiles assume that all folders in your current project directory
45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations
46 | # to look for source code. The any folders or files that match any of the
47 | # items in the PROJECT_EXCLUSIONS list below will be ignored.
48 | #
49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete
50 | # string unless teh user adds a wildcard (%) operator to match subdirectories.
51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is
52 | # treated literally.
53 | #
54 | # (default) PROJECT_EXCLUSIONS = (blank)
55 | #
56 | # Will automatically exclude the following:
57 | #
58 | # $(PROJECT_ROOT)/bin%
59 | # $(PROJECT_ROOT)/obj%
60 | # $(PROJECT_ROOT)/%.xcodeproj
61 | #
62 | # Note: Leave a leading space when adding list items with the += operator
63 | ################################################################################
64 | # PROJECT_EXCLUSIONS =
65 |
66 | ################################################################################
67 | # PROJECT LINKER FLAGS
68 | # These flags will be sent to the linker when compiling the executable.
69 | #
70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs
71 | #
72 | # Note: Leave a leading space when adding list items with the += operator
73 | ################################################################################
74 |
75 | # Currently, shared libraries that are needed are copied to the
76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to
77 | # add a runtime path to search for those shared libraries, since they aren't
78 | # incorporated directly into the final executable application binary.
79 | # TODO: should this be a default setting?
80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs
81 |
82 | ################################################################################
83 | # PROJECT DEFINES
84 | # Create a space-delimited list of DEFINES. The list will be converted into
85 | # CFLAGS with the "-D" flag later in the makefile.
86 | #
87 | # (default) PROJECT_DEFINES = (blank)
88 | #
89 | # Note: Leave a leading space when adding list items with the += operator
90 | ################################################################################
91 | # PROJECT_DEFINES =
92 |
93 | ################################################################################
94 | # PROJECT CFLAGS
95 | # This is a list of fully qualified CFLAGS required when compiling for this
96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS
97 | # defined in your platform specific core configuration files. These flags are
98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below.
99 | #
100 | # (default) PROJECT_CFLAGS = (blank)
101 | #
102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in
103 | # your platform specific configuration file will be applied by default and
104 | # further flags here may not be needed.
105 | #
106 | # Note: Leave a leading space when adding list items with the += operator
107 | ################################################################################
108 | # PROJECT_CFLAGS =
109 |
110 | ################################################################################
111 | # PROJECT OPTIMIZATION CFLAGS
112 | # These are lists of CFLAGS that are target-specific. While any flags could
113 | # be conditionally added, they are usually limited to optimization flags.
114 | # These flags are added BEFORE the PROJECT_CFLAGS.
115 | #
116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets.
117 | #
118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank)
119 | #
120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets.
121 | #
122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank)
123 | #
124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the
125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration
126 | # file will be applied by default and further optimization flags here may not
127 | # be needed.
128 | #
129 | # Note: Leave a leading space when adding list items with the += operator
130 | ################################################################################
131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE =
132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG =
133 |
134 | ################################################################################
135 | # PROJECT COMPILERS
136 | # Custom compilers can be set for CC and CXX
137 | # (default) PROJECT_CXX = (blank)
138 | # (default) PROJECT_CC = (blank)
139 | # Note: Leave a leading space when adding list items with the += operator
140 | ################################################################################
141 | # PROJECT_CXX =
142 | # PROJECT_CC =
143 |
--------------------------------------------------------------------------------
/Shooting/config.make:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # CONFIGURE PROJECT MAKEFILE (optional)
3 | # This file is where we make project specific configurations.
4 | ################################################################################
5 |
6 | ################################################################################
7 | # OF ROOT
8 | # The location of your root openFrameworks installation
9 | # (default) OF_ROOT = ../../..
10 | ################################################################################
11 | # OF_ROOT = ../../..
12 |
13 | ################################################################################
14 | # PROJECT ROOT
15 | # The location of the project - a starting place for searching for files
16 | # (default) PROJECT_ROOT = . (this directory)
17 | #
18 | ################################################################################
19 | # PROJECT_ROOT = .
20 |
21 | ################################################################################
22 | # PROJECT SPECIFIC CHECKS
23 | # This is a project defined section to create internal makefile flags to
24 | # conditionally enable or disable the addition of various features within
25 | # this makefile. For instance, if you want to make changes based on whether
26 | # GTK is installed, one might test that here and create a variable to check.
27 | ################################################################################
28 | # None
29 |
30 | ################################################################################
31 | # PROJECT EXTERNAL SOURCE PATHS
32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder.
33 | # Like source folders in the PROJECT_ROOT, these paths are subject to
34 | # exlclusion via the PROJECT_EXLCUSIONS list.
35 | #
36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank)
37 | #
38 | # Note: Leave a leading space when adding list items with the += operator
39 | ################################################################################
40 | # PROJECT_EXTERNAL_SOURCE_PATHS =
41 |
42 | ################################################################################
43 | # PROJECT EXCLUSIONS
44 | # These makefiles assume that all folders in your current project directory
45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations
46 | # to look for source code. The any folders or files that match any of the
47 | # items in the PROJECT_EXCLUSIONS list below will be ignored.
48 | #
49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete
50 | # string unless teh user adds a wildcard (%) operator to match subdirectories.
51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is
52 | # treated literally.
53 | #
54 | # (default) PROJECT_EXCLUSIONS = (blank)
55 | #
56 | # Will automatically exclude the following:
57 | #
58 | # $(PROJECT_ROOT)/bin%
59 | # $(PROJECT_ROOT)/obj%
60 | # $(PROJECT_ROOT)/%.xcodeproj
61 | #
62 | # Note: Leave a leading space when adding list items with the += operator
63 | ################################################################################
64 | # PROJECT_EXCLUSIONS =
65 |
66 | ################################################################################
67 | # PROJECT LINKER FLAGS
68 | # These flags will be sent to the linker when compiling the executable.
69 | #
70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs
71 | #
72 | # Note: Leave a leading space when adding list items with the += operator
73 | ################################################################################
74 |
75 | # Currently, shared libraries that are needed are copied to the
76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to
77 | # add a runtime path to search for those shared libraries, since they aren't
78 | # incorporated directly into the final executable application binary.
79 | # TODO: should this be a default setting?
80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs
81 |
82 | ################################################################################
83 | # PROJECT DEFINES
84 | # Create a space-delimited list of DEFINES. The list will be converted into
85 | # CFLAGS with the "-D" flag later in the makefile.
86 | #
87 | # (default) PROJECT_DEFINES = (blank)
88 | #
89 | # Note: Leave a leading space when adding list items with the += operator
90 | ################################################################################
91 | # PROJECT_DEFINES =
92 |
93 | ################################################################################
94 | # PROJECT CFLAGS
95 | # This is a list of fully qualified CFLAGS required when compiling for this
96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS
97 | # defined in your platform specific core configuration files. These flags are
98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below.
99 | #
100 | # (default) PROJECT_CFLAGS = (blank)
101 | #
102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in
103 | # your platform specific configuration file will be applied by default and
104 | # further flags here may not be needed.
105 | #
106 | # Note: Leave a leading space when adding list items with the += operator
107 | ################################################################################
108 | # PROJECT_CFLAGS =
109 |
110 | ################################################################################
111 | # PROJECT OPTIMIZATION CFLAGS
112 | # These are lists of CFLAGS that are target-specific. While any flags could
113 | # be conditionally added, they are usually limited to optimization flags.
114 | # These flags are added BEFORE the PROJECT_CFLAGS.
115 | #
116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets.
117 | #
118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank)
119 | #
120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets.
121 | #
122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank)
123 | #
124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the
125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration
126 | # file will be applied by default and further optimization flags here may not
127 | # be needed.
128 | #
129 | # Note: Leave a leading space when adding list items with the += operator
130 | ################################################################################
131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE =
132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG =
133 |
134 | ################################################################################
135 | # PROJECT COMPILERS
136 | # Custom compilers can be set for CC and CXX
137 | # (default) PROJECT_CXX = (blank)
138 | # (default) PROJECT_CC = (blank)
139 | # Note: Leave a leading space when adding list items with the += operator
140 | ################################################################################
141 | # PROJECT_CXX =
142 | # PROJECT_CC =
143 |
--------------------------------------------------------------------------------
/KinectRecorder/config.make:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # CONFIGURE PROJECT MAKEFILE (optional)
3 | # This file is where we make project specific configurations.
4 | ################################################################################
5 |
6 | ################################################################################
7 | # OF ROOT
8 | # The location of your root openFrameworks installation
9 | # (default) OF_ROOT = ../../..
10 | ################################################################################
11 | # OF_ROOT = ../../..
12 |
13 | ################################################################################
14 | # PROJECT ROOT
15 | # The location of the project - a starting place for searching for files
16 | # (default) PROJECT_ROOT = . (this directory)
17 | #
18 | ################################################################################
19 | # PROJECT_ROOT = .
20 |
21 | ################################################################################
22 | # PROJECT SPECIFIC CHECKS
23 | # This is a project defined section to create internal makefile flags to
24 | # conditionally enable or disable the addition of various features within
25 | # this makefile. For instance, if you want to make changes based on whether
26 | # GTK is installed, one might test that here and create a variable to check.
27 | ################################################################################
28 | # None
29 |
30 | ################################################################################
31 | # PROJECT EXTERNAL SOURCE PATHS
32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder.
33 | # Like source folders in the PROJECT_ROOT, these paths are subject to
34 | # exlclusion via the PROJECT_EXLCUSIONS list.
35 | #
36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank)
37 | #
38 | # Note: Leave a leading space when adding list items with the += operator
39 | ################################################################################
40 | # PROJECT_EXTERNAL_SOURCE_PATHS =
41 |
42 | ################################################################################
43 | # PROJECT EXCLUSIONS
44 | # These makefiles assume that all folders in your current project directory
45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations
46 | # to look for source code. The any folders or files that match any of the
47 | # items in the PROJECT_EXCLUSIONS list below will be ignored.
48 | #
49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete
50 | # string unless teh user adds a wildcard (%) operator to match subdirectories.
51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is
52 | # treated literally.
53 | #
54 | # (default) PROJECT_EXCLUSIONS = (blank)
55 | #
56 | # Will automatically exclude the following:
57 | #
58 | # $(PROJECT_ROOT)/bin%
59 | # $(PROJECT_ROOT)/obj%
60 | # $(PROJECT_ROOT)/%.xcodeproj
61 | #
62 | # Note: Leave a leading space when adding list items with the += operator
63 | ################################################################################
64 | # PROJECT_EXCLUSIONS =
65 |
66 | ################################################################################
67 | # PROJECT LINKER FLAGS
68 | # These flags will be sent to the linker when compiling the executable.
69 | #
70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs
71 | #
72 | # Note: Leave a leading space when adding list items with the += operator
73 | ################################################################################
74 |
75 | # Currently, shared libraries that are needed are copied to the
76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to
77 | # add a runtime path to search for those shared libraries, since they aren't
78 | # incorporated directly into the final executable application binary.
79 | # TODO: should this be a default setting?
80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs
81 |
82 | ################################################################################
83 | # PROJECT DEFINES
84 | # Create a space-delimited list of DEFINES. The list will be converted into
85 | # CFLAGS with the "-D" flag later in the makefile.
86 | #
87 | # (default) PROJECT_DEFINES = (blank)
88 | #
89 | # Note: Leave a leading space when adding list items with the += operator
90 | ################################################################################
91 | # PROJECT_DEFINES =
92 |
93 | ################################################################################
94 | # PROJECT CFLAGS
95 | # This is a list of fully qualified CFLAGS required when compiling for this
96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS
97 | # defined in your platform specific core configuration files. These flags are
98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below.
99 | #
100 | # (default) PROJECT_CFLAGS = (blank)
101 | #
102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in
103 | # your platform specific configuration file will be applied by default and
104 | # further flags here may not be needed.
105 | #
106 | # Note: Leave a leading space when adding list items with the += operator
107 | ################################################################################
108 | # PROJECT_CFLAGS =
109 |
110 | ################################################################################
111 | # PROJECT OPTIMIZATION CFLAGS
112 | # These are lists of CFLAGS that are target-specific. While any flags could
113 | # be conditionally added, they are usually limited to optimization flags.
114 | # These flags are added BEFORE the PROJECT_CFLAGS.
115 | #
116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets.
117 | #
118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank)
119 | #
120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets.
121 | #
122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank)
123 | #
124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the
125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration
126 | # file will be applied by default and further optimization flags here may not
127 | # be needed.
128 | #
129 | # Note: Leave a leading space when adding list items with the += operator
130 | ################################################################################
131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE =
132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG =
133 |
134 | ################################################################################
135 | # PROJECT COMPILERS
136 | # Custom compilers can be set for CC and CXX
137 | # (default) PROJECT_CXX = (blank)
138 | # (default) PROJECT_CC = (blank)
139 | # Note: Leave a leading space when adding list items with the += operator
140 | ################################################################################
141 | # PROJECT_CXX =
142 | # PROJECT_CC =
143 |
--------------------------------------------------------------------------------
/HeightmapGenerator/config.make:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # CONFIGURE PROJECT MAKEFILE (optional)
3 | # This file is where we make project specific configurations.
4 | ################################################################################
5 |
6 | ################################################################################
7 | # OF ROOT
8 | # The location of your root openFrameworks installation
9 | # (default) OF_ROOT = ../../..
10 | ################################################################################
11 | # OF_ROOT = ../../..
12 |
13 | ################################################################################
14 | # PROJECT ROOT
15 | # The location of the project - a starting place for searching for files
16 | # (default) PROJECT_ROOT = . (this directory)
17 | #
18 | ################################################################################
19 | # PROJECT_ROOT = .
20 |
21 | ################################################################################
22 | # PROJECT SPECIFIC CHECKS
23 | # This is a project defined section to create internal makefile flags to
24 | # conditionally enable or disable the addition of various features within
25 | # this makefile. For instance, if you want to make changes based on whether
26 | # GTK is installed, one might test that here and create a variable to check.
27 | ################################################################################
28 | # None
29 |
30 | ################################################################################
31 | # PROJECT EXTERNAL SOURCE PATHS
32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder.
33 | # Like source folders in the PROJECT_ROOT, these paths are subject to
34 | # exlclusion via the PROJECT_EXLCUSIONS list.
35 | #
36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank)
37 | #
38 | # Note: Leave a leading space when adding list items with the += operator
39 | ################################################################################
40 | # PROJECT_EXTERNAL_SOURCE_PATHS =
41 |
42 | ################################################################################
43 | # PROJECT EXCLUSIONS
44 | # These makefiles assume that all folders in your current project directory
45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations
46 | # to look for source code. The any folders or files that match any of the
47 | # items in the PROJECT_EXCLUSIONS list below will be ignored.
48 | #
49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete
50 | # string unless teh user adds a wildcard (%) operator to match subdirectories.
51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is
52 | # treated literally.
53 | #
54 | # (default) PROJECT_EXCLUSIONS = (blank)
55 | #
56 | # Will automatically exclude the following:
57 | #
58 | # $(PROJECT_ROOT)/bin%
59 | # $(PROJECT_ROOT)/obj%
60 | # $(PROJECT_ROOT)/%.xcodeproj
61 | #
62 | # Note: Leave a leading space when adding list items with the += operator
63 | ################################################################################
64 | # PROJECT_EXCLUSIONS =
65 |
66 | ################################################################################
67 | # PROJECT LINKER FLAGS
68 | # These flags will be sent to the linker when compiling the executable.
69 | #
70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs
71 | #
72 | # Note: Leave a leading space when adding list items with the += operator
73 | ################################################################################
74 |
75 | # Currently, shared libraries that are needed are copied to the
76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to
77 | # add a runtime path to search for those shared libraries, since they aren't
78 | # incorporated directly into the final executable application binary.
79 | # TODO: should this be a default setting?
80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs
81 |
82 | ################################################################################
83 | # PROJECT DEFINES
84 | # Create a space-delimited list of DEFINES. The list will be converted into
85 | # CFLAGS with the "-D" flag later in the makefile.
86 | #
87 | # (default) PROJECT_DEFINES = (blank)
88 | #
89 | # Note: Leave a leading space when adding list items with the += operator
90 | ################################################################################
91 | # PROJECT_DEFINES =
92 |
93 | ################################################################################
94 | # PROJECT CFLAGS
95 | # This is a list of fully qualified CFLAGS required when compiling for this
96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS
97 | # defined in your platform specific core configuration files. These flags are
98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below.
99 | #
100 | # (default) PROJECT_CFLAGS = (blank)
101 | #
102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in
103 | # your platform specific configuration file will be applied by default and
104 | # further flags here may not be needed.
105 | #
106 | # Note: Leave a leading space when adding list items with the += operator
107 | ################################################################################
108 | # PROJECT_CFLAGS =
109 |
110 | ################################################################################
111 | # PROJECT OPTIMIZATION CFLAGS
112 | # These are lists of CFLAGS that are target-specific. While any flags could
113 | # be conditionally added, they are usually limited to optimization flags.
114 | # These flags are added BEFORE the PROJECT_CFLAGS.
115 | #
116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets.
117 | #
118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank)
119 | #
120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets.
121 | #
122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank)
123 | #
124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the
125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration
126 | # file will be applied by default and further optimization flags here may not
127 | # be needed.
128 | #
129 | # Note: Leave a leading space when adding list items with the += operator
130 | ################################################################################
131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE =
132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG =
133 |
134 | ################################################################################
135 | # PROJECT COMPILERS
136 | # Custom compilers can be set for CC and CXX
137 | # (default) PROJECT_CXX = (blank)
138 | # (default) PROJECT_CC = (blank)
139 | # Note: Leave a leading space when adding list items with the += operator
140 | ################################################################################
141 | # PROJECT_CXX =
142 | # PROJECT_CC =
143 |
--------------------------------------------------------------------------------
/Shooting/src/ofxMultiKinectV2Mod.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // ofxMultiKinectV2Mod
3 | //
4 | // Created by Yuya Hanai on 10/16/14.
5 | //
6 | #include "ofxMultiKinectV2Mod.h"
7 | #include "ofProtonect2.h"
8 |
9 | using namespace libfreenect2;
10 |
11 | class KinectV2DeviceManager
12 | {
13 | public:
14 | static KinectV2DeviceManager& getManager()
15 | {
16 | static KinectV2DeviceManager o;
17 | if (!o.initialized) {
18 | o.init();
19 | }
20 |
21 | return o;
22 | }
23 |
24 | void forceInit() {
25 | init();
26 | }
27 |
28 | int getDeviceCount() const {
29 | return device_count;
30 | }
31 |
32 | const vector& getSerials() const {
33 | return serials;
34 | }
35 |
36 | private:
37 | vector serials;
38 | int device_count = -1;
39 | bool initialized = false;
40 | KinectV2DeviceManager() {}
41 |
42 | void init()
43 | {
44 | libfreenect2::Freenect2 freenect2;
45 | device_count = freenect2.enumerateDevices();
46 | serials.clear();
47 | for (int i = 0; i < device_count; i++){
48 | string serial = freenect2.getDeviceSerialNumber(i);
49 | serials.push_back(serial);
50 | }
51 | std::sort(serials.begin(), serials.end());
52 | for (auto&p : serials) {
53 | ofLogVerbose("KinectV2DeviceManager") << "sorted device id : " << p;
54 | }
55 | initialized = true;
56 | }
57 | };
58 |
59 | //------------------------------------------
60 | ofxMultiKinectV2Mod::ofxMultiKinectV2Mod()
61 | {
62 | protonect2 = new ofProtonect2();
63 |
64 | bEnableFlipBuffer = false;
65 | bEnableJpegDecode = true;
66 | bOpened = false;
67 | bNewBuffer = false;
68 | bNewFrame = false;
69 |
70 | lastFrameNo = -1;
71 | }
72 |
73 | ofxMultiKinectV2Mod::~ofxMultiKinectV2Mod()
74 | {
75 | close();
76 | delete protonect2;
77 | }
78 |
79 | int ofxMultiKinectV2Mod::getDeviceCount()
80 | {
81 | return KinectV2DeviceManager::getManager().getDeviceCount();
82 | }
83 |
84 | void ofxMultiKinectV2Mod::open(bool enableColor, bool enableIr, int deviceIndex, int oclDeviceIndex)
85 | {
86 | close();
87 |
88 | bNewFrame = false;
89 | bNewBuffer = false;
90 | bOpened = false;
91 |
92 | int mode = 0;
93 | mode |= enableColor ? libfreenect2::Frame::Color : 0;
94 | mode |= enableIr ? libfreenect2::Frame::Ir | libfreenect2::Frame::Depth : 0;
95 |
96 | bool ret = protonect2->open(KinectV2DeviceManager::getManager().getSerials()[deviceIndex],
97 | mode, oclDeviceIndex);
98 |
99 | if (!ret) {
100 | return;
101 | }
102 |
103 | lastFrameNo = -1;
104 |
105 |
106 | bOpened = true;
107 | }
108 |
109 | void ofxMultiKinectV2Mod::start()
110 | {
111 | if (!bOpened) {
112 | return;
113 | }
114 | protonect2->start();
115 |
116 | startThread();
117 | }
118 |
119 | void ofxMultiKinectV2Mod::threadedFunction()
120 | {
121 | while(isThreadRunning()){
122 | protonect2->update();
123 | jpegBack = protonect2->getJpegBuffer();
124 |
125 | // float ts = ofGetElapsedTimef();
126 | if (protonect2->getIrBuffer().size() == 512 * 424 * 4) {
127 | irPixBack.setFromPixels(reinterpret_cast(&protonect2->getIrBuffer().front()), 512, 424, 1);
128 | if (bEnableFlipBuffer) {
129 | irPixBack.mirror(false, true);
130 | }
131 | }
132 | if (protonect2->getDepthBuffer().size() == 512 * 424 * 4) {
133 | depthPixBack.setFromPixels(reinterpret_cast(&protonect2->getDepthBuffer().front()), 512, 424, 1);
134 | if (bEnableFlipBuffer) {
135 | depthPixBack.mirror(false, true);
136 | }
137 |
138 | }
139 | if (bEnableJpegDecode && jpegBack.size()) {
140 | ofBuffer tmp;
141 | tmp.set(&jpegBack.front(), jpegBack.size());
142 | #ifdef USE_OFX_TURBO_JPEG
143 | turbo.load(tmp, colorPixBack);
144 | #else
145 | ofLoadImage(colorPixBack, tmp);
146 | #endif
147 | if (bEnableFlipBuffer) {
148 | colorPixBack.mirror(false, true);
149 | }
150 | }
151 | // float t = ofGetElapsedTimef() - ts;
152 | // cerr << 1000.0*t << "ms" << endl;
153 |
154 | lock();
155 | jpegFront.swap(jpegBack);
156 | irPixFront.swap(irPixBack);
157 | depthPixFront.swap(depthPixBack);
158 | if (bEnableJpegDecode && colorPixBack.isAllocated()) {
159 | colorPixFront.swap(colorPixBack);
160 | }
161 | bNewBuffer = true;
162 | unlock();
163 |
164 | ofSleepMillis(2);
165 | }
166 | }
167 |
168 | void ofxMultiKinectV2Mod::update()
169 | {
170 | if( ofGetFrameNum() != lastFrameNo ){
171 | bNewFrame = false;
172 | lastFrameNo = ofGetFrameNum();
173 | }
174 | if( bNewBuffer ){
175 | lock();
176 | bNewBuffer = false;
177 | jpeg = jpegFront;
178 | irPix = irPixFront;
179 | depthPix = depthPixFront;
180 |
181 | if (depthPixDistance.isAllocated()) {
182 | for (int i = 0, len = 512 * 424; i < len; i++) {
183 | depthPixDistance[i] = depthPix[i] * feedbackRate + depthPixDistance[i] * (1 - feedbackRate);
184 | }
185 | } else {
186 | depthPixDistance.allocate(512, 424, 1);
187 | for (int i = 0, len = 512 * 424; i < len; i++) {
188 | depthPixDistance[i] = depthPix[i];
189 | }
190 | }
191 |
192 |
193 | if (bEnableJpegDecode) {
194 | colorPix = colorPixFront;
195 | }
196 | unlock();
197 | bNewFrame = true;
198 | }
199 |
200 | }
201 |
202 | void ofxMultiKinectV2Mod::close()
203 | {
204 | if( bOpened ){
205 | waitForThread(true, 3000);
206 | protonect2->close();
207 | bOpened = false;
208 | }
209 | }
210 |
211 | bool ofxMultiKinectV2Mod::isFrameNew()
212 | {
213 | return bNewFrame;
214 | }
215 |
216 |
217 | ofPixels& ofxMultiKinectV2Mod::getColorPixelsRef() {
218 | return colorPix;
219 | }
220 |
221 | ofFloatPixels& ofxMultiKinectV2Mod::getDepthPixelsRef() {
222 | return depthPix;
223 | }
224 |
225 | ofFloatPixels& ofxMultiKinectV2Mod::getIrPixelsRef() {
226 | return irPix;
227 | }
228 |
229 | const vector& ofxMultiKinectV2Mod::getJpegBuffer() {
230 | return jpeg;
231 | }
232 |
233 | float ofxMultiKinectV2Mod::getDistanceAt(int x, int y) {
234 | if (!depthPix.isAllocated()) {
235 | return 0.0f;
236 | }
237 | return depthPixDistance[x + y * depthPix.getWidth()] * 0.1; // mm to cm
238 | }
239 |
240 | // TODO: use undistorted
241 | ofVec3f ofxMultiKinectV2Mod::getWorldCoordinateAt(int x, int y) {
242 | return getWorldCoordinateAt(x, y, getDistanceAt(x, y));
243 | }
244 | //}
245 |
246 | ofVec3f ofxMultiKinectV2Mod::getWorldCoordinateAt(int x, int y, float z) {
247 | libfreenect2::Freenect2Device::IrCameraParams p;
248 | ofVec3f world;
249 | if (this->getProtonect()) {
250 | p = this->getProtonect()->getIrCameraParams();
251 | world.z = -z;
252 | world.x = (x - p.cx) * z / p.fx;
253 | world.y = -(y - p.cy) * z / p.fy;
254 | }
255 | return world;
256 | }
257 |
258 | ofVec2f ofxMultiKinectV2Mod::getFocus() {
259 | libfreenect2::Freenect2Device::IrCameraParams p;
260 | ofVec2f fov;
261 | if (this->getProtonect()) {
262 | p = this->getProtonect()->getIrCameraParams();
263 | fov.set(p.fx, p.fy);
264 | }
265 | return fov;
266 | }
267 |
268 |
269 |
--------------------------------------------------------------------------------
/HeightmapGenerator/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | //--------------------------------------------------------------
4 | void ofApp::setup(){
5 | ofSetWindowShape(DEPTH_WIDTH * 3 + GUI_WIDTH, 1280);
6 |
7 | loadGui();
8 |
9 | loadTake();
10 | }
11 |
12 | //--------------------------------------------------------------
13 | void ofApp::loadGui() {
14 | gui = new ofxDatGui(ofxDatGuiAnchor::TOP_LEFT);
15 |
16 | gui->addSlider("capture near", 0, 300.0)->bind(hmr.captureNear);
17 | gui->addSlider("capture far", 0, 300.0)->bind(hmr.captureFar);
18 | gui->addSlider("capture width", 4, DEPTH_WIDTH * 3.0f)->bind(hmr.captureSize.x);
19 | gui->addSlider("capture height", 4, DEPTH_HEIGHT * 3.0f)->bind(hmr.captureSize.y);
20 | gui->addSlider("translation x", -0.5, +0.5)->bind(hmr.translation.x);
21 | gui->addSlider("translation y", -0.5, +0.5)->bind(hmr.translation.y);
22 | gui->addSlider("scale", 1, 12.0)->bind(hmr.scale);
23 |
24 | gui->addBreak()->setHeight(20.0f);
25 | gui->addSlider("time", 0, 0)->bind(currentFrame);
26 | gui->addToggle("preview")->bind(hmr.isPreview);
27 |
28 | gui->addBreak()->setHeight(20.0f);
29 | gui->setTheme(new ofxDatGuiThemeMidnight);
30 | gui->setWidth(GUI_WIDTH);
31 | gui->onSliderEvent(this, &ofApp::onSliderEvent);
32 | gui->onToggleEvent(this, &ofApp::onToggleEvent);
33 |
34 | ofxXmlSettings settings;
35 | settings.loadFile(SETTINGS_PATH);
36 |
37 | takeName = settings.getValue("takeName", "");
38 | hmr.captureNear = settings.getValue("capturrNear", 50.0);
39 | hmr.captureFar = settings.getValue("captureFar", 500.0);
40 | hmr.captureSize.x = settings.getValue("captureWidth", 640.0);
41 | hmr.captureSize.y = settings.getValue("captureHeight", 480.0);
42 | hmr.translation.x = settings.getValue("translationX", 0.0);
43 | hmr.translation.y = settings.getValue("translationY", 0.0);
44 | hmr.scale = settings.getValue("scale", 1);
45 | hmr.isPreview = (bool)settings.getValue("isPreview", (int)true);
46 | }
47 |
48 | void ofApp::saveGui() {
49 | ofxXmlSettings settings;
50 |
51 | settings.addValue("takeName", takeName);
52 | settings.addValue("captureNear", hmr.captureNear);
53 | settings.addValue("captureFar", hmr.captureFar);
54 | settings.addValue("captureWidth", hmr.captureSize.x);
55 | settings.addValue("captureHeight", hmr.captureSize.y);
56 | settings.addValue("translationX", hmr.translation.x);
57 | settings.addValue("translationY", hmr.translation.y);
58 | settings.addValue("scale", hmr.scale);
59 | settings.addValue("isPreview", (int)hmr.isPreview);
60 |
61 | settings.saveFile(SETTINGS_PATH);
62 | }
63 |
64 | void ofApp::onSliderEvent(ofxDatGuiSliderEvent e) {
65 | needsUpdate = true;
66 |
67 | string label = e.target->getLabel();
68 |
69 | if (label == "TIME") {
70 | loadFrame();
71 | }
72 | }
73 |
74 | void ofApp::onToggleEvent(ofxDatGuiToggleEvent e) {
75 | needsUpdate = true;
76 | }
77 |
78 | //--------------------------------------------------------------
79 | void ofApp::exit() {
80 | saveGui();
81 | }
82 |
83 | //--------------------------------------------------------------
84 | void ofApp::update(){
85 |
86 | if (frameList.size() > 0 && needsUpdate) {
87 | needsUpdate = false;
88 | hmr.render();
89 | }
90 | }
91 |
92 | //--------------------------------------------------------------
93 | void ofApp::draw(){
94 |
95 | ofBackground(0);
96 |
97 | ofPushMatrix();
98 | ofTranslate(GUI_WIDTH, 0);
99 | {
100 | // image
101 | ofSetColor(255);
102 | if (hmr.getTexture().isAllocated()) {
103 | hmr.getTexture().draw(0, 50, DEPTH_WIDTH / 2, DEPTH_HEIGHT / 2);
104 | }
105 |
106 | hmr.getTexture().draw(DEPTH_WIDTH / 2, 50);
107 |
108 | // frame
109 | ofNoFill();
110 | ofSetColor(255);
111 | ofSetLineWidth(LINE_WIDTH);
112 | ofRectangle(50 + LINE_WIDTH / 2, 0, DEPTH_WIDTH / 2 - LINE_WIDTH, DEPTH_HEIGHT / 2 - LINE_WIDTH);
113 | ofFill();
114 |
115 | ofSetColor(255);
116 | ofDrawBitmapString("Take Name:" + takeName, 10, 15);
117 |
118 | ss.str("");
119 | ss << "Current Frame: " << (ofToString(currentFrame) + "/" + ofToString(totalFrame));
120 | ss << " near=" << ofToString(hmr.near, 4);
121 | ss << " far=" << ofToString(hmr.far, 4);
122 | ss << " fx=" << ofToString(hmr.focus.x);
123 | ss << " outputWidth=" << ofToString(hmr.getWidth());
124 | ss << " outputHeight=" << ofToString(hmr.getHeight());
125 |
126 | ofDrawBitmapString(ss.str(), 10, 35);
127 | }
128 | ofPopMatrix();
129 | }
130 |
131 | //--------------------------------------------------------------
132 | void ofApp::loadTake() {
133 | ofDirectory dir(ofToDataPath(SAVED_DIR + "/" + takeName + "/" + INPAINTED_NAME));
134 | dir.allowExt("exr");
135 | frameList = dir.getFiles();
136 |
137 | ofxXmlSettings params;
138 | params.loadFile(ofToDataPath(SAVED_DIR + "/" + takeName + "/params.xml"));
139 | hmr.focus.set(params.getValue("fx", 365.0),
140 | params.getValue("fy", 365.0));
141 | hmr.near = params.getValue("near", 0);
142 | hmr.far = params.getValue("far", 0);
143 |
144 | totalFrame = frameList.size();
145 | currentFrame = 0;
146 |
147 | gui->getSlider("time")->setMax(totalFrame - 1);
148 | loadFrame();
149 | ofLogNotice() << "Take Name: " << dir.getAbsolutePath() << " Frame Count: " << totalFrame;
150 | }
151 |
152 | void ofApp::loadTakeWithDialog() {
153 | ofFileDialogResult result = ofSystemLoadDialog("load take", true, ofToDataPath(SAVED_DIR));
154 | takeName = result.getName();
155 |
156 | loadTake();
157 | }
158 |
159 | //--------------------------------------------------------------
160 | void ofApp::loadFrame() {
161 | string path = frameList[currentFrame].getAbsolutePath();
162 | hmr.loadTexture(path);
163 | needsUpdate = true;
164 | ofLogNotice() << "Loading: " << path;
165 | }
166 |
167 | //--------------------------------------------------------------
168 | void ofApp::exportTake() {
169 | exporter.start(hmr, takeName);
170 | }
171 |
172 | //--------------------------------------------------------------
173 | void ofApp::keyPressed(int key){
174 |
175 | switch (key) {
176 | case 'o':
177 | loadTakeWithDialog();
178 | break;
179 |
180 | case 's':
181 | exportTake();
182 | break;
183 |
184 | case OF_KEY_LEFT:
185 | if (--currentFrame < 0) currentFrame = 0;
186 | loadFrame();
187 | needsUpdate = true;
188 | break;
189 | case OF_KEY_RIGHT:
190 | if (++currentFrame >= totalFrame) currentFrame = totalFrame - 1;
191 | loadFrame();
192 | needsUpdate = true;
193 | }
194 |
195 | }
196 |
197 | //--------------------------------------------------------------
198 | void ofApp::keyReleased(int key){
199 |
200 | }
201 |
202 | //--------------------------------------------------------------
203 | void ofApp::mouseMoved(int x, int y ){
204 |
205 | }
206 |
207 | //--------------------------------------------------------------
208 | void ofApp::mouseDragged(int x, int y, int button){
209 |
210 | }
211 |
212 | //--------------------------------------------------------------
213 | void ofApp::mousePressed(int x, int y, int button){
214 |
215 | }
216 |
217 | //--------------------------------------------------------------
218 | void ofApp::mouseReleased(int x, int y, int button){
219 |
220 | }
221 |
222 | //--------------------------------------------------------------
223 | void ofApp::mouseEntered(int x, int y){
224 |
225 | }
226 |
227 | //--------------------------------------------------------------
228 | void ofApp::mouseExited(int x, int y){
229 |
230 | }
231 |
232 | //--------------------------------------------------------------
233 | void ofApp::windowResized(int w, int h){
234 |
235 | }
236 |
237 | //--------------------------------------------------------------
238 | void ofApp::gotMessage(ofMessage msg){
239 |
240 | }
241 |
242 | //--------------------------------------------------------------
243 | void ofApp::dragEvent(ofDragInfo dragInfo){
244 |
245 | }
246 |
--------------------------------------------------------------------------------
/Calibration/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | //--------------------------------------------------------------
4 | void ofApp::setup(){
5 | ofSetWindowShape(1280, 800);
6 | ofSetVerticalSync(true);
7 | ofSetFrameRate(60);
8 |
9 | depthShader.setupShaderFromSource(GL_FRAGMENT_SHADER, depthFragmentShader);
10 | depthShader.linkProgram();
11 |
12 | kinect.open(true, true, 0); // kinect1.open(true, true, 0, 2); // GeForce on MacBookPro Retina
13 | kinect.start();
14 | kinect.setEnableFlipBuffer(true);
15 | gr.setup(kinect.getProtonect(), 2);
16 |
17 | chessboardSize = 300;
18 | chessboardX = 5;
19 | chessboardY = 4;
20 |
21 | fboChessboard.allocate(PROJECTOR_RESOLUTION_X, PROJECTOR_RESOLUTION_Y, GL_RGBA);
22 | secondWindow.setup("chessboard", -PROJECTOR_RESOLUTION_X, 0, fboChessboard.getWidth(), fboChessboard.getHeight(), true);
23 | secondWindow.show();
24 |
25 | searching = false;
26 | }
27 |
28 | //--------------------------------------------------------------
29 | void ofApp::drawChessboard(int x, int y, int chessboardSize) {
30 | float w = chessboardSize / chessboardX;
31 | float h = chessboardSize / chessboardY;
32 |
33 | currentProjectorPoints.clear();
34 | fboChessboard.begin();
35 | ofBackground(255);
36 | ofSetColor(0);
37 | ofTranslate(x, y);
38 | for (int j=0; j0 && i>0) {
43 | currentProjectorPoints.push_back(ofVec2f(ofMap(x+x0, 0, fboChessboard.getWidth(), 0, 1),
44 | ofMap(y+y0, 0, fboChessboard.getHeight(), 0, 1)));
45 | }
46 | if ((i+j)%2==0) ofDrawRectangle(x0, y0, w, h);
47 | }
48 | }
49 | ofSetColor(255);
50 | fboChessboard.end();
51 | }
52 |
53 | //--------------------------------------------------------------
54 | void ofApp::drawTestingPoint(ofVec2f projectedPoint) {
55 | float ptSize = ofMap(sin(ofGetFrameNum()*0.1), -1, 1, 3, 40);
56 | fboChessboard.begin();
57 | ofBackground(255);
58 | ofSetColor(0, 255, 0);
59 | ofDrawCircle(ofMap(projectedPoint.x, 0, 1, 0, fboChessboard.getWidth()),
60 | ofMap(projectedPoint.y, 0, 1, 0, fboChessboard.getHeight()),
61 | ptSize);
62 | ofSetColor(255);
63 | fboChessboard.end();
64 | }
65 |
66 | //--------------------------------------------------------------
67 | void ofApp::addPointPair() {
68 | int nDepthPoints = 0;
69 | for (int i=0; i 0) nDepthPoints++;
72 | }
73 | if (nDepthPoints == (chessboardX-1)*(chessboardY-1)) {
74 | for (int i=0; iinitScene();
22 | this->loadGui();
23 | }
24 |
25 | //--------------------------------------------------------------
26 | void ofApp::initScene() {
27 |
28 | mesh.setMode(OF_PRIMITIVE_POINTS);
29 |
30 | int x, y;
31 | int w = DEPTH_WIDTH;
32 | int h = DEPTH_HEIGHT;
33 |
34 | for (y = 0; y < h; y++) {
35 | for (x = 0; x < w; x++) {
36 | mesh.addColor(ofColor(255));
37 | mesh.addTexCoord(ofVec2f(x / (float)w, y / (float)h));
38 | mesh.addVertex(ofVec3f(x - w / 2, y - h / 2, 0));
39 | }
40 | }
41 |
42 | // initalize camera
43 | camera.setPosition(80, 80, -120);
44 | camera.lookAt(ofVec3f());
45 | camera.setFov(50);
46 |
47 | orthoCamera.setPosition(0, 0, -120);
48 | orthoCamera.lookAt(ofVec3f());
49 | orthoCamera.enableOrtho();
50 |
51 | // init shader
52 | depthShader.setupShaderFromFile(GL_FRAGMENT_SHADER, "depth.frag");
53 | depthShader.linkProgram();
54 | filledShader.setupShaderFromFile(GL_FRAGMENT_SHADER, "filled.frag");
55 | filledShader.linkProgram();
56 | pointShader.load("point");
57 | }
58 |
59 | //--------------------------------------------------------------
60 | void ofApp::loadGui() {
61 | gui = new ofxDatGui(ofxDatGuiAnchor::TOP_LEFT);
62 | gui->addFRM();
63 | gui->addBreak()->setHeight(10.0f);
64 |
65 | gui->addSlider("near", 0, 800)->bind(near);
66 | gui->addSlider("far", 0, 800)->bind(far);
67 | gui->addSlider("fill radius", 1, 15)->bind(postProcessing.radius);
68 | gui->addToggle("preview height")->bind(isPreviewHeight);
69 | gui->addToggle("preview thumb")->bind(isPreviewThumb);
70 | gui->addToggle("flip horizontal")->bind(isFlipHorizontal);
71 | gui->setTheme(new ofxDatGuiThemeMidnight());
72 |
73 | // load
74 | ofxXmlSettings settings;
75 | settings.loadFile("settings.xml");
76 |
77 | near = settings.getValue("near", 50.0);
78 | far = settings.getValue("far", 500.0);
79 | postProcessing.radius = settings.getValue("fillRadius", 3.0);
80 | isPreviewHeight = (bool)settings.getValue("isPreviewHeight", (bool)false);
81 | isPreviewThumb = (bool)settings.getValue("isPreviewThumb", (bool)false);
82 | isPreviewThumb = (bool)settings.getValue("isFlipHorizontal", (bool)true);
83 | }
84 |
85 | void ofApp::saveGui() {
86 |
87 | ofxXmlSettings settings;
88 | settings.addValue("near", near);
89 | settings.addValue("far", far);
90 | settings.addValue("fillRadius", postProcessing.radius);
91 | settings.addValue("isPreviewHeight", (int)isPreviewHeight);
92 | settings.addValue("isPreviewThumb", (int)isPreviewThumb);
93 | settings.addValue("isFlipHorizontal", (int)isFlipHorizontal);
94 | settings.saveFile("settings.xml");
95 |
96 | }
97 |
98 | //--------------------------------------------------------------
99 | void ofApp::update(){
100 |
101 | kinect.update();
102 | if (kinect.isFrameNew()) {
103 |
104 | focus.set(kinect.getFocus());
105 |
106 |
107 | int w = DEPTH_WIDTH;
108 | int h = DEPTH_HEIGHT;
109 | int x, y, offset;
110 | float value, invalid;
111 |
112 | for (y = 0; y < h; y++) {
113 | for (x = 0; x < w; x++) {
114 |
115 | float dist = kinect.getDistanceAt(x, y);
116 | offset = (y * w + x) * 3;
117 |
118 | if(near < dist && dist < far) {
119 | value = ofMap(dist, far, near, 0.0f, 1.0f, true);
120 | invalid = 0.0f;
121 | } else {
122 | value = 0.0f;
123 | invalid = 1.0f;
124 |
125 |
126 | }
127 | depthPixels[offset ] = value;
128 | depthPixels[offset + 1] = invalid;
129 | depthPixels[offset + 2] = 0.0f;
130 | }
131 | }
132 |
133 | depthPixels.mirror(false, !isFlipHorizontal);
134 | depthImage.setFromPixels(depthPixels);
135 |
136 |
137 | if (isRecording) {
138 | recorder.addFrame(depthPixels);
139 | }
140 | }
141 |
142 |
143 | if (willStopRecording && recorder.q.size() == 0) {
144 | recorder.stopThread();
145 | willStopRecording = false;
146 |
147 | doPostProcessing();
148 | }
149 |
150 | // update guide
151 | // guide.clear();
152 | // guide.addVertex(0, 0, 0);
153 | // guide.addVertex()
154 | }
155 |
156 | //--------------------------------------------------------------
157 | void ofApp::doPostProcessing() {
158 | postProcessing.setup(takeName);
159 | postProcessing.startThread();
160 | }
161 |
162 | //--------------------------------------------------------------
163 | void ofApp::exit() {
164 | saveGui();
165 | recorder.waitForThread();
166 | }
167 |
168 | //--------------------------------------------------------------
169 | void ofApp::draw(){
170 | ofBackground(0);
171 | this->drawScene();
172 | this->drawUi();
173 | }
174 |
175 | //--------------------------------------------------------------
176 | void ofApp::drawScene() {
177 |
178 | ofPushMatrix();
179 | ofEnableDepthTest();
180 | {
181 | ofTranslate(GUI_WIDTH, DEPTH_HEIGHT);
182 |
183 | if (isPreviewHeight) {
184 | orthoCamera.begin();
185 | } else {
186 | camera.begin();
187 | }
188 |
189 | ofDrawAxis(400);
190 | // ofDrawGrid(80, 5);
191 |
192 | ofSetColor(255);
193 |
194 | pointShader.begin();
195 | pointShader.setUniform2f("resolution", DEPTH_WIDTH, DEPTH_HEIGHT);
196 | pointShader.setUniform1f("near", near);
197 | pointShader.setUniform1f("far", far);
198 | pointShader.setUniform2f("focus", focus.x, focus.y);
199 | pointShader.setUniformTexture("depth", depthImage, 0);
200 |
201 | mesh.draw();
202 | pointShader.end();
203 |
204 | guide.draw();
205 |
206 | if (isPreviewHeight) {
207 | orthoCamera.end();
208 | } else {
209 | camera.end();
210 | }
211 | }
212 |
213 | ofDisableDepthTest();
214 | ofPopMatrix();
215 | }
216 |
217 | //--------------------------------------------------------------
218 | void ofApp::drawUi() {
219 |
220 | ofPushMatrix();
221 | ofTranslate(GUI_WIDTH, 0);
222 | {
223 | if (isPreviewThumb) {
224 | ofSetColor(0);
225 | ofDrawRectangle(0, 0, DEPTH_WIDTH * 3, DEPTH_HEIGHT);
226 |
227 | ofSetColor(255);
228 | depthShader.begin();
229 | {
230 | depthImage.draw(0, 0);
231 |
232 | if (testImage.isAllocated()) {
233 | testImage.draw(DEPTH_WIDTH, 0);
234 | }
235 | }
236 | depthShader.end();
237 | filledShader.begin();
238 | {
239 | if (testFilledImage.isAllocated()) {
240 | testFilledImage.draw(DEPTH_WIDTH * 2, 0);
241 | }
242 | }
243 | filledShader.end();
244 |
245 | ofNoFill();
246 | ofSetLineWidth(2);
247 | ofDrawRectangle(LINE_WIDTH / 2, LINE_WIDTH / 2, DEPTH_WIDTH - LINE_WIDTH, DEPTH_HEIGHT - LINE_WIDTH);
248 | ofDrawRectangle(LINE_WIDTH / 2 + DEPTH_WIDTH, LINE_WIDTH / 2, DEPTH_WIDTH - LINE_WIDTH, DEPTH_HEIGHT - LINE_WIDTH);
249 | ofDrawRectangle(LINE_WIDTH / 2 + DEPTH_WIDTH * 2, LINE_WIDTH / 2, DEPTH_WIDTH - LINE_WIDTH, DEPTH_HEIGHT - LINE_WIDTH);
250 | ofFill();
251 | }
252 |
253 | if (isRecording) {
254 | ofSetColor(255, 0, 0);
255 | ofDrawCircle(40, 40, 10);
256 | ss.str("");
257 | ss << "recording: " << takeName << "_" << ofToString(recorder.counter, 6, '0');
258 | ofDrawBitmapString(ss.str(), 50, 40);
259 | } else if (willStopRecording) {
260 | ofSetColor(255, 0, 255);
261 | ofDrawCircle(40, 40, 10);
262 | ofDrawBitmapString("saving...", 50, 40);
263 | } else if (postProcessing.isThreadRunning()) {
264 | ofSetColor(0, 255, 0);
265 | ofDrawBitmapString("processing...", 50, 40);
266 | ofDrawRectangle(0, 0, ofGetWidth() * postProcessing.progress, 10);
267 | }
268 |
269 | }
270 | ofPopMatrix();
271 |
272 | }
273 |
274 | //--------------------------------------------------------------
275 | void ofApp::keyPressed(int key){
276 |
277 | switch (key) {
278 | case 'r':
279 | if (willStopRecording || postProcessing.isThreadRunning()) {
280 | ofLogError() << "Cannot recording while saving previous frames";
281 | break;
282 | }
283 |
284 | isRecording = !isRecording;
285 | if (isRecording) {
286 | takeName = getTakeName();
287 |
288 | recorder.setCounter(0);
289 | recorder.setPrefix(ofToDataPath(SAVED_DIR + "/" + takeName + "/" + RAW_NAME + "/" + takeName + "_" + RAW_NAME + "_"));
290 |
291 | ofLogNotice() << "TakeName:" << takeName;
292 |
293 | recorder.startThread();
294 | } else {
295 | willStopRecording = true;
296 |
297 | // save current settings
298 | ofxXmlSettings params;
299 | params.addValue("near", near);
300 | params.addValue("far", far);
301 | params.addValue("fx", focus.x);
302 | params.addValue("fy", focus.y);
303 | params.saveFile(SAVED_DIR + "/" + takeName + "/params.xml");
304 |
305 | ofLogNotice() << "End Recording frames:" << recorder.counter;
306 | }
307 | break;
308 |
309 | case 't':
310 | // test shooting
311 | testPixels.setFromPixels(depthPixels.getData(), DEPTH_WIDTH, DEPTH_HEIGHT, 3);
312 | depthFiller.radius = postProcessing.radius;
313 | testFilledPixels = depthFiller.inpaint(testPixels);
314 |
315 | testImage.setFromPixels(testPixels);
316 | testFilledImage.setFromPixels(testFilledPixels);
317 | break;
318 |
319 | case 'h':
320 | isPreviewHeight = !isPreviewHeight;
321 | break;
322 |
323 | case 'q':
324 | isPreviewThumb = !isPreviewThumb;
325 | break;
326 | }
327 | }
328 |
329 | //--------------------------------------------------------------
330 | string ofApp::getTakeName() {
331 | return ofToString(ofGetYear(), 4, '0') + "-"
332 | + ofToString(ofGetMonth(), 2, '0') + "-"
333 | + ofToString(ofGetDay(), 2, '0') + "-"
334 | + ofToString(ofGetHours(), 2, '0') + "-"
335 | + ofToString(ofGetMinutes(), 2, '0') + "-"
336 | + ofToString(ofGetSeconds(), 2, '0');
337 | }
338 |
--------------------------------------------------------------------------------
/Shooting/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | #define depth_SCALE 1000
4 |
5 | //--------------------------------------------------------------
6 | void ofApp::setup(){
7 |
8 | ofSetVerticalSync(true);
9 | ofSetFrameRate(30);
10 | ofSetWindowShape(1024, 576);
11 | ofSetWindowTitle("Calibration Control");
12 | ofSetWindowPosition(0, 0);
13 | ofEnableAlphaBlending();
14 | ofSetCircleResolution(12);
15 | ofBackground(0);
16 |
17 | // init kinect
18 | kinect.open(true, true, 0);
19 | kinect.setEnableFlipBuffer(true);
20 | kinect.start();
21 |
22 | kpt.loadCalibration("calibration.xml");
23 |
24 | // load shader
25 | depthShader.setupShaderFromFile(GL_FRAGMENT_SHADER, "depth.frag");
26 | depthShader.linkProgram();
27 |
28 | irShader.setupShaderFromFile(GL_FRAGMENT_SHADER, "ir.frag");
29 | irShader.linkProgram();
30 |
31 | // calibration
32 | projectorWidth = 1280;
33 | projectorHeight = 720;
34 |
35 | // setup the second window
36 | secondWindow.setup("Projector", -projectorWidth, 0, projectorWidth, projectorHeight, true);
37 | secondWindow.show();
38 |
39 |
40 | this->loadGui();
41 | this->initScene();
42 | this->initShooting();
43 | }
44 |
45 | //--------------------------------------------------------------
46 | void ofApp::initShooting() {
47 | // init shooting
48 |
49 | hud.allocate(140, 120, GL_RGBA);
50 |
51 | dmx.connect("/dev/tty.usbserial-EN159284");
52 | if (isPreviewLight) {
53 | enableLight();
54 | } else {
55 | disableLight();
56 | }
57 |
58 | dfReceiver.setup(1234);
59 |
60 | heightmapLoader.setup("/Users/mugi/Works/2016/26_techne/render/heightmap/heightmap_overlay_depth####.exr");
61 | heightmapPixels.allocate(HEIGHTMAP_WIDTH, HEIGHTMAP_WIDTH, 1);
62 | heightmapU8Pixels.allocate(HEIGHTMAP_WIDTH, HEIGHTMAP_WIDTH, 1);
63 | heightmapCvImage.allocate(HEIGHTMAP_WIDTH, HEIGHTMAP_WIDTH);
64 |
65 | overlayLoader.setup("/Users/mugi/Works/2016/26_techne/render/heightmap/heightmap_overlay####.exr");
66 | overlayPixels.allocate(HEIGHTMAP_WIDTH, HEIGHTMAP_WIDTH, 1);
67 |
68 | loadHeightmap();
69 |
70 | contour.setStrokeColor(255);
71 | contour.setStrokeWidth(1);
72 | contour.setFilled(false);
73 |
74 |
75 | int x, y;
76 | int w = DEPTH_WIDTH;
77 | int h = DEPTH_HEIGHT;
78 | int step = 2;
79 |
80 | for (y = 0; y < h; y += step) {
81 | for (x = 0; x < w; x += step) {
82 | depthPointCloud.addColor(ofColor(255));
83 | depthPointCloud.addTexCoord(ofVec2f(x / (float)w, y / (float)h));
84 | depthPointCloud.addVertex(ofVec3f(x - w / 2, y - h / 2, 0));
85 | }
86 | }
87 |
88 | ofPlanePrimitive plane;
89 | plane.set(DEPTH_WIDTH - 1, DEPTH_HEIGHT - 1);
90 | plane.setResolution(DEPTH_WIDTH, DEPTH_HEIGHT);
91 |
92 | heightmapMesh = plane.getMesh();
93 |
94 | for (y = 0; y < h; y++) {
95 | for (x = 0; x < w; x++) {
96 | heightmapMesh.addColor(ofColor(255));
97 | heightmapMesh.setTexCoord(y * w + x, ofVec2f(x, y));
98 | }
99 | }
100 |
101 | // heightmapMesh.setPosition(1280/2, 720/2, 0);
102 | heightmapMesh.setMode(OF_PRIMITIVE_POINTS);
103 | ofLogNotice() << "vertices=" << heightmapMesh.getVertices().size();
104 | ofLogNotice() << "indices=" << heightmapMesh.getIndices().size();
105 | ofLogNotice() << "colors=" << heightmapMesh.getColors().size();
106 | ofLogNotice() << "texCoords=" << heightmapMesh.getTexCoords().size();
107 |
108 | heightmapShader.load("heightmap");
109 | }
110 |
111 | //--------------------------------------------------------------
112 | void ofApp::initScene() {
113 |
114 | view3d.allocate(DEPTH_WIDTH, DEPTH_HEIGHT);
115 |
116 | depthPixels.allocate(DEPTH_WIDTH, DEPTH_HEIGHT, OF_IMAGE_COLOR);
117 | depthImage.allocate(DEPTH_WIDTH, DEPTH_HEIGHT, OF_IMAGE_COLOR);
118 |
119 | depthPointCloud.setMode(OF_PRIMITIVE_POINTS);
120 |
121 | int x, y;
122 | int w = DEPTH_WIDTH;
123 | int h = DEPTH_HEIGHT;
124 | int step = 2;
125 |
126 | for (y = 0; y < h; y += step) {
127 | for (x = 0; x < w; x += step) {
128 | depthPointCloud.addColor(ofColor(255));
129 | depthPointCloud.addTexCoord(ofVec2f(x / (float)w, y / (float)h));
130 | depthPointCloud.addVertex(ofVec3f(x - w / 2, y - h / 2, 0));
131 | }
132 | }
133 |
134 | // initalize camera
135 | camera.setPosition(0, -80, 0);
136 | camera.lookAt(ofVec3f(0, 0, -100));
137 | camera.setFov(50);
138 |
139 | // init shader
140 | pointShader.load("point");
141 | }
142 |
143 | //--------------------------------------------------------------
144 | void ofApp::loadGui() {
145 | ofxDatGuiLog::quiet();
146 |
147 | gui = new ofxDatGui(ofxDatGuiAnchor::TOP_LEFT);
148 | gui->addFRM();
149 |
150 | gui->addBreak()->setHeight(30.0f);
151 | ofxDatGuiFolder* scene = gui->addFolder("scene");
152 | scene->addSlider("near", 0, 300)->bind(near);
153 | scene->addSlider("far", 0, 300)->bind(far);
154 | scene->addToggle("show ir")->bind(isDisplayIr);
155 | scene->addToggle("show scene")->bind(showScene);
156 |
157 | gui->addBreak()->setHeight(30.0f);
158 | ofxDatGuiFolder* disc = gui->addFolder("disc");
159 | disc->addButton("calibrate");
160 | disc->addToggle("use calibrated")->bind(useCalibrated);
161 | disc->addSlider("mask margin", 0, 50)->bind(discMaskMargin);
162 | disc->addSlider("mask threshold", 0, 400)->bind(discMaskThreshold);
163 | disc->expand();
164 |
165 | gui->addBreak()->setHeight(30.0f);
166 | ofxDatGuiFolder* shooting = gui->addFolder("shooting");
167 | shooting->addButton("switch shooting mode");
168 | shooting->addSlider("feedback rate", 0, 0.6)->bind(kinect.feedbackRate);
169 | shooting->addSlider("tolerance (cm)", 0, 1)->bind(tolerance);
170 | shooting->addToggle("display heightmap")->bind(isDisplayHeightmap);
171 | shooting->addToggle("preview light")->bind(isPreviewLight);
172 | shooting->addSlider("light front", 0, 1)->bind(lightFront);
173 | shooting->addSlider("light back", 0, 1)->bind(lightBack);
174 | shooting->addSlider("rotate step", 0, 360)->bind(rotateStep);
175 | shooting->addToggle("enable timer");
176 | shooting->addToggle("show overlay")->bind(showOverlay);
177 | shooting->addToggle("show heightmap")->bind(showHeightmap);
178 | shooting->addToggle("force display")->bind(forceDisplay);
179 | shooting->expand();
180 |
181 | gui->onToggleEvent(this, &ofApp::onToggleEvent);
182 | gui->onSliderEvent(this, &ofApp::onSliderEvent);
183 | gui->onButtonEvent(this, &ofApp::onButtonEvent);
184 | gui->on2dPadEvent(this, &ofApp::on2dPadEvent);
185 |
186 | gui->setTheme(new ofxDatGuiThemeMidnight());
187 | gui->setWidth(GUI_WIDTH);
188 |
189 | // load
190 | {
191 | ofxJSONElement settings;
192 | settings.open("settings.json");
193 |
194 | mode = settings.get("mode", MODE_CALIBRATION).asInt();
195 |
196 | // scene
197 | near = settings["scene"].get("near", 50).asFloat();
198 | far = settings["scene"].get("far", 150).asFloat();
199 | isDisplayIr = settings["scene"].get("isDisplayIr", true).asBool();
200 | showScene = settings["scene"].get("showScene", true).asBool();
201 |
202 | // disc
203 | kOrigin.x = settings["disc"]["origin"]["kinect"].get((Json::ArrayIndex)0, DEPTH_WIDTH / 2).asFloat();
204 | kOrigin.y = settings["disc"]["origin"]["kinect"].get((Json::ArrayIndex)1, DEPTH_HEIGHT / 2).asFloat();
205 | wOrigin.x = settings["disc"]["origin"]["world"].get((Json::ArrayIndex)0, 0).asFloat();
206 | wOrigin.y = settings["disc"]["origin"]["world"].get((Json::ArrayIndex)1, 0).asFloat();
207 | wOrigin.z = settings["disc"]["origin"]["world"].get((Json::ArrayIndex)2, 100).asFloat();
208 |
209 | kAxisX.x = settings["disc"]["axisX"]["kinect"].get((Json::ArrayIndex)0, DEPTH_WIDTH).asFloat();
210 | kAxisX.y = settings["disc"]["axisX"]["kinect"].get((Json::ArrayIndex)1, DEPTH_HEIGHT / 2).asFloat();
211 | wAxisX.x = settings["disc"]["axisX"]["world"].get((Json::ArrayIndex)0, 40).asFloat();
212 | wAxisX.y = settings["disc"]["axisX"]["world"].get((Json::ArrayIndex)1, 0).asFloat();
213 | wAxisX.z = settings["disc"]["axisX"]["world"].get((Json::ArrayIndex)2, 100).asFloat();
214 |
215 | kAxisY.x = settings["disc"]["axisY"]["kinect"].get((Json::ArrayIndex)0, DEPTH_WIDTH / 2).asFloat();
216 | kAxisY.y = settings["disc"]["axisY"]["kinect"].get((Json::ArrayIndex)1, 0).asFloat();
217 | wAxisY.x = settings["disc"]["axisY"]["world"].get((Json::ArrayIndex)0, 0).asFloat();
218 | wAxisY.y = settings["disc"]["axisY"]["world"].get((Json::ArrayIndex)1, 40).asFloat();
219 | wAxisY.z = settings["disc"]["axisY"]["world"].get((Json::ArrayIndex)2, 100).asFloat();
220 |
221 | discMaskMargin = settings["disc"].get("maskMargin", 5).asFloat();
222 | discMaskThreshold = settings["disc"].get("maskThreshold", 0.2).asFloat();
223 | makeDiscMask();
224 |
225 | ofxJSON::ofxJSONElement mat = settings["disc"]["mat"];
226 | float m00 = mat[ 0].asFloat();
227 | float m01 = mat[ 1].asFloat();
228 | float m02 = mat[ 2].asFloat();
229 | float m03 = mat[ 3].asFloat();
230 | float m10 = mat[ 4].asFloat();
231 | float m11 = mat[ 5].asFloat();
232 | float m12 = mat[ 6].asFloat();
233 | float m13 = mat[ 7].asFloat();
234 | float m20 = mat[ 8].asFloat();
235 | float m21 = mat[ 9].asFloat();
236 | float m22 = mat[10].asFloat();
237 | float m23 = mat[11].asFloat();
238 | float m30 = mat[12].asFloat();
239 | float m31 = mat[13].asFloat();
240 | float m32 = mat[14].asFloat();
241 | float m33 = mat[15].asFloat();
242 | discMat.set(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33);
243 | discInvMat = discMat.getInverse();
244 |
245 | // shooting
246 | kinect.feedbackRate = settings["shooting"].get("feedbackRate", 0.1).asFloat();
247 |
248 | tolerance = settings["shooting"].get("tolerance", 0.5).asFloat();
249 | isDisplayHeightmap = settings["shooting"].get("isDisplayHeightmap", true).asBool();
250 |
251 | isPreviewLight = settings["shooting"].get("isPreviewLight", false).asBool();
252 | lightFront = settings["shooting"].get("lightFront", 1.0).asFloat();
253 | lightBack = settings["shooting"].get("lightBack", 1.0).asFloat();
254 |
255 | currentFrame = settings["shooting"].get("currentFrame", -1).asInt();
256 | hudOrigin.set(
257 | settings["shooting"]["hudOrigin"].get((Json::ArrayIndex)0, 0).asFloat(),
258 | settings["shooting"]["hudOrigin"].get((Json::ArrayIndex)1, 0).asFloat());
259 |
260 | rotateStep = settings["shooting"].get("rotateStep", 1).asFloat();
261 |
262 | timer.toggle( settings["shooting"].get("enableTimer", false).asBool() );
263 | timer.reset( settings["shooting"].get("elapsedTime", 0).asFloat() );
264 | showOverlay = settings["shooting"].get("showOverlay", true).asBool();
265 | showHeightmap = settings["shooting"].get("showHeightmap", true).asBool();
266 | forceDisplay = settings["shoting"].get("forceDisplay", false).asBool();
267 | }
268 | }
269 |
270 | void ofApp::onToggleEvent(ofxDatGuiToggleEvent e) {
271 |
272 | bool value = e.target->getChecked();
273 |
274 | if (e.target->is("preview light")) {
275 | if (value) {
276 | enableLight();
277 | } else {
278 | disableLight();
279 | }
280 | } else if (e.target->is("enable timer")) {
281 | timer.toggle(value);
282 | }
283 | }
284 |
285 | void ofApp::onSliderEvent(ofxDatGuiSliderEvent e) {
286 | if (e.target->is("light front") || e.target->is("light back")) {
287 | enableLight();
288 | }
289 | }
290 |
291 | void ofApp::onButtonEvent(ofxDatGuiButtonEvent e) {
292 | if (e.target->is("calibrate disc")) {
293 | mode = MODE_CALIBRATION;
294 | } else if (e.target->is("switch shooting mode")) {
295 | mode = MODE_SHOOTING;
296 | }
297 | }
298 |
299 | void ofApp::on2dPadEvent(ofxDatGui2dPadEvent e) {
300 | /*
301 | if (e.target->is("position offset")) {
302 | ofPoint value = e.target->getPoint();
303 | // ofLogNotice() << value.x << " x " << value.y;
304 | kinectProjectorCalibration.setChessboardTranslation(projectorWidth * (value.x - 0.5), projectorHeight * (value.y - 0.5));
305 | }*/
306 | }
307 |
308 | void ofApp::saveGui() {
309 |
310 | ofxJSONElement settings;
311 |
312 | settings["mode"] = mode;
313 |
314 | // scene
315 | settings["scene"]["near"] = near;
316 | settings["scene"]["far"] = far;
317 | settings["scene"]["isDisplayIr"] = isDisplayIr;
318 | settings["scene"]["showScene"] = showScene;
319 |
320 | // disc
321 | settings["disc"]["origin"]["kinect"][0] = kOrigin.x;
322 | settings["disc"]["origin"]["kinect"][1] = kOrigin.y;
323 | settings["disc"]["origin"]["world"][0] = wOrigin.x;
324 | settings["disc"]["origin"]["world"][1] = wOrigin.y;
325 | settings["disc"]["origin"]["world"][2] = wOrigin.z;
326 |
327 | settings["disc"]["axisX"]["kinect"][0] = kAxisX.x;
328 | settings["disc"]["axisX"]["kinect"][1] = kAxisX.y;
329 | settings["disc"]["axisX"]["world"][0] = wAxisX.x;
330 | settings["disc"]["axisX"]["world"][1] = wAxisX.y;
331 | settings["disc"]["axisX"]["world"][2] = wAxisX.z;
332 |
333 | settings["disc"]["axisY"]["kinect"][0] = kAxisY.x;
334 | settings["disc"]["axisY"]["kinect"][1] = kAxisY.y;
335 | settings["disc"]["axisY"]["world"][0] = wAxisY.x;
336 | settings["disc"]["axisY"]["world"][1] = wAxisY.y;
337 | settings["disc"]["axisY"]["world"][2] = wAxisY.z;
338 |
339 | settings["disc"]["maskMargin"] = discMaskMargin;
340 | settings["disc"]["maskThreshold"] = discMaskThreshold;
341 |
342 | settings["disc"]["mat"][ 0] = discMat.getRowAsVec4f(0).x;
343 | settings["disc"]["mat"][ 1] = discMat.getRowAsVec4f(1).x;
344 | settings["disc"]["mat"][ 2] = discMat.getRowAsVec4f(2).x;
345 | settings["disc"]["mat"][ 3] = discMat.getRowAsVec4f(3).x;
346 | settings["disc"]["mat"][ 4] = discMat.getRowAsVec4f(0).y;
347 | settings["disc"]["mat"][ 5] = discMat.getRowAsVec4f(1).y;
348 | settings["disc"]["mat"][ 6] = discMat.getRowAsVec4f(2).y;
349 | settings["disc"]["mat"][ 7] = discMat.getRowAsVec4f(3).y;
350 | settings["disc"]["mat"][ 8] = discMat.getRowAsVec4f(0).z;
351 | settings["disc"]["mat"][ 9] = discMat.getRowAsVec4f(1).z;
352 | settings["disc"]["mat"][10] = discMat.getRowAsVec4f(2).z;
353 | settings["disc"]["mat"][11] = discMat.getRowAsVec4f(3).z;
354 | settings["disc"]["mat"][12] = discMat.getRowAsVec4f(0).w;
355 | settings["disc"]["mat"][13] = discMat.getRowAsVec4f(1).w;
356 | settings["disc"]["mat"][14] = discMat.getRowAsVec4f(2).w;
357 | settings["disc"]["mat"][15] = discMat.getRowAsVec4f(3).w;
358 |
359 | // shooting
360 | settings["shooting"]["feedbackRate"] = kinect.feedbackRate;
361 | settings["shooting"]["isDisplayHeightmap"] = isDisplayHeightmap;
362 |
363 | settings["shooting"]["isPreviewLight"] = isPreviewLight;
364 | settings["shooting"]["lightFront"] = lightFront;
365 | settings["shooting"]["lightBack"] = lightBack;
366 | settings["shooting"]["rotateStep"] = rotateStep;
367 |
368 | settings["shooting"]["currentFrame"] = currentFrame;
369 | settings["shooting"]["hudOrigin"][0] = hudOrigin.x;
370 | settings["shooting"]["hudOrigin"][1] = hudOrigin.y;
371 | settings["shooting"]["enableTimer"] = timer.isEnabled();
372 | settings["shooting"]["showOverlay"] = showOverlay;
373 | settings["shooting"]["showHeightmap"] = showHeightmap;
374 | settings["shooting"]["forceDisplay"] = forceDisplay;
375 |
376 | settings.save("settings.json");
377 |
378 | }
379 |
380 | //--------------------------------------------------------------
381 | void ofApp::sendDmx() {
382 | dmx.setLevel(1, lightFront * 255);
383 | dmx.setLevel(2, lightBack * 255);
384 | dmx.update();
385 | }
386 |
387 | void ofApp::enableLight() {
388 | isPreviewLight = true;
389 | sendDmx();
390 | }
391 |
392 | void ofApp::disableLight() {
393 | isPreviewLight = false;
394 | dmx.setLevel(1, 0);
395 | dmx.setLevel(2, 0);
396 | dmx.update();
397 | }
398 |
399 | void ofApp::doBeforeShoot() {
400 | // enableLight();
401 | }
402 |
403 | void ofApp::doAfterShoot() {
404 | // disableLight();
405 | timer.reset();
406 | }
407 |
408 | //--------------------------------------------------------------
409 | void ofApp::update(){
410 |
411 | kinect.update();
412 |
413 | if (kinect.isFrameNew()) {
414 | ofFloatPixels& irPixels = kinect.getIrPixelsRef();
415 | // irPixels.mirror(false, true);
416 | irTex.loadData(irPixels);
417 |
418 |
419 | this->updateScene();
420 | }
421 |
422 | if (mode == MODE_CALIBRATION) {
423 | if (restCalibrationFrames-- > 0) {
424 |
425 | wOrigin += kinect.getWorldCoordinateAt(kOrigin.x, kOrigin.y);
426 | wAxisX += kinect.getWorldCoordinateAt(kAxisX.x, kAxisX.y);
427 | wAxisY += kinect.getWorldCoordinateAt(kAxisY.x, kAxisY.y);
428 |
429 | // on finished
430 | if (restCalibrationFrames == 0) {
431 | wOrigin /= (float)CALIB_FRAMES;
432 | wAxisX /= (float)CALIB_FRAMES;
433 | wAxisY /= (float)CALIB_FRAMES;
434 |
435 | // make matrix
436 | ofVec3f ex, ey, ez;
437 | ex = (wAxisX - wOrigin).getNormalized();
438 | ey = (wAxisY - wOrigin).getNormalized();
439 | ez = ex.getCrossed(ey).getNormalized();
440 |
441 | discMat.setTranslation(wOrigin);
442 | discMat.set(ex.x, ey.x, ez.x, wOrigin.x,
443 | ex.y, ey.y, ez.y, wOrigin.y,
444 | ex.z, ey.z, ez.z, wOrigin.z,
445 | 0, 0, 0, 1);
446 | discInvMat = discMat.getInverse();
447 |
448 | useCalibrated = true;
449 | restCalibrationFrames = -1;
450 |
451 | makeDiscMask();
452 | }
453 |
454 | }
455 |
456 | } else if (mode == MODE_SHOOTING) {
457 |
458 | while (dfReceiver.hasWaitingMessages()) {
459 | ofxOscMessage m;
460 | dfReceiver.getNextMessage(m);
461 |
462 | string address = m.getAddress();
463 | int frame = m.getArgAsInt(0);
464 |
465 | ofLogNotice() << "path:" << address << " value:" << frame;
466 |
467 | if (address == "/dragonframe/shoot" || address == "/dragonframe/position") {
468 | currentFrame = frame;
469 | loadHeightmap();
470 | }
471 |
472 | if (address == "/dragonframe/shoot") {
473 | doBeforeShoot();
474 | } else if (address == "/dragonframe/cc") {
475 | doAfterShoot();
476 | }
477 | }
478 |
479 | }
480 | }
481 |
482 | void ofApp::updateScene() {
483 |
484 | if (showScene) {
485 | focus.set(kinect.getFocus());
486 |
487 |
488 | int w = DEPTH_WIDTH;
489 | int h = DEPTH_HEIGHT;
490 | int x, y, offset;
491 | float value, invalid, dist;
492 |
493 | for (y = 0; y < h; y++) {
494 | for (x = 0; x < w; x++) {
495 |
496 | dist = kinect.getDistanceAt(x, y);
497 | offset = (y * w + x) * 3;
498 |
499 | if(near < dist && dist < far) {
500 | value = ofMap(dist, far, near, 0.0f, 1.0f, true);
501 | invalid = 0.0f;
502 | } else {
503 | value = 0.0f;
504 | invalid = 1.0f;
505 | }
506 |
507 | depthPixels[offset ] = value;
508 | depthPixels[offset + 1] = invalid;
509 | depthPixels[offset + 2] = 0.0;
510 | }
511 | }
512 |
513 | depthPixels.mirror(false, true);
514 | depthImage.setFromPixels(depthPixels);
515 | }
516 | }
517 |
518 |
519 | //--------------------------------------------------------------
520 | void ofApp::exit() {
521 | saveGui();
522 | }
523 |
524 | //--------------------------------------------------------------
525 | string ofApp::getCurrentFeatureName() {
526 | switch (currentFeature) {
527 | case F_ORIGIN:
528 | return "origin";
529 | case F_AXIS_X:
530 | return "axis x";
531 | case F_AXIS_Y:
532 | return "axis y";
533 | case F_DISPLAY:
534 | return "display";
535 | }
536 | }
537 |
538 | void ofApp::makeDiscMask() {
539 | if (!discMaskPixels.isAllocated()) {
540 | discMaskPixels.allocate(DEPTH_WIDTH, DEPTH_HEIGHT, 1);
541 | }
542 |
543 | float radius = max(kOrigin.distance(kAxisX), kOrigin.distance(kAxisY)) + discMaskMargin;
544 |
545 | ofVec2f p;
546 | for (p.y = 0; p.y < DEPTH_HEIGHT; p.y++) {
547 | for (p.x = 0; p.x < DEPTH_WIDTH; p.x++) {
548 | float dist = kOrigin.distance(p);
549 | discMaskPixels[p.y * DEPTH_WIDTH + p.x] = (dist <= radius) ? 255 : 0;
550 | }
551 | }
552 |
553 | discMaskImage.setFromPixels(discMaskPixels);
554 | }
555 |
556 | //--------------------------------------------------------------
557 | void ofApp::draw(){
558 | ofBackground(20);
559 | ofSetColor(255);
560 | ofPushMatrix();
561 |
562 | ofTranslate(GUI_WIDTH, 0);
563 |
564 | ofPushMatrix();
565 |
566 | this->drawScene();
567 |
568 | if (isDisplayIr) {
569 | // draw ir
570 | if (irTex.isAllocated()) {
571 | irShader.begin();
572 | irTex.draw(0, 0);
573 | irShader.end();
574 |
575 | ofDrawLine(DEPTH_WIDTH / 2, 0, DEPTH_WIDTH / 2, DEPTH_HEIGHT);
576 | ofDrawLine(0, DEPTH_HEIGHT / 2, DEPTH_WIDTH, DEPTH_HEIGHT / 2);
577 | }
578 |
579 | if (discMaskImage.isAllocated()) {
580 | ofSetColor(255, 255, 0, 30);
581 | discMaskImage.draw(0, 0);
582 | ofSetColor(255);
583 | }
584 | ofTranslate(0, DEPTH_HEIGHT);
585 | }
586 |
587 | if (mode == MODE_CALIBRATION) {
588 |
589 | drawCalibration();
590 |
591 | } else if (mode == MODE_SHOOTING) {
592 |
593 | drawShooting();
594 | }
595 |
596 | ofPopMatrix();
597 | }
598 |
599 | void ofApp::drawCalibration() {
600 |
601 | ofVec3f wo = useCalibrated ? wOrigin : kinect.getWorldCoordinateAt(kOrigin.x, kOrigin.y);
602 | ofVec3f wx = useCalibrated ? wAxisX : kinect.getWorldCoordinateAt(kAxisX.x, kAxisX.y);
603 | ofVec3f wy = useCalibrated ? wAxisY : kinect.getWorldCoordinateAt(kAxisY.x, kAxisY.y);
604 |
605 |
606 | ofTranslate(0, 20);
607 | ofDrawBitmapString("MODE: calibrating disc", 10, 0);
608 |
609 | ofTranslate(0, 20);
610 | ofDrawBitmapString("EDITING: " + getCurrentFeatureName(), 10, 0);
611 |
612 | ofTranslate(0, 20);
613 | ofDrawBitmapString("KINECT: origin-" + toString(kOrigin) + " axisX-" + toString(kAxisX) + " axisY-" + toString(kAxisY) + " display-" + toString(hudOrigin), 10, 0);
614 |
615 | if (restCalibrationFrames > 0) {
616 |
617 | ofSetColor(255, 0, 0);
618 | ofTranslate(0, 20);
619 | ofDrawBitmapString("calibrating..." + ofToString(restCalibrationFrames) + "frames", 10, 0);
620 | ofSetColor(255);
621 |
622 | } else {
623 | ofTranslate(0, 20);
624 | ofDrawBitmapString("WORLD: origin-" + toString(wOrigin) + " axisX-" + toString(wAxisX) + " axisY-" + toString(wAxisY), 10, 0);
625 | ofTranslate(0, 20);
626 |
627 | ofDrawBitmapString("Radius X=" + ofToString((wx - wo).length(), 1) +
628 | "Y=" + ofToString((wy - wo).length(), 1), 10, 0);
629 | }
630 |
631 | ofTranslate(0, 20);
632 | ofDrawBitmapString(useCalibrated ? "USE CALIBRATED" : "REALTIME", 10, 0);
633 |
634 | // draw point
635 | ofPopMatrix();
636 |
637 | ofSetColor(255, 255, 255); ofDrawCircle(kOrigin.x, kOrigin.y, 3);
638 | ofSetColor(255, 0, 0); ofDrawCircle(kAxisX.x, kAxisX.y, 3);
639 | ofSetColor(0, 255, 0); ofDrawCircle(kAxisY.x, kAxisY.y, 3);
640 |
641 | secondWindow.begin();
642 | {
643 | ofVec3f ex = wx - wo, ey = wy - wo;
644 |
645 | ofVec2f po = getProj(wo), px = getProj(wx), py = getProj(wy);
646 |
647 | ofBackground(50, 0, 0);
648 | ofSetColor(255, 255, 255);
649 | ofDrawCircle(po, 3);
650 |
651 | ofSetColor(255, 0, 0);
652 | ofDrawCircle(px, 3);
653 | ofDrawLine(po, px);
654 |
655 | ofSetColor(0, 255, 0);
656 | ofDrawCircle(py, 3);
657 | ofDrawLine(po, py);
658 |
659 | // draw circle
660 | ofSetColor(255);
661 | ofNoFill();
662 |
663 | ofVec2f prev = getProj(wx), curt;
664 | for (int i = 1; i <= 60; i++) {
665 | float angle = (float)(i / 60.0) * 2 * PI;
666 | curt.set(getProj(wo + ex * cos(angle) + ey * sin(angle)));
667 | ofDrawLine(prev, curt);
668 | prev.set(curt);
669 | }
670 | ofFill();
671 |
672 | ofDrawLine(projectorWidth / 2, 0, projectorWidth / 2, projectorHeight);
673 | ofDrawLine(0, projectorHeight / 2, projectorWidth, projectorHeight / 2);
674 |
675 | // draw center
676 | ofSetColor(255, 255, 0);
677 | ofDrawCircle(getProj(kinect.getWorldCoordinateAt(DEPTH_WIDTH / 2, DEPTH_HEIGHT / 2)), 3);
678 |
679 | // draw display origin
680 | ofSetColor(0, 255, 255);
681 | ofDrawRectangle(hudOrigin, hud.getWidth(), hud.getHeight());
682 | }
683 | secondWindow.end();
684 | }
685 |
686 | void ofApp::drawShooting() {
687 |
688 | ofSetColor(255);
689 | ofDrawBitmapString("Disc Angle = " + ofToString(heightmapRotation / (PI * 2) * 360, 2), 10, 30);
690 |
691 | timer.isEnabled() ? ofSetColor(255) : ofSetColor(0, 0, 255);
692 | ofDrawBitmapString("Elapsed Time = " + timer.getTimeString(), 10, 50);
693 |
694 | ofTranslate(0, 60);
695 |
696 | if (heightmapLoader.isLoaded()) {
697 | ofSetColor(255);
698 | ofDrawBitmapString("frame=" + ofToString(currentFrame), 10, 20);
699 |
700 | if (isDisplayHeightmap) {
701 | heightmapImage.draw(0, 40, 512, 512);
702 | contourFinder.draw(0, 40, 512, 512);
703 | overlayImage.draw(512, 40, 512, 512);
704 | }
705 | ofSetColor(255);
706 | } else {
707 | ofSetColor(255, 0, 0);
708 | ofDrawBitmapString("frame=" + ofToString(currentFrame), 10, 20);
709 | }
710 |
711 | ofSetColor(255);
712 |
713 | // draw hud
714 | hud.begin();
715 | {
716 | ofClear(0, 0, 0, 0);
717 |
718 | ofSetColor(255);
719 | ofDrawBitmapString("Frame=" + ofToString(currentFrame), 10, 10);
720 |
721 | timer.isEnabled() ? ofSetColor(255) : ofSetColor(0, 0, 255);
722 | ofDrawBitmapString("Elapsed=" + timer.getTimeString(), 10, 30);
723 | ofDrawBitmapString("Disc Angle=" + ofToString(heightmapRotation, 2), 10, 50);
724 | }
725 | hud.end();
726 |
727 | secondWindow.begin();
728 | {
729 | ofBackground(0);
730 | ofPushMatrix();
731 |
732 |
733 | if ((irTex.isAllocated() && !isPreviewLight) || forceDisplay) {
734 |
735 | ofDrawBitmapString("CURRENT FRAME=" + ofToString(currentFrame), hudOrigin);
736 | int step = 1;
737 | int offset = 0;
738 | float u, v;
739 | ofVec2f kCoord, pCoord;
740 | ofVec3f wCoord;
741 |
742 | ofVec3f pos;
743 | float h, th, mix;
744 |
745 | ofFloatPixelsRef irPixels = kinect.getIrPixelsRef();
746 |
747 | for (kCoord.y = 0; kCoord.y < DEPTH_HEIGHT; kCoord.y += step) {
748 | for (kCoord.x = 0; kCoord.x < DEPTH_WIDTH; kCoord.x += step) {
749 | offset = kCoord.y * DEPTH_WIDTH + kCoord.x;
750 |
751 | /*
752 | if (discMaskPixels[offset] == 0 || irPixels[offset] < discMaskThreshold) {
753 | continue;
754 | }
755 | */
756 |
757 | wCoord.set( kinect.getWorldCoordinateAt(kCoord.x, kCoord.y) );
758 | heightmapMesh.setVertex(offset, wCoord);
759 | }
760 | }
761 |
762 | ofSetColor(255);
763 | heightmapShader.begin();
764 |
765 | vector coffs = kpt.getCalibration();
766 |
767 | heightmapShader.setUniformTexture("heightmap", heightmapImage.getTexture(), 1);
768 | heightmapShader.setUniformMatrix4f("discInvMat", discInvMat);
769 | heightmapShader.setUniform2f("projectorSize", 1280, 720);
770 | heightmapShader.setUniform2f("projectorOffset", -96, 0);
771 | heightmapShader.setUniform1f("tolerance", tolerance);
772 |
773 | // heightmapShader.setUniformi
774 | heightmapShader.setUniform1i("showOverlay", showOverlay ? 1 : 0);
775 | heightmapShader.setUniform1i("showHeightmap", showHeightmap ? 1 : 0);
776 | heightmapShader.setUniformTexture("overlay", overlayImage.getTexture(), 2);
777 |
778 | // heightmapShader.setUniformTexture("depth", depthImage, 0);
779 | // heightmapShader.setUniform2f("focus", focus.x, focus.y);
780 | // heightmapShader.setUniform1f("near", near);
781 | // heightmapShader.setUniform1f("far", far);
782 |
783 | heightmapShader.setUniform1f("coff0", coffs[0]);
784 | heightmapShader.setUniform1f("coff1", coffs[1]);
785 | heightmapShader.setUniform1f("coff2", coffs[2]);
786 | heightmapShader.setUniform1f("coff3", coffs[3]);
787 | heightmapShader.setUniform1f("coff4", coffs[4]);
788 | heightmapShader.setUniform1f("coff5", coffs[5]);
789 | heightmapShader.setUniform1f("coff6", coffs[6]);
790 | heightmapShader.setUniform1f("coff7", coffs[7]);
791 | heightmapShader.setUniform1f("coff8", coffs[8]);
792 | heightmapShader.setUniform1f("coff9", coffs[9]);
793 | heightmapShader.setUniform1f("coff10", coffs[10]);
794 |
795 | heightmapMesh.draw();
796 | heightmapShader.end();
797 |
798 | // ofDrawLine(projectorWidth / 2, 0, projectorWidth / 2, projectorHeight);
799 | // ofDrawLine(0, projectorHeight / 2, projectorWidth, projectorHeight / 2);
800 |
801 |
802 |
803 | ofSetColor(255);
804 | for (auto blob : contourFinder.blobs) {
805 | contour.clear();
806 |
807 | bool isFirst = true;
808 |
809 | for (auto p : blob.pts ) {
810 | ofVec3f wc = getWorldFromDisc(ofVec2f(ofMap(p.x, 0, HEIGHTMAP_WIDTH, -30, 30),
811 | ofMap(p.y, 0, HEIGHTMAP_WIDTH, 30, -30)));
812 | ofVec2f pc = getProj(wc);
813 |
814 | if (isFirst) {contour.moveTo(pc); isFirst = false;}
815 | else {contour.lineTo(pc);}
816 |
817 | // ofDrawRectangle(pc.x, pc.y, 10, 10);
818 | }
819 | contour.close();
820 | contour.draw();
821 | }
822 |
823 | // draw angle
824 | {
825 | float rad = heightmapRotation;
826 | ofVec2f rotOrigin = getProjFromDisc(cos(rad) * 10, sin(rad) * 10);
827 | ofVec2f rotOrigin2 = getProjFromDisc(cos(rad) * 30, sin(rad) * 30);
828 | ofSetColor(255);
829 | ofDrawLine(rotOrigin, rotOrigin2);
830 | }
831 |
832 | {
833 | float rad = heightmapRotation + PI;
834 | ofVec2f rotOrigin = getProjFromDisc(cos(rad) * 10, sin(rad) * 10);
835 | ofVec2f rotOrigin2 = getProjFromDisc(cos(rad) * 30, sin(rad) * 30);
836 | ofSetColor(255);
837 | ofDrawLine(rotOrigin, rotOrigin2);
838 | }
839 |
840 | // draw circle
841 | ofSetColor(255);
842 | ofNoFill();
843 |
844 | ofVec2f prev = getProjFromDisc(ofVec2f(30, 0));
845 | ofVec2f curt;
846 | for (int i = 1; i <= 60; i++) {
847 | float angle = (float)(i / 60.0) * 2 * PI;
848 | curt.set(getProjFromDisc(cos(angle) * 30, sin(angle) * 30));
849 | ofDrawLine(prev, curt);
850 | prev.set(curt);
851 | }
852 | ofFill();
853 |
854 |
855 |
856 | // draw hud
857 | ofSetColor(255);
858 | hud.draw(hudOrigin);
859 |
860 |
861 | }
862 |
863 | ofPopMatrix();
864 | }
865 | secondWindow.end();
866 |
867 |
868 |
869 | }
870 |
871 | void ofApp::drawScene() {
872 |
873 | if (showScene) {
874 |
875 | ofBackground(0);
876 | ofSetColor(255);
877 |
878 | ofEnableDepthTest();
879 | camera.begin();
880 | {
881 | ofDrawAxis(200);
882 |
883 | ofSetColor(255);
884 |
885 | pointShader.begin();
886 | pointShader.setUniform2f("resolution", DEPTH_WIDTH, DEPTH_HEIGHT);
887 | pointShader.setUniform1f("near", near);
888 | pointShader.setUniform1f("far", far);
889 | pointShader.setUniform2f("focus", focus.x, focus.y);
890 | pointShader.setUniformTexture("depth", depthImage, 0);
891 | pointShader.setUniformTexture("irTex", irTex, 1);
892 | pointShader.setUniform1f("discMaskThreshold", discMaskThreshold);
893 | depthPointCloud.draw();
894 | pointShader.end();
895 |
896 | ofSetColor(255);
897 | ofDrawCircle(wOrigin, 0.3);
898 |
899 | ofSetColor(255, 0, 0);
900 | ofDrawCircle(wAxisX, 0.3);
901 | ofDrawLine(discMat * ofVec3f(), discMat * ofVec3f(1, 0, 0));
902 |
903 | ofSetColor(0, 255, 0);
904 | ofDrawCircle(wAxisY, 0.3);
905 | ofDrawLine(discMat * ofVec3f(), discMat * ofVec3f(0, 1, 0));
906 |
907 | ofSetColor(0, 0, 255);
908 | ofDrawLine(discMat * ofVec3f(), discMat * ofVec3f(0, 0, 1));
909 | }
910 |
911 | ofSetColor(255);
912 |
913 | camera.end();
914 | ofDisableDepthTest();
915 | }
916 | }
917 |
918 | //--------------------------------------------------------------
919 | ofVec2f ofApp::getProj(ofVec3f wc) {
920 | return kpt.getProjectedPoint(wc * ofVec3f(1, 1, -1)) * ofVec2f(projectorWidth, projectorHeight) - ofVec2f(96, 0);
921 |
922 |
923 | }
924 |
925 | ofVec3f ofApp::getDisc(ofVec3f wc) {
926 | return discInvMat * wc;
927 | }
928 |
929 | ofVec3f ofApp::getWorldFromDisc(ofVec2f dc) {
930 | return discMat * ofVec3f(dc.x, dc.y, 0);
931 | }
932 |
933 | ofVec2f ofApp::getProjFromDisc(ofVec2f dc) {
934 | return getProj(getWorldFromDisc(dc));
935 | }
936 |
937 | void ofApp::loadHeightmap() {
938 | heightmapLoader.load(heightmapPixels, currentFrame);
939 |
940 | if (heightmapLoader.isLoaded()) {
941 | heightmapImage.setFromPixels(heightmapPixels);
942 |
943 | heightmapRotation = heightmapPixels[3 * HEIGHTMAP_WIDTH + 3] * PI * 2;
944 |
945 | int x, y;
946 |
947 | for (int i = 0, len = HEIGHTMAP_WIDTH * HEIGHTMAP_WIDTH; i < len; i++) {
948 | heightmapU8Pixels[i] = (unsigned char)(heightmapPixels[i] * 255 * 80);
949 | }
950 |
951 | heightmapCvImage.setFromPixels(heightmapU8Pixels);
952 | heightmapCvImage.threshold(0);
953 | contourFinder.findContours(heightmapCvImage, 2, HEIGHTMAP_WIDTH * HEIGHTMAP_WIDTH, 20, true);
954 | }
955 |
956 | overlayLoader.load(overlayPixels, currentFrame);
957 | if (overlayLoader.isLoaded()) {
958 | overlayImage.setFromPixels(overlayPixels);
959 | }
960 | }
961 |
962 | //--------------------------------------------------------------
963 | string ofApp::toString(ofVec2f value) {
964 | return "(" + ofToString(value.x, 1) + ", " + ofToString(value.y, 1) + ")";
965 | }
966 |
967 | string ofApp::toString(ofVec3f value) {
968 | return "(" + ofToString(value.x, 1) + ", " + ofToString(value.y, 1) + ", " + ofToString(value.z, 1) + ")";
969 | }
970 |
971 | //--------------------------------------------------------------
972 | void ofApp::moveFeature(float x, float y) {
973 | float amp = 1.0;
974 | if (altPressed) amp = 0.1;
975 | else if (shiftPressed) amp = 10.0;
976 |
977 | if (currentFeature == F_ORIGIN) {
978 | kOrigin += ofVec2f(x, y) * amp;
979 | } else if (currentFeature == F_AXIS_X) {
980 | kAxisX += ofVec2f(x, y) * amp;
981 | } else if (currentFeature == F_AXIS_Y) {
982 | kAxisY += ofVec2f(x, y) * amp;
983 | } else if (currentFeature == F_DISPLAY) {
984 | hudOrigin += ofVec2f(x, y) * amp * 10;
985 | }
986 | }
987 |
988 | //--------------------------------------------------------------
989 | void ofApp::keyPressed(int key){
990 |
991 | if (mode == MODE_CALIBRATION) {
992 |
993 | switch (key) {
994 | case OF_KEY_LEFT: moveFeature(-1, 0); break;
995 | case OF_KEY_UP: moveFeature( 0, -1); break;
996 | case OF_KEY_RIGHT: moveFeature(+1, 0); break;
997 | case OF_KEY_DOWN: moveFeature( 0, +1); break;
998 |
999 | case '1': currentFeature = F_ORIGIN; break;
1000 | case '2': currentFeature = F_AXIS_X; break;
1001 | case '3': currentFeature = F_AXIS_Y; break;
1002 | case '4': currentFeature = F_DISPLAY; break;
1003 |
1004 | case 'c':
1005 | wOrigin.set(0, 0, 0);
1006 | wAxisX.set(0, 0, 0);
1007 | wAxisY.set(0, 0, 0);
1008 | restCalibrationFrames = CALIB_FRAMES;
1009 | break;
1010 |
1011 | case 'd':
1012 | useCalibrated = !useCalibrated;
1013 | break;
1014 | }
1015 |
1016 | } else if (mode == MODE_SHOOTING) {
1017 |
1018 | switch (key) {
1019 |
1020 | case '5': lightBack = ofClamp(lightBack + LIGHT_STEP, 0, 1); sendDmx(); break;
1021 | case '2': lightBack = ofClamp(lightBack - LIGHT_STEP, 0, 1); sendDmx(); break;
1022 | case '4': lightFront = ofClamp(lightFront + LIGHT_STEP, 0, 1); sendDmx(); break;
1023 | case '1': lightFront = ofClamp(lightFront - LIGHT_STEP, 0, 1); sendDmx(); break;
1024 |
1025 | case 'd':
1026 | isDisplayHeightmap = !isDisplayHeightmap;
1027 | break;
1028 |
1029 | case 'o':
1030 | showOverlay = !showOverlay;
1031 | break;
1032 |
1033 | case 'h':
1034 | showHeightmap = !showHeightmap;
1035 | break;
1036 |
1037 | case 'n':
1038 | currentFrame += 1;
1039 | loadHeightmap();
1040 | break;
1041 | case 'p':
1042 | currentFrame -= 1;
1043 | loadHeightmap();
1044 | break;
1045 |
1046 | case 'm':
1047 | forceDisplay = !forceDisplay;
1048 | break;
1049 | }
1050 | }
1051 |
1052 | switch (key) {
1053 | case OF_KEY_LEFT_ALT: altPressed = true; break;
1054 | case OF_KEY_LEFT_SHIFT: shiftPressed = true; break;
1055 |
1056 | case 't':
1057 | if (mode == MODE_SHOOTING) mode = MODE_CALIBRATION;
1058 | else if (mode == MODE_CALIBRATION) mode = MODE_SHOOTING;
1059 | break;
1060 |
1061 | case 'i':
1062 | isDisplayIr = !isDisplayIr;
1063 | break;
1064 |
1065 | case 'l':
1066 | if (isPreviewLight) {
1067 | disableLight();
1068 | } else {
1069 | enableLight();
1070 | }
1071 | break;
1072 |
1073 | case 'f':
1074 | ofToggleFullscreen();
1075 | break;
1076 | }
1077 |
1078 | }
1079 |
1080 | void ofApp::keyReleased(int key) {
1081 | switch (key) {
1082 | case OF_KEY_LEFT_ALT: altPressed = false; break;
1083 | case OF_KEY_LEFT_SHIFT: shiftPressed = false; break;
1084 | }
1085 | }
--------------------------------------------------------------------------------