diff --git a/modules/core/src/lut.cpp b/modules/core/src/lut.cpp index a6b64c9b96..008a4e212a 100644 --- a/modules/core/src/lut.cpp +++ b/modules/core/src/lut.cpp @@ -50,11 +50,26 @@ static void LUT8u_16s( const uchar* src, const short* lut, short* dst, int len, LUT8u_( src, lut, dst, len, cn, lutcn ); } +static void LUT8u_32u( const uchar* src, const uint* lut, uint* dst, int len, int cn, int lutcn ) +{ + LUT8u_( src, lut, dst, len, cn, lutcn ); +} + static void LUT8u_32s( const uchar* src, const int* lut, int* dst, int len, int cn, int lutcn ) { LUT8u_( src, lut, dst, len, cn, lutcn ); } +static void LUT8u_64u( const uchar* src, const uint64_t* lut, uint64_t* dst, int len, int cn, int lutcn ) +{ + LUT8u_( src, lut, dst, len, cn, lutcn ); +} + +static void LUT8u_64s( const uchar* src, const int64_t* lut, int64_t* dst, int len, int cn, int lutcn ) +{ + LUT8u_( src, lut, dst, len, cn, lutcn ); +} + static void LUT8u_16f( const uchar* src, const hfloat* lut, hfloat* dst, int len, int cn, int lutcn ) { LUT8u_( src, lut, dst, len, cn, lutcn ); @@ -75,7 +90,10 @@ typedef void (*LUTFunc)( const uchar* src, const uchar* lut, uchar* dst, int len static LUTFunc lutTab[CV_DEPTH_MAX] = { (LUTFunc)LUT8u_8u, (LUTFunc)LUT8u_8s, (LUTFunc)LUT8u_16u, (LUTFunc)LUT8u_16s, - (LUTFunc)LUT8u_32s, (LUTFunc)LUT8u_32f, (LUTFunc)LUT8u_64f, (LUTFunc)LUT8u_16f + (LUTFunc)LUT8u_32s, (LUTFunc)LUT8u_32f, (LUTFunc)LUT8u_64f, (LUTFunc)LUT8u_16f, + // new data types in 5.x + /*bf16*/ (LUTFunc)LUT8u_16f, /*bool*/(LUTFunc)LUT8u_8u, (LUTFunc)LUT8u_64u, + (LUTFunc)LUT8u_64s, (LUTFunc)LUT8u_32u }; #ifdef HAVE_OPENCL diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index 8cb85169af..a1295b743d 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -3484,23 +3484,6 @@ INSTANTIATE_TEST_CASE_P( testing::Values(CV_16BF, CV_Bool, CV_64U, CV_64S, CV_32U) ); -/////////////////////////////////////////////////////////////////////////////////// -typedef testing::TestWithParam LutNotSupportedMatDepth; - -TEST_P(LutNotSupportedMatDepth, lut) -{ - cv::Mat src = cv::Mat::zeros(16,16, CV_8UC1); - cv::Mat lut = cv::Mat(1, 256, CV_MAKETYPE(GetParam(), 1)); - cv::Mat dst; - EXPECT_THROW( cv::LUT(src,lut,dst), cv::Exception); -} - -INSTANTIATE_TEST_CASE_P( - Lut, - LutNotSupportedMatDepth, - testing::Values(CV_16BF, CV_Bool, CV_64U, CV_64S, CV_32U) -); - /////////////////////////////////////////////////////////////////////////////////// typedef testing::TestWithParam MinMaxSupportedMatDepth; @@ -3526,9 +3509,7 @@ INSTANTIATE_TEST_CASE_P( testing::Values(perf::MatDepth(CV_16F), CV_16BF, CV_Bool, CV_64U, CV_64S, CV_32U) ); -CV_ENUM(LutMatType, CV_8U, CV_16U, CV_16F, CV_32S, CV_32F, CV_64F) - -struct Core_LUT: public testing::TestWithParam +struct Core_LUT: public testing::TestWithParam { template cv::Mat referenceWithType(cv::Mat input, cv::Mat table) @@ -3559,21 +3540,25 @@ struct Core_LUT: public testing::TestWithParam template cv::Mat reference(cv::Mat input, cv::Mat table) { - if (table.type() == CV_8U) + if ((table.type() == CV_8U) || (table.type() == CV_8S) || (table.type() == CV_Bool)) { return referenceWithType(input, table); } - else if (table.type() == CV_16U) + else if ((table.type() == CV_16U) || (table.type() == CV_16S)) { return referenceWithType(input, table); } - else if (table.type() == CV_16F) + else if ((table.type() == CV_16F) || (table.type() == CV_16BF)) { return referenceWithType(input, table); } - else if (table.type() == CV_32S) + else if ((table.type() == CV_32S) || (table.type() == CV_32U)) { - return referenceWithType(input, table); + return referenceWithType(input, table); + } + else if ((table.type() == CV_64S) || (table.type() == CV_64U)) + { + return referenceWithType(input, table); } else if (table.type() == CV_32F) { @@ -3602,6 +3587,13 @@ TEST_P(Core_LUT, accuracy) cv::Mat gt = reference(input, table); + // Force convert to 8U as CV_Bool is not supported in cv::norm for now + // TODO: Remove conversion after cv::norm fix + if (type == CV_Bool) + { + output.convertTo(output, CV_8U); + gt.convertTo(gt, CV_8U); + } ASSERT_EQ(0, cv::norm(output, gt, cv::NORM_INF)); } @@ -3619,10 +3611,18 @@ TEST_P(Core_LUT, accuracy_multi) cv::Mat gt = reference<3>(input, table); + // Force convert to 8U as CV_Bool is not supported in cv::norm for now + // TODO: Remove conversion after cv::norm fix + if (type == CV_Bool) + { + output.convertTo(output, CV_8U); + gt.convertTo(gt, CV_8U); + } + ASSERT_EQ(0, cv::norm(output, gt, cv::NORM_INF)); } -INSTANTIATE_TEST_CASE_P(/**/, Core_LUT, LutMatType::all()); +INSTANTIATE_TEST_CASE_P(/**/, Core_LUT, perf::MatDepth::all()); }} // namespace