mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 21:22:43 -06:00
Merge pull request #30976 from ternaus/codex/pow-zero-any-channel
core: fix pow with zero exponent on high-channel images 🤖🤖🤖 The zero-exponent branch of cv::pow fills the destination with a four-component Scalar. CPU outputs with more than four channels reject it. Use a single numeric input that broadcasts to every channel for this case. CUDA output continues through the four-component path required by its OutputArray implementation. The 5.1 wheel reproduces the assertion for five and nine channels. A patched ARM64 Release core build passed a native 24-case check across Mat and UMat, CV_8U, CV_16F and CV_32F, and channels 1, 4, 5 and 9. Added a parameterized Core regression test.
This commit is contained in:
@@ -998,7 +998,10 @@ void pow( InputArray _src, double power, OutputArray _dst )
|
||||
{
|
||||
case 0:
|
||||
_dst.createSameSize(_src, type);
|
||||
_dst.setTo(Scalar::all(1));
|
||||
if (cn > 4 && !_dst.isGpuMat())
|
||||
_dst.setTo(1.0);
|
||||
else
|
||||
_dst.setTo(Scalar::all(1));
|
||||
return;
|
||||
case 1:
|
||||
_src.copyTo(_dst);
|
||||
|
||||
@@ -2572,6 +2572,24 @@ TEST(Core_Transform, accuracy) { Core_TransformTest test; test.safe_run(); }
|
||||
TEST(Core_TransformLarge, accuracy) { Core_TransformLargeTest test; test.safe_run(); }
|
||||
TEST(Core_PerspectiveTransform, accuracy) { Core_PerspectiveTransformTest test; test.safe_run(); }
|
||||
TEST(Core_Pow, accuracy) { Core_PowTest test; test.safe_run(); }
|
||||
|
||||
using Core_PowZero = testing::TestWithParam<int>;
|
||||
|
||||
TEST_P(Core_PowZero, fills_all_channels)
|
||||
{
|
||||
const int channels = GetParam();
|
||||
Mat src(3, 7, CV_MAKETYPE(CV_32F, channels));
|
||||
src.reshape(1).setTo(-2.0);
|
||||
Mat dst;
|
||||
|
||||
cv::pow(src, 0, dst);
|
||||
|
||||
ASSERT_EQ(src.size(), dst.size());
|
||||
ASSERT_EQ(src.type(), dst.type());
|
||||
EXPECT_EQ(0, countNonZero(dst.reshape(1) != 1));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/**/, Core_PowZero, testing::Values(1, 4, 5, 9));
|
||||
TEST(Core_SolveLinearSystem, accuracy) { Core_SolveTest test; test.safe_run(); }
|
||||
TEST(Core_Trace, accuracy) { Core_TraceTest test; test.safe_run(); }
|
||||
TEST(Core_SolvePoly, accuracy) { Core_SolvePolyTest test; test.safe_run(); }
|
||||
|
||||
Reference in New Issue
Block a user