From a7d78415196a647b42d9b18358534773b952917f Mon Sep 17 00:00:00 2001 From: pizzoli Date: Sat, 14 Nov 2015 08:49:02 +0100 Subject: [PATCH] replaced patch constants in device memory with definitions --- include/rmd/mvs_device_data.cuh | 14 ++------------ include/rmd/seed_matrix.cuh | 1 - src/epipolar_match.cu | 3 +-- src/seed_check.cu | 4 ++-- src/seed_init.cu | 12 +++++------- test/seed_matrix_test.cpp | 26 ++++++++++++-------------- 6 files changed, 22 insertions(+), 38 deletions(-) diff --git a/include/rmd/mvs_device_data.cuh b/include/rmd/mvs_device_data.cuh index fbc804e..09ad7b8 100644 --- a/include/rmd/mvs_device_data.cuh +++ b/include/rmd/mvs_device_data.cuh @@ -36,20 +36,11 @@ struct SceneData float sigma_sq_max; }; -struct CorrPatch -{ #ifndef RMD_CORR_PATCH_SIDE -#define RMD_CORR_PATCH_SIDE 5 +#define RMD_CORR_PATCH_SIDE 5 #endif #define RMD_CORR_PATCH_OFFSET -RMD_CORR_PATCH_SIDE/2 - CorrPatch() - : side(RMD_CORR_PATCH_SIDE) - , offset(make_int2(RMD_CORR_PATCH_OFFSET, - RMD_CORR_PATCH_OFFSET)) - { } - const int side; - const int2 offset; -}; +#define RMD_CORR_PATCH_AREA RMD_CORR_PATCH_SIDE*RMD_CORR_PATCH_SIDE // DeviceData struct stores pointers to dev memory. // It is allocated and set from host. @@ -104,7 +95,6 @@ struct DeviceData size_t height; SceneData scene; - CorrPatch patch; // Algorithm parameters float eta_inlier; diff --git a/include/rmd/seed_matrix.cuh b/include/rmd/seed_matrix.cuh index 500e12f..ecf724b 100644 --- a/include/rmd/seed_matrix.cuh +++ b/include/rmd/seed_matrix.cuh @@ -77,7 +77,6 @@ public: void downloadConstTemplDenom(float *host_align_row_maj) const; void downloadConvergence(int *host_align_row_maj) const; void downloadEpipolarMatches(float2 *host_align_row_maj) const; - int getPatchSide() const { return dev_data_.patch.side; } #endif private: diff --git a/src/epipolar_match.cu b/src/epipolar_match.cu index 385cef6..a0e3f6b 100644 --- a/src/epipolar_match.cu +++ b/src/epipolar_match.cu @@ -119,10 +119,9 @@ void seedEpipolarMatchKernel( sum_img_templ += img*templ; } } -#define RMD_CORR_PATCH_AREA RMD_CORR_PATCH_SIDE*RMD_CORR_PATCH_SIDE const float ncc_numerator = RMD_CORR_PATCH_AREA*sum_img_templ - sum_img*sum_templ; const float ncc_denominator = (RMD_CORR_PATCH_AREA*sum_img_sq - sum_img*sum_img)*const_templ_denom; -#undef RMD_CORR_PATCH_AREA + const float ncc = ncc_numerator * rsqrtf(ncc_denominator + FLT_MIN); if(ncc > best_ncc) diff --git a/src/seed_check.cu b/src/seed_check.cu index 80f6bde..7123961 100644 --- a/src/seed_check.cu +++ b/src/seed_check.cu @@ -34,8 +34,8 @@ void seedCheckKernel(mvs::DeviceData *dev_ptr) if(x >= dev_ptr->width || y >= dev_ptr->height) return; - if(x > dev_ptr->width-dev_ptr->patch.side-1 || y > dev_ptr->height-dev_ptr->patch.side-1 || - x < dev_ptr->patch.side || y < dev_ptr->patch.side) + if(x > dev_ptr->width-RMD_CORR_PATCH_SIDE-1 || y > dev_ptr->height-RMD_CORR_PATCH_SIDE-1 || + x < RMD_CORR_PATCH_SIDE || y < RMD_CORR_PATCH_SIDE) { dev_ptr->convergence->atXY(x, y) = ConvergenceStates::BORDER; return; diff --git a/src/seed_init.cu b/src/seed_init.cu index 1aebbbf..fc02033 100644 --- a/src/seed_init.cu +++ b/src/seed_init.cu @@ -36,16 +36,14 @@ void seedInitKernel(mvs::DeviceData *dev_ptr) // Compute template statistics for NCC float sum_templ = 0.0f; float sum_templ_sq = 0.0f; - const int &side = dev_ptr->patch.side; - const int2 &offset = dev_ptr->patch.offset; - for(int patch_y=0; patch_ysum_templ->atXY(x, y) = sum_templ; dev_ptr->const_templ_denom->atXY(x, y) = - (float) ( (double) side*side*sum_templ_sq - (double) sum_templ*sum_templ ); + (float) ( (double) RMD_CORR_PATCH_AREA*sum_templ_sq - (double) sum_templ*sum_templ ); // Init measurement parameters dev_ptr->mu->atXY(x, y) = dev_ptr->scene.avg_depth; diff --git a/test/seed_matrix_test.cpp b/test/seed_matrix_test.cpp index 9ca22da..dc89a34 100644 --- a/test/seed_matrix_test.cpp +++ b/test/seed_matrix_test.cpp @@ -121,29 +121,28 @@ TEST(RMDCuTests, seedMatrixInit) cv::Mat ocv_sum_templ(ref_img.rows, ref_img.cols, CV_32FC1); cv::Mat ocv_const_templ_denom(ref_img.rows, ref_img.cols, CV_32FC1); - const int side = seeds.getPatchSide(); - for(size_t y=side; y( y-side/2+patch_y, x-side/2+patch_x ); + const double templ = (double) ref_img_flt.at( y-RMD_CORR_PATCH_SIDE/2+patch_y, x-RMD_CORR_PATCH_SIDE/2+patch_x ); sum_templ += templ; sum_templ_sq += templ*templ; } } ocv_sum_templ.at(y, x) = (float) sum_templ; - ocv_const_templ_denom.at(y, x) = (float) ( ((double)(side*side))*sum_templ_sq - sum_templ*sum_templ ); + ocv_const_templ_denom.at(y, x) = (float) ( ((double)RMD_CORR_PATCH_AREA)*sum_templ_sq - sum_templ*sum_templ ); } } - for(size_t r=side; r(r, c), cu_sum_templ.at(r, c), 0.00001f); ASSERT_NEAR(ocv_const_templ_denom.at(r, c), cu_const_templ_denom.at(r, c), 0.001f); @@ -217,15 +216,14 @@ TEST(RMDCuTests, seedMatrixCheck) cv::Mat cu_convergence(ref_img.rows, ref_img.cols, CV_32SC1); seeds.downloadConvergence(reinterpret_cast(cu_convergence.data)); - const int side = seeds.getPatchSide(); for(size_t r=0; rref_img.rows-side-1 - || rref_img.cols-side-1 - || cref_img.rows-RMD_CORR_PATCH_SIDE-1 + || rref_img.cols-RMD_CORR_PATCH_SIDE-1 + || c(r, c)) << "(r, c) = (" << r << ", " << c <<")"; }