From b7fc8918f4029d6b20634d5e5243ee831758230d Mon Sep 17 00:00:00 2001 From: Kazik Pogoda Date: Wed, 24 Aug 2022 20:53:50 +0200 Subject: [PATCH] orx-kinect refactoring + new general orx-depth-camera (#257) --- .gitignore | 4 +- README.md | 1 + build.gradle | 4 +- orx-color/src/commonMain/kotlin/Color.kt | 5 + orx-depth-camera/build.gradle.kts | 26 + .../src/commonMain/kotlin/DepthCamera.kt | 72 +++ orx-fx/README.md | 19 + .../kotlin/colormap/ColormapFilter.kt | 24 + .../kotlin/colormap/GrayscaleColormap.kt | 10 + .../colormap/SpectralZucconiColormap.kt | 13 + .../kotlin/colormap/TurboColormap.kt | 12 + .../glsl/colormap/grayscale-colormap.frag | 31 + .../colormap/spectral-zucconi-colormap.frag | 38 +- .../shaders/glsl/colormap/turbo-colormap.frag | 51 +- .../build.gradle.kts | 5 + .../src/main/kotlin/DepthCameraCalibrator.kt | 267 +++++++++ orx-jvm/orx-kinect-common/build.gradle.kts | 3 + .../src/main/kotlin/Kinect.kt | 183 +++--- .../openrndr/extra/kinect/impl/KinectImpl.kt | 154 ----- .../extra/kinect/depth-to-grayscale.frag | 9 - .../extra/kinect/depth-to-raw-normalized.frag | 19 + .../kinect/impl/kinect-raw-to-depth.frag | 16 - orx-jvm/orx-kinect-v1-demo/build.gradle.kts | 3 + .../src/main/kotlin/DepthToColorMapsDemo.kt | 73 --- ...seDemo.kt => Kinect1Demo01BasicUseCase.kt} | 14 +- .../Kinect1Demo02MotionCaptureUseCase.kt | 111 ++++ .../kotlin/Kinect1Demo03DepthToColorMaps.kt | 93 +++ .../main/kotlin/Kinect1Demo04SwitchOffLed.kt | 31 + .../kotlin/Kinect1Demo05MultipleDevices.kt | 32 + .../Kinect1Demo07NativeFreenectCommands.kt | 44 ++ .../main/kotlin/Kinect1Demo08LogLevelFlood.kt | 30 + .../kotlin/Kinect1Demo09RawDepthProcessing.kt | 49 ++ .../Kinect1Demo10DepthCameraCalibration.kt | 117 ++++ .../src/main/kotlin/MultipleKinectsDemo.kt | 33 - .../main/kotlin/NativeFreenectCommandsDemo.kt | 43 -- .../orx-kinect-v1/src/main/kotlin/Kinect1.kt | 562 ++++++++++++++++++ .../orx-kinect-v1/src/main/kotlin/KinectV1.kt | 289 --------- .../kinect/v1/kinect1-depth-to-meters.frag | 23 + settings.gradle.kts | 4 +- 39 files changed, 1792 insertions(+), 725 deletions(-) create mode 100644 orx-color/src/commonMain/kotlin/Color.kt create mode 100644 orx-depth-camera/build.gradle.kts create mode 100644 orx-depth-camera/src/commonMain/kotlin/DepthCamera.kt create mode 100644 orx-fx/src/commonMain/kotlin/colormap/ColormapFilter.kt create mode 100644 orx-fx/src/commonMain/kotlin/colormap/GrayscaleColormap.kt create mode 100644 orx-fx/src/commonMain/kotlin/colormap/SpectralZucconiColormap.kt create mode 100644 orx-fx/src/commonMain/kotlin/colormap/TurboColormap.kt create mode 100644 orx-fx/src/shaders/glsl/colormap/grayscale-colormap.frag rename orx-jvm/orx-kinect-common/src/main/resources/org/openrndr/extra/kinect/depth-to-colors-zucconi6.frag => orx-fx/src/shaders/glsl/colormap/spectral-zucconi-colormap.frag (71%) rename orx-jvm/orx-kinect-common/src/main/resources/org/openrndr/extra/kinect/depth-to-colors-turbo.frag => orx-fx/src/shaders/glsl/colormap/turbo-colormap.frag (56%) create mode 100644 orx-jvm/orx-depth-camera-calibrator/build.gradle.kts create mode 100644 orx-jvm/orx-depth-camera-calibrator/src/main/kotlin/DepthCameraCalibrator.kt create mode 100644 orx-jvm/orx-kinect-common/build.gradle.kts delete mode 100644 orx-jvm/orx-kinect-common/src/main/kotlin/org/openrndr/extra/kinect/impl/KinectImpl.kt delete mode 100644 orx-jvm/orx-kinect-common/src/main/resources/org/openrndr/extra/kinect/depth-to-grayscale.frag create mode 100644 orx-jvm/orx-kinect-common/src/main/resources/org/openrndr/extra/kinect/depth-to-raw-normalized.frag delete mode 100644 orx-jvm/orx-kinect-common/src/main/resources/org/openrndr/extra/kinect/impl/kinect-raw-to-depth.frag delete mode 100644 orx-jvm/orx-kinect-v1-demo/src/main/kotlin/DepthToColorMapsDemo.kt rename orx-jvm/orx-kinect-v1-demo/src/main/kotlin/{BasicUseCaseDemo.kt => Kinect1Demo01BasicUseCase.kt} (54%) create mode 100644 orx-jvm/orx-kinect-v1-demo/src/main/kotlin/Kinect1Demo02MotionCaptureUseCase.kt create mode 100644 orx-jvm/orx-kinect-v1-demo/src/main/kotlin/Kinect1Demo03DepthToColorMaps.kt create mode 100644 orx-jvm/orx-kinect-v1-demo/src/main/kotlin/Kinect1Demo04SwitchOffLed.kt create mode 100644 orx-jvm/orx-kinect-v1-demo/src/main/kotlin/Kinect1Demo05MultipleDevices.kt create mode 100644 orx-jvm/orx-kinect-v1-demo/src/main/kotlin/Kinect1Demo07NativeFreenectCommands.kt create mode 100644 orx-jvm/orx-kinect-v1-demo/src/main/kotlin/Kinect1Demo08LogLevelFlood.kt create mode 100644 orx-jvm/orx-kinect-v1-demo/src/main/kotlin/Kinect1Demo09RawDepthProcessing.kt create mode 100644 orx-jvm/orx-kinect-v1-demo/src/main/kotlin/Kinect1Demo10DepthCameraCalibration.kt delete mode 100644 orx-jvm/orx-kinect-v1-demo/src/main/kotlin/MultipleKinectsDemo.kt delete mode 100644 orx-jvm/orx-kinect-v1-demo/src/main/kotlin/NativeFreenectCommandsDemo.kt create mode 100644 orx-jvm/orx-kinect-v1/src/main/kotlin/Kinect1.kt delete mode 100644 orx-jvm/orx-kinect-v1/src/main/kotlin/KinectV1.kt create mode 100644 orx-jvm/orx-kinect-v1/src/main/resources/org/openrndr/extra/kinect/v1/kinect1-depth-to-meters.frag diff --git a/.gitignore b/.gitignore index 225d38d4..58b9fbd7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ build/ *.iml/ .idea/ gradle.properties -/ShaderError.txt +/hs_err_pid*.log +/gui-parameters/ +/ShaderError.glsl diff --git a/README.md b/README.md index 515beef7..c011557d 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ A growing library of assorted data structures, algorithms and utilities. | [`orx-temporal-blur`](orx-temporal-blur/) | Post-processing temporal-blur video effect. CPU intense, therefore not intended for use with the `ScreenRecorder` extension or other real-time uses. | | [`orx-time-operators`](orx-time-operators/) | A collection of time-sensitive functions aimed at controlling raw data over-time, such as Envelope and LFO. | | [`orx-timer`](orx-timer/) | Simple timer functionality providing `repeat`, to run code with a given interval and `timeOut`, to run code once after a given delay. | +| [`orx-depth-camera`](orx-depth-camera/) | Common API for various depth cameras like Kinect 1 and 2. | ## JVM only diff --git a/build.gradle b/build.gradle index 212d7cfd..81f5ae83 100644 --- a/build.gradle +++ b/build.gradle @@ -35,8 +35,8 @@ def multiplatformModules = [ "orx-shader-phrases", "orx-shapes", "orx-quadtree", - "orx-hash-grid" - + "orx-hash-grid", + "orx-depth-camera" ] def doNotPublish = ["openrndr-demos"] diff --git a/orx-color/src/commonMain/kotlin/Color.kt b/orx-color/src/commonMain/kotlin/Color.kt new file mode 100644 index 00000000..91eaf885 --- /dev/null +++ b/orx-color/src/commonMain/kotlin/Color.kt @@ -0,0 +1,5 @@ +// keeping this file here will stop IntelliJ from showing warning in nested relative packages +/** + * orx-color + */ +package org.openrndr.extra.color diff --git a/orx-depth-camera/build.gradle.kts b/orx-depth-camera/build.gradle.kts new file mode 100644 index 00000000..206c42b3 --- /dev/null +++ b/orx-depth-camera/build.gradle.kts @@ -0,0 +1,26 @@ +plugins { + kotlin("multiplatform") +} + +kotlin { + jvm { + testRuns["test"].executionTask.configure { + useJUnitPlatform() + } + } + js(IR) { + browser() + nodejs() + } + + sourceSets { + @Suppress("UNUSED_VARIABLE") + val commonMain by getting { + dependencies { + implementation(libs.openrndr.application) + implementation(libs.openrndr.math) + } + } + } + +} diff --git a/orx-depth-camera/src/commonMain/kotlin/DepthCamera.kt b/orx-depth-camera/src/commonMain/kotlin/DepthCamera.kt new file mode 100644 index 00000000..07452b88 --- /dev/null +++ b/orx-depth-camera/src/commonMain/kotlin/DepthCamera.kt @@ -0,0 +1,72 @@ +package org.openrndr.extra.depth.camera + +import org.openrndr.draw.ColorBuffer +import org.openrndr.math.IntVector2 + +/** + * Defines how pixel values encoded in depth [ColorBuffer] will be interpreted. + */ +enum class DepthMeasurement { + + /** + * Raw values, but normalized to the range 0-1. + * Useful for debugging, because full range of captured values can be rendered + * as a texture. Therefore it's a default setting. + */ + RAW_NORMALIZED, + + /** + * Raw values, exactly as they are provided by the device. + * Note: it might imply that [ColorBuffer] of the depth camera frame + * is provided in integer-based format (for example in case of Kinect devices). + */ + RAW, + + /** + * Expressed in meters. + * It is using floating point numbers. + * Note: values above `1.0` will not be visible if displayed as a texture. + */ + METERS, + +} + +/** + * General API of any depth camera. + */ +interface DepthCamera { + + /** + * Current operating resolution. + */ + val resolution: IntVector2 + + /** + * The units/mapping in which depth is expressed on received frames. + */ + var depthMeasurement: DepthMeasurement + + /** + * Flips source depth data image in horizontal axis (mirror). + */ + var flipH: Boolean + + /** + * Flips source depth data image in vertical axis (upside-down). + */ + var flipV: Boolean + + /** + * The most recent frame received from the depth camera. + */ + val currentFrame: ColorBuffer + + /** + * Will execute the supplied block of code with each most recent frame + * from the depth camera as an input. + * + * @param block the code to execute when the new frame is received. + */ + fun onFrameReceived(block: (frame: ColorBuffer) -> Unit) + +} diff --git a/orx-fx/README.md b/orx-fx/README.md index c42da676..487a5da9 100644 --- a/orx-fx/README.md +++ b/orx-fx/README.md @@ -167,6 +167,25 @@ fun main() = application { } ``` +### Colormap + +Colormap filters operate only on the RED color channel. For example +depth maps from +[orx-depth-camera](https://github.com/openrndr/orx/tree/master/orx-depth-camera). + +They allow selection of `min` / `max` value range and applying exponential +shaping `curve` within this range: + +- `GrayscaleColormap` - maps to gray tones +- `SpectralZucconiColormap` - maps to natural light dispersion spectrum as described + by Alan Zucconi in the + [Improving the Rainbow](https://www.alanzucconi.com/2017/07/15/improving-the-rainbow/) + article. +- `TurboColormap` - maps to Turbo Colormap according to + [Turbo, An Improved Rainbow Colormap for Visualization](https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html) + by Google. + +