mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #24578 from Kumataro:fix_verify_unsupported_new_mat_depth
Fix verify unsupported new mat depth for nonzero/minmax/lut #24578 `cv::LUI()`, `cv::minMaxLoc()`, `cv::minMaxIdx()`, `cv::countNonZero()`, `cv::findNonZero()` and `cv::hasNonZero()` uses depth-based function table. However, it is too short for `CV_16BF`, `CV_Bool`, `CV_64U`, `CV_64S` and `CV_32U` and it may occur out-boundary-access. This patch fix it. And If necessary, when someone extends these functions to support, please relax this test. ### 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
This commit is contained in:
@@ -3032,4 +3032,75 @@ TEST_P(FiniteMaskFixture, flags)
|
||||
// Params are: depth, channels 1 to 4
|
||||
INSTANTIATE_TEST_CASE_P(Core_FiniteMask, FiniteMaskFixture, ::testing::Combine(::testing::Values(CV_32F, CV_64F), ::testing::Range(1, 5)));
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
typedef testing::TestWithParam<perf::MatDepth> NonZeroNotSupportedMatDepth;
|
||||
|
||||
TEST_P(NonZeroNotSupportedMatDepth, findNonZero)
|
||||
{
|
||||
cv::Mat src = cv::Mat(16,16, CV_MAKETYPE(GetParam(), 1));
|
||||
vector<Point> pts;
|
||||
EXPECT_THROW( findNonZero(src, pts), cv::Exception);
|
||||
}
|
||||
|
||||
TEST_P(NonZeroNotSupportedMatDepth, countNonZero)
|
||||
{
|
||||
cv::Mat src = cv::Mat(16,16, CV_MAKETYPE(GetParam(), 1));
|
||||
EXPECT_THROW( countNonZero(src), cv::Exception);
|
||||
}
|
||||
|
||||
TEST_P(NonZeroNotSupportedMatDepth, hasNonZero)
|
||||
{
|
||||
cv::Mat src = cv::Mat(16,16, CV_MAKETYPE(GetParam(), 1));
|
||||
EXPECT_THROW( hasNonZero(src), cv::Exception);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
NonZero,
|
||||
NonZeroNotSupportedMatDepth,
|
||||
testing::Values(perf::MatDepth(CV_16F), CV_16BF, CV_Bool, CV_64U, CV_64S, CV_32U)
|
||||
);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
typedef testing::TestWithParam<perf::MatDepth> 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(perf::MatDepth(CV_16F), CV_16BF, CV_Bool, CV_64U, CV_64S, CV_32U)
|
||||
);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
typedef testing::TestWithParam<perf::MatDepth> MinMaxNotSupportedMatDepth;
|
||||
|
||||
TEST_P(MinMaxNotSupportedMatDepth, minMaxLoc)
|
||||
{
|
||||
cv::Mat src = cv::Mat(16,16, CV_MAKETYPE(GetParam(), 1));
|
||||
double minV=0.0, maxV=0.0;
|
||||
Point minLoc, maxLoc;
|
||||
EXPECT_THROW( cv::minMaxLoc(src, &minV, &maxV, &minLoc, &maxLoc), cv::Exception);
|
||||
}
|
||||
|
||||
TEST_P(MinMaxNotSupportedMatDepth, minMaxIdx)
|
||||
{
|
||||
cv::Mat src = cv::Mat(16,16, CV_MAKETYPE(GetParam(), 1));
|
||||
double minV=0.0, maxV=0.0;
|
||||
int minIdx=0, maxIdx=0;
|
||||
EXPECT_THROW( cv::minMaxIdx(src, &minV, &maxV, &minIdx, &maxIdx), cv::Exception);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
MinMaxLoc,
|
||||
MinMaxNotSupportedMatDepth,
|
||||
testing::Values(perf::MatDepth(CV_16F), CV_16BF, CV_Bool, CV_64U, CV_64S, CV_32U)
|
||||
);
|
||||
|
||||
}} // namespace
|
||||
|
||||
Reference in New Issue
Block a user