diff --git a/modules/core/src/sum.dispatch.cpp b/modules/core/src/sum.dispatch.cpp index d7a93cec97..9c5d94632e 100644 --- a/modules/core/src/sum.dispatch.cpp +++ b/modules/core/src/sum.dispatch.cpp @@ -139,7 +139,8 @@ static Scalar sum_(const Mat& src) if (func == nullptr) { if (depth == CV_Bool && cn == 1) return Scalar((double)countNonZero(src)); - CV_Error(Error::StsNotImplemented, ""); + CV_Error_(Error::StsNotImplemented, ("sum: %s input is not supported, convert the input to another type (e.g. CV_32F) first", + typeToString(src.type()).c_str())); } const Mat* arrays[] = {&src, 0}; diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index 4f8098e35e..5804e08ec4 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -4710,6 +4710,27 @@ TEST(Core_Arithm, inRange_unsupported_depth_30153) } } +TEST(Core_Arithm, sum_unsupported_depth) +{ + for (int depth : {CV_Bool, CV_8F_E4M3FN, CV_8F_E4M3FNUZ}) + { + for (int cn : {1, 3}) + { + if (depth == CV_Bool && cn == 1) + continue; // single-channel CV_Bool is supported by cv::sum + cv::Mat src(4, 4, CV_MAKETYPE(depth, cn), cv::Scalar::all(0)); + try + { + cv::sum(src); + ADD_FAILURE() << "cv::sum did not throw for " << cv::typeToString(src.type()); + } + catch (const cv::Exception& e) + { + EXPECT_NE(std::string::npos, e.err.find(cv::typeToString(src.type()))) << e.err; + } + } + } +} TEST(Core_Arithm, min_empty) {