From f9a763aa183d78bc952ef757de372870873d55e6 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Mon, 22 Jul 2019 15:08:29 +0300 Subject: [PATCH] Hack faster colour distance --- applications/reconstruct/src/depth_camera.cu | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/applications/reconstruct/src/depth_camera.cu b/applications/reconstruct/src/depth_camera.cu index 39a6dcf3b..47ecf8822 100644 --- a/applications/reconstruct/src/depth_camera.cu +++ b/applications/reconstruct/src/depth_camera.cu @@ -38,14 +38,19 @@ extern __device__ float spatialWeighting(float r); * Real-time foreground-background segmentation using codebook model. * Real-Time Imaging. https://doi.org/10.1016/j.rti.2004.12.004 */ - __device__ float colordiffFloat(const uchar4 &pa, const uchar4 &pb) { - float x_2 = pb.x * pb.x + pb.y * pb.y + pb.z * pb.z; - float v_2 = pa.x * pa.x + pa.y * pa.y + pa.z * pa.z; - float xv_2 = pow(pb.x * pa.x + pb.y * pa.y + pb.z * pa.z, 2); - float p_2 = xv_2 / v_2; + __device__ inline float colordiffFloat(const uchar4 &pa, const uchar4 &pb) { + const float x_2 = pb.x * pb.x + pb.y * pb.y + pb.z * pb.z; + const float v_2 = pa.x * pa.x + pa.y * pa.y + pa.z * pa.z; + const float xv_2 = pow(pb.x * pa.x + pb.y * pa.y + pb.z * pa.z, 2); + const float p_2 = xv_2 / v_2; return sqrt(x_2 - p_2); } +__device__ float colordiffFloat2(const uchar4 &pa, const uchar4 &pb) { + float3 delta = make_float3((float)pa.x - (float)pb.x, (float)pa.y - (float)pb.y, (float)pa.z - (float)pb.z); + return length(delta); +} + /* * Colour weighting as suggested in: * C. Kuster et al. Spatio-Temporal Geometry Fusion for Multiple Hybrid Cameras using Moving Least Squares Surfaces. 2014. @@ -98,7 +103,7 @@ __global__ void mls_smooth_kernel(ftl::cuda::TextureObject<float> output, HashDa uchar4 c2 = tex2D<uchar4>(camera.colour, screenPos.x+u, screenPos.y+v); //float4 normal = tex2D<float4>(camera.normal, screenPos.x+u, screenPos.y+v); const float3 worldPos = camera.pose * camera.params.kinectDepthToSkeleton(screenPos.x+u, screenPos.y+v, depth); - const float weight = spatialWeighting(length(mPos - worldPos))*colourWeighting(colordiffFloat(c1,c2)); + const float weight = spatialWeighting(length(mPos - worldPos))*colourWeighting(colordiffFloat2(c1,c2)); wpos += weight*worldPos; //wnorm += weight*make_float3(normal); -- GitLab