From 1950c4dbb993c60f11ddc8adf3c4eeab998fc175 Mon Sep 17 00:00:00 2001 From: cudawarped <12133430+cudawarped@users.noreply.github.com> Date: Sat, 21 Jun 2025 16:32:31 +0300 Subject: [PATCH] Merge pull request #27379 from cudawarped:fix_cuda_convertTo cuda: Fix GpuMat::convertTo issues described in 27373 #27379 Fix https://github.com/opencv/opencv/issues/27373. 1. `GpuMat::convertTo` uses `convertToScale` due to incorrect overload. 2. There are no runtime checks to prevent the use of `CV_16U` data types in Release builds. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake --- modules/core/include/opencv2/core/cuda.hpp | 9 ++++++++- modules/core/src/cuda/gpu_mat.cu | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/core/include/opencv2/core/cuda.hpp b/modules/core/include/opencv2/core/cuda.hpp index 8191c00783..76b8e6bff1 100644 --- a/modules/core/include/opencv2/core/cuda.hpp +++ b/modules/core/include/opencv2/core/cuda.hpp @@ -240,6 +240,10 @@ public: //! converts GpuMat to another datatype (Blocking call) void convertTo(OutputArray dst, int rtype) const; + //! bindings overload which converts GpuMat to another datatype (Blocking call) + CV_WRAP void convertTo(CV_OUT GpuMat& dst, int rtype) const { + convertTo(static_cast(dst), rtype); + } //! converts GpuMat to another datatype (Non-Blocking call) void convertTo(OutputArray dst, int rtype, Stream& stream) const; @@ -250,10 +254,13 @@ public: //! converts GpuMat to another datatype with scaling (Blocking call) void convertTo(OutputArray dst, int rtype, double alpha, double beta = 0.0) const; + //! bindings overload which converts GpuMat to another datatype with scaling(Blocking call) - CV_WRAP void convertTo(CV_OUT GpuMat& dst, int rtype, double alpha = 1.0, double beta = 0.0) const { +#ifdef OPENCV_BINDINGS_PARSER + CV_WRAP void convertTo(CV_OUT GpuMat& dst, int rtype, double alpha=1.0, double beta = 0.0) const { convertTo(static_cast(dst), rtype, alpha, beta); } +#endif //! converts GpuMat to another datatype with scaling (Non-Blocking call) void convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const; diff --git a/modules/core/src/cuda/gpu_mat.cu b/modules/core/src/cuda/gpu_mat.cu index a86888cac3..b6f95445db 100644 --- a/modules/core/src/cuda/gpu_mat.cu +++ b/modules/core/src/cuda/gpu_mat.cu @@ -546,7 +546,7 @@ void cv::cuda::GpuMat::convertTo(OutputArray _dst, int rtype, Stream& stream) co return; } - CV_DbgAssert( sdepth <= CV_64F && ddepth <= CV_64F ); + CV_Assert( sdepth <= CV_64F && ddepth <= CV_64F ); GpuMat src = *this; @@ -578,6 +578,8 @@ void cv::cuda::GpuMat::convertTo(OutputArray _dst, int rtype, double alpha, doub const int sdepth = depth(); const int ddepth = CV_MAT_DEPTH(rtype); + CV_Assert(sdepth <= CV_64F && ddepth <= CV_64F); + GpuMat src = *this; _dst.create(size(), rtype);