From 8d43e2b945d051bc1e042922307add79bd637499 Mon Sep 17 00:00:00 2001 From: Andreas Franek Date: Mon, 4 Jul 2016 16:13:31 +0200 Subject: [PATCH] fixed the cuda optical flow error normalization factor texture channels were not considered correctly, nor was the cuda texture normalization --- modules/cudaoptflow/src/cuda/pyrlk.cu | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/cudaoptflow/src/cuda/pyrlk.cu b/modules/cudaoptflow/src/cuda/pyrlk.cu index 5d40a47eae..5c81edface 100644 --- a/modules/cudaoptflow/src/cuda/pyrlk.cu +++ b/modules/cudaoptflow/src/cuda/pyrlk.cu @@ -344,6 +344,18 @@ namespace pyrlk return ret; } + template + struct DenormalizationFactor + { + static const float factor = 1.0; + }; + + template <> + struct DenormalizationFactor + { + static const float factor = 255.0; + }; + template __global__ void sparseKernel(const float2* prevPts, float2* nextPts, uchar* status, float* err, const int level, const int rows, const int cols) { @@ -532,7 +544,7 @@ namespace pyrlk nextPts[blockIdx.x] = nextPt; if (calcErr) - err[blockIdx.x] = static_cast(errval) / (cn * c_winSize_x * c_winSize_y); + err[blockIdx.x] = static_cast(errval) / (::min(cn, 3) * c_winSize_x * c_winSize_y) * DenormalizationFactor::factor; } } @@ -725,7 +737,7 @@ namespace pyrlk nextPts[blockIdx.x] = nextPt; if (calcErr) - err[blockIdx.x] = static_cast(errval) / (3 * c_winSize_x * c_winSize_y); + err[blockIdx.x] = static_cast(errval) / (::min(cn, 3)*c_winSize_x * c_winSize_y); } } // __global__ void sparseKernel_ @@ -1109,4 +1121,4 @@ namespace pyrlk template class pyrLK_caller; } -#endif /* CUDA_DISABLER */ \ No newline at end of file +#endif /* CUDA_DISABLER */