From f7df4e01b456004bbc2cb684f6e9e8b568c48f9f Mon Sep 17 00:00:00 2001 From: "Lee L. Schloesser" Date: Thu, 15 Aug 2024 15:27:43 -0400 Subject: [PATCH] Adds 32F disparity support to CUDA DBF --- modules/cudastereo/include/opencv2/cudastereo.hpp | 2 +- .../cudastereo/src/cuda/disparity_bilateral_filter.cu | 11 ++++++----- modules/cudastereo/src/disparity_bilateral_filter.cpp | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/cudastereo/include/opencv2/cudastereo.hpp b/modules/cudastereo/include/opencv2/cudastereo.hpp index 27291c2e97d..74827ae8cdd 100644 --- a/modules/cudastereo/include/opencv2/cudastereo.hpp +++ b/modules/cudastereo/include/opencv2/cudastereo.hpp @@ -300,7 +300,7 @@ class CV_EXPORTS_W DisparityBilateralFilter : public cv::Algorithm public: /** @brief Refines a disparity map using joint bilateral filtering. - @param disparity Input disparity map. CV_8UC1 and CV_16SC1 types are supported. + @param disparity Input disparity map. CV_8UC1, CV_16SC1, and CV_32FC1 types are supported. @param image Input image. CV_8UC1 and CV_8UC3 types are supported. @param dst Destination disparity map. It has the same size and type as disparity . @param stream Stream for the asynchronous version. diff --git a/modules/cudastereo/src/cuda/disparity_bilateral_filter.cu b/modules/cudastereo/src/cuda/disparity_bilateral_filter.cu index c69e6559f79..665d669b2ab 100644 --- a/modules/cudastereo/src/cuda/disparity_bilateral_filter.cu +++ b/modules/cudastereo/src/cuda/disparity_bilateral_filter.cu @@ -117,11 +117,11 @@ namespace cv { namespace cuda { namespace device const T disp_reg = disp_y[xi]; - cost[0] += ::min(cmax_disc, ::abs(disp_reg - dp[0])) * weight; - cost[1] += ::min(cmax_disc, ::abs(disp_reg - dp[1])) * weight; - cost[2] += ::min(cmax_disc, ::abs(disp_reg - dp[2])) * weight; - cost[3] += ::min(cmax_disc, ::abs(disp_reg - dp[3])) * weight; - cost[4] += ::min(cmax_disc, ::abs(disp_reg - dp[4])) * weight; + cost[0] += ::min((float)cmax_disc, (float)::abs(disp_reg - dp[0])) * weight; + cost[1] += ::min((float)cmax_disc, (float)::abs(disp_reg - dp[1])) * weight; + cost[2] += ::min((float)cmax_disc, (float)::abs(disp_reg - dp[2])) * weight; + cost[3] += ::min((float)cmax_disc, (float)::abs(disp_reg - dp[3])) * weight; + cost[4] += ::min((float)cmax_disc, (float)::abs(disp_reg - dp[4])) * weight; } } @@ -199,6 +199,7 @@ namespace cv { namespace cuda { namespace device template void disp_bilateral_filter(PtrStepSz disp, PtrStepSzb img, int channels, int iters, const float *table_color, const float *table_space, size_t table_step, int radius, short, short, cudaStream_t stream); template void disp_bilateral_filter(PtrStepSz disp, PtrStepSzb img, int channels, int iters, const float *table_color, const float *table_space, size_t table_step, int radius, short, short, cudaStream_t stream); + template void disp_bilateral_filter(PtrStepSz disp, PtrStepSzb img, int channels, int iters, const float *table_color, const float *table_space, size_t table_step, int radius, short, short, cudaStream_t stream); } // namespace bilateral_filter }}} // namespace cv { namespace cuda { namespace cudev diff --git a/modules/cudastereo/src/disparity_bilateral_filter.cpp b/modules/cudastereo/src/disparity_bilateral_filter.cpp index c59e3b2cb4a..226876c4e84 100644 --- a/modules/cudastereo/src/disparity_bilateral_filter.cpp +++ b/modules/cudastereo/src/disparity_bilateral_filter.cpp @@ -173,14 +173,14 @@ namespace GpuMat& table_color, GpuMat& table_space, const GpuMat& disp, const GpuMat& img, OutputArray dst, Stream& stream); const bilateral_filter_operator_t operators[] = - {disp_bilateral_filter_operator, 0, 0, disp_bilateral_filter_operator, 0, 0, 0, 0}; + {disp_bilateral_filter_operator, 0, 0, disp_bilateral_filter_operator, 0, disp_bilateral_filter_operator, 0, 0}; CV_Assert( 0 < ndisp_ && 0 < radius_ && 0 < iters_ ); GpuMat disp = _disp.getGpuMat(); GpuMat img = _image.getGpuMat(); - CV_Assert( disp.type() == CV_8U || disp.type() == CV_16S ); + CV_Assert( disp.type() == CV_8U || disp.type() == CV_16S || disp.type() == CV_32F ); CV_Assert( img.type() == CV_8UC1 || img.type() == CV_8UC3 ); CV_Assert( disp.size() == img.size() );