From d5a7d1d9baab145d3ca9809e60fba897dada9cb2 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Mon, 12 Aug 2019 08:45:57 +0300
Subject: [PATCH] WIP Dynamic smoothing

---
 applications/reconstruct/src/dibr.cu | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/applications/reconstruct/src/dibr.cu b/applications/reconstruct/src/dibr.cu
index 8d21279f1..93ea413e4 100644
--- a/applications/reconstruct/src/dibr.cu
+++ b/applications/reconstruct/src/dibr.cu
@@ -400,6 +400,8 @@ __device__ inline float warpMin(float e) {
 }
 
 #define ENERGY_THRESHOLD 0.1f
+#define SMOOTHING_MULTIPLIER_A 10.0f
+#define SMOOTHING_MULTIPLIER_B 5.0f
 
 
 /*
@@ -449,7 +451,7 @@ __device__ inline float warpMin(float e) {
 		//     1) Depth from original source
 		//     2) Colour contrast in underlying RGB
 		//     3) Estimated noise levels in depth values
-		if (point.z > clusterBase && point.z < params.camera.m_sensorDepthWorldMax && length(point - camPos) <= 0.04f) {
+		if (point.z > clusterBase && point.z < params.camera.m_sensorDepthWorldMax && length(point - camPos) <= SMOOTHING_MULTIPLIER_A*(point.z / params.camera.fx)) {
 			atomicMin(&minimum[warp], point.z*1000.0f);
 		}
 	}
@@ -471,7 +473,7 @@ __device__ inline float warpMin(float e) {
 		const float3 point = params.camera.kinectDepthToSkeleton(x+u, y+v, float(point_in.tex2D(x+u, y+v)) / 1000.0f);
 
 		// If it is close enough...
-		if (point.z > params.camera.m_sensorDepthWorldMin && point.z < params.camera.m_sensorDepthWorldMax && length(point - minPos) <= 0.04f) {
+		if (point.z > params.camera.m_sensorDepthWorldMin && point.z < params.camera.m_sensorDepthWorldMax && length(point - minPos) <= SMOOTHING_MULTIPLIER_A*(point.z / params.camera.fx)) {
 			// Append to neighbour list
 			//unsigned int idx = atomicInc(&nidx[warp], MAX_NEIGHBORS_2-1);
 			unsigned int idx = atomicAdd(&nidx[warp], 1);
@@ -511,7 +513,7 @@ __device__ inline float warpMin(float e) {
 	// Search for best or threshold energy
 	for (int k=lane; k<MAX_ITERATIONS; k+=WARP_SIZE) {
 		const float3 nearest = params.camera.kinectDepthToSkeleton(x,y,minDepth+float(k)*interval);
-		const float myenergy = ftl::cuda::mls_point_energy<MAX_NEIGHBORS_2>(neighborhood_cache[warp], nearest, min(nidx[warp], MAX_NEIGHBORS_2), SPATIAL_SMOOTHING);
+		const float myenergy = ftl::cuda::mls_point_energy<MAX_NEIGHBORS_2>(neighborhood_cache[warp], nearest, min(nidx[warp], MAX_NEIGHBORS_2), SMOOTHING_MULTIPLIER_B*(nearest.z/params.camera.fx));
 		const float newenergy = warpMax(max(myenergy, maxenergy));
 		bestdepth = (myenergy == newenergy) ? nearest.z : (newenergy > maxenergy) ? 0.0f : bestdepth;
 		maxenergy = newenergy;
@@ -548,7 +550,7 @@ __device__ inline float warpMin(float e) {
 	if (maxenergy >= ENERGY_THRESHOLD) return;
 
 	// Move to next possible surface...
-	clusterBase = minDepth + 0.04f;
+	clusterBase = minDepth + 0.01f;
 
 	};
 }
-- 
GitLab