From a25ec14927f1fc134e3313d8d1cc2f0e8c6c9a34 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Thu, 5 Nov 2020 20:18:08 +0200
Subject: [PATCH] Correction to feature bug

---
 .../src/fusion/smoothing/mls_multi_weighted.cu | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/components/operators/src/fusion/smoothing/mls_multi_weighted.cu b/components/operators/src/fusion/smoothing/mls_multi_weighted.cu
index a8bb1a9b7..dd889f532 100644
--- a/components/operators/src/fusion/smoothing/mls_multi_weighted.cu
+++ b/components/operators/src/fusion/smoothing/mls_multi_weighted.cu
@@ -57,13 +57,27 @@ __device__ inline float featureWeight(int f1, int f2) {
 
 	float3 X = camera_origin.screenToCam((int)(x),(int)(y),d0);
 
-	int2 s = camera_in.camToScreen<int2>(o_2_in * X);
+	const float3 camPos = o_2_in * X;
+	const int2 s = camera_in.camToScreen<int2>(camPos);
 
 	// TODO: Could dynamically adjust the smoothing factors depending upon the
 	// number of matches. Meaning, if lots of good local and feature matches
 	// then be less likely to include poorer matches. Conversely, if only poor
 	// non-local or feature distance matches, then increase search range.
 
+	// Could also adapt smoothing parameters using variance or some other local
+	// image measures. Or by just considering distance of the central projected
+	// points as an indication of miss-alignment. Both spatial distance and
+	// feature distance could be used to adjust parameters.
+
+	/*if (s.x >= 0 && s.x < camera_in.width && s.y >= 0 && s.y <= camera_in.height) {
+		// Get depth at exact reprojection point
+		const float d = depth_in[s.x+s.y*dpitch_i];
+		// Get feature at exact reprojection point
+		const uchar2 feature2 = feature_in[s.x+y+(s.y+v)*fpitch_i];
+	}*/
+
+
     // Neighbourhood
     for (int v=-SEARCH_RADIUS; v<=SEARCH_RADIUS; ++v) {
     for (int u=-SEARCH_RADIUS; u<=SEARCH_RADIUS; ++u) {
@@ -74,7 +88,7 @@ __device__ inline float featureWeight(int f1, int f2) {
 		const float3 Xi = in_2_o * camera_in.screenToCam(s.x+u, s.y+v, d);
 		const float3 Ni = make_float3(normals_in[s.x+u+(s.y+v)*npitch_in]);
 
-		const uchar2 feature2 = feature_in[s.x+y+(s.y+v)*fpitch_i];
+		const uchar2 feature2 = feature_in[s.x+u+(s.y+v)*fpitch_i];
 
 		// Gauss approx weighting functions
 		// Rule: spatially close and feature close is strong
-- 
GitLab