From 84f33d0578d3a836c8384608363ef5e2c24030fa Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 23 Oct 2014 19:33:19 +0400 Subject: [PATCH] minor fix for StereoCSBP data cost compute kernel and test --- modules/gpu/src/cuda/stereocsbp.cu | 14 ++++++++++---- modules/gpu/test/test_calib3d.cpp | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/gpu/src/cuda/stereocsbp.cu b/modules/gpu/src/cuda/stereocsbp.cu index 7b76f47..412e938 100644 --- a/modules/gpu/src/cuda/stereocsbp.cu +++ b/modules/gpu/src/cuda/stereocsbp.cu @@ -103,16 +103,22 @@ namespace cv { namespace gpu { namespace device { static __device__ __forceinline__ float compute(const uchar* left, const uchar* right) { - return fmin(cdata_weight * ::abs((int)*left - *right), cdata_weight * cmax_data_term); + int l = *(left); + int r = *(right); + + return fmin(cdata_weight * ::abs(l - r), cdata_weight * cmax_data_term); } }; template <> struct DataCostPerPixel<3> { static __device__ __forceinline__ float compute(const uchar* left, const uchar* right) { - float tb = 0.114f * ::abs((int)left[0] - right[0]); - float tg = 0.587f * ::abs((int)left[1] - right[1]); - float tr = 0.299f * ::abs((int)left[2] - right[2]); + uchar3 l = *((const uchar3*)left); + uchar3 r = *((const uchar3*)right); + + float tb = 0.114f * ::abs((int)l.x - r.x); + float tg = 0.587f * ::abs((int)l.y - r.y); + float tr = 0.299f * ::abs((int)l.z - r.z); return fmin(cdata_weight * (tr + tg + tb), cdata_weight * cmax_data_term); } diff --git a/modules/gpu/test/test_calib3d.cpp b/modules/gpu/test/test_calib3d.cpp index 5de3d34..9d59ee7 100644 --- a/modules/gpu/test/test_calib3d.cpp +++ b/modules/gpu/test/test_calib3d.cpp @@ -158,7 +158,7 @@ GPU_TEST_P(StereoConstantSpaceBP, Regression) cv::Mat h_disp(disp); h_disp.convertTo(h_disp, disp_gold.depth()); - EXPECT_MAT_NEAR(disp_gold, h_disp, 1.0); + EXPECT_MAT_SIMILAR(disp_gold, h_disp, 1e-4); } INSTANTIATE_TEST_CASE_P(GPU_Calib3D, StereoConstantSpaceBP, ALL_DEVICES); -- 2.7.4