diff --git a/src/obs-kinect-freenect/FreenectDevice.cpp b/src/obs-kinect-freenect/FreenectDevice.cpp index cac4d49..9885c2d 100644 --- a/src/obs-kinect-freenect/FreenectDevice.cpp +++ b/src/obs-kinect-freenect/FreenectDevice.cpp @@ -16,6 +16,7 @@ ******************************************************************************/ #include "FreenectDevice.hpp" +#include #include #include #include @@ -24,7 +25,7 @@ KinectFreenectDevice::KinectFreenectDevice(freenect_device* device, const char* serial) : m_device(device) { - SetSupportedSources(Source_Color | Source_Depth); + SetSupportedSources(Source_Color | Source_Depth | Source_ColorMappedDepth); SetUniqueName("Kinect " + std::string(serial)); } @@ -56,7 +57,7 @@ void KinectFreenectDevice::ThreadFunc(std::condition_variable& cv, std::mutex& m currentColorMode = colorMode; - freenect_frame_mode depthMode = freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_MM); + freenect_frame_mode depthMode = freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT_PACKED); if (freenect_set_depth_mode(m_device, depthMode) < 0) throw std::runtime_error("failed to set video mode"); @@ -166,25 +167,43 @@ void KinectFreenectDevice::ThreadFunc(std::condition_variable& cv, std::mutex& m frameData.format = GS_RGBA; } - // Depth + // Depth (and color mapped depth) { std::scoped_lock lock(ud.depthMutex); - const std::uint16_t* frameMem = ud.depthFrontBuffer.data(); + std::uint16_t* frameMem = ud.depthFrontBuffer.data(); if (!frameMem) continue; - DepthFrameData& frameData = framePtr->depthFrame.emplace(); - frameData.width = currentDepthMode.width; - frameData.height = currentDepthMode.height; + // Depth + { + DepthFrameData& frameData = framePtr->depthFrame.emplace(); + frameData.width = currentDepthMode.width; + frameData.height = currentDepthMode.height; - // Convert to R16 - std::size_t memSize = frameData.width * frameData.height * 2; - frameData.memory.resize(memSize); - std::memcpy(frameData.memory.data(), frameMem, memSize); + // Copy it to buffer memory + std::size_t memSize = frameData.width * frameData.height * 2; + frameData.memory.resize(memSize); + freenect_convert_packed_to_16bit(reinterpret_cast(frameMem), reinterpret_cast(frameData.memory.data()), 11, frameData.width*frameData.height); + + frameData.ptr.reset(reinterpret_cast(frameData.memory.data())); + frameData.pitch = static_cast(frameData.width * 2); + } - frameData.ptr.reset(reinterpret_cast(frameData.memory.data())); - frameData.pitch = static_cast(frameData.width * 2); + // Color-mapped depth + { + DepthFrameData& frameData = framePtr->colorMappedDepthFrame.emplace(); + frameData.width = currentDepthMode.width; + frameData.height = currentDepthMode.height; + + // Convert to R16 + std::size_t memSize = frameData.width * frameData.height * 2; + frameData.memory.resize(memSize); + freenect_map_depth_to_rgb(m_device, reinterpret_cast(frameMem), reinterpret_cast(frameData.memory.data())); + + frameData.ptr.reset(reinterpret_cast(frameData.memory.data())); + frameData.pitch = static_cast(frameData.width * 2); + } } UpdateFrame(std::move(framePtr)); diff --git a/xmake-repo/packages/l/libfreenect/xmake.lua b/xmake-repo/packages/l/libfreenect/xmake.lua index 02c9cc1..b54c083 100644 --- a/xmake-repo/packages/l/libfreenect/xmake.lua +++ b/xmake-repo/packages/l/libfreenect/xmake.lua @@ -3,14 +3,8 @@ package("libfreenect") set_description("Drivers and libraries for the Xbox Kinect device on Windows, Linux, and OS X") set_license("GPL-2.0") - set_urls("https://github.com/OpenKinect/libfreenect/archive/refs/tags/$(version).tar.gz", - "https://github.com/OpenKinect/libfreenect.git") - add_versions("v0.6.2", "e135f5e60ae290bf1aa403556211f0a62856a9e34f12f12400ec593620a36bfa") - - add_urls("https://github.com/OpenKinect/libfreenect.git") - - add_versions("v0.2.1", "fd64c5d9b214df6f6a55b4419357e51083f15d93") - add_versions("v0.2.0", "v0.2.0") + set_urls("https://github.com/SirLynix/libfreenect.git") + add_versions("v0.1", "5e2cd8e18877fbe7ef4c863161e90873c06a9180") add_deps("cmake >=3.12.4") if is_plat("windows") then @@ -40,4 +34,5 @@ package("libfreenect") on_test(function (package) assert(package:has_cfuncs("freenect_init", {includes = "libfreenect/libfreenect.h"})) + assert(package:has_cfuncs("freenect_map_depth_to_rgb", {includes = "libfreenect/libfreenect_registration.h"})) end)