1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2025-04-28 22:13:51 +03:00
243 changed files with 12965 additions and 3216 deletions
+92
View File
@@ -75,6 +75,98 @@ TEST(Imgproc_Threshold, threshold_dryrun)
}
}
typedef tuple < bool, int, int, int, int > Imgproc_Threshold_Masked_Params_t;
typedef testing::TestWithParam< Imgproc_Threshold_Masked_Params_t > Imgproc_Threshold_Masked_Fixed;
TEST_P(Imgproc_Threshold_Masked_Fixed, threshold_mask_fixed)
{
bool useROI = get<0>(GetParam());
int depth = get<1>(GetParam());
int cn = get<2>(GetParam());
int threshType = get<3>(GetParam());
int threshFlag = get<4>(GetParam());
const int _threshType = threshType | threshFlag;
Size sz(127, 127);
Size wrapperSize = useROI ? Size(sz.width+4, sz.height+4) : sz;
Mat wrapper(wrapperSize, CV_MAKETYPE(depth, cn));
Mat input = useROI ? Mat(wrapper, Rect(Point(), sz)) : wrapper;
cv::randu(input, cv::Scalar::all(0), cv::Scalar::all(255));
Mat mask = cv::Mat::zeros(sz, CV_8UC1);
cv::RotatedRect ellipseRect((cv::Point2f)cv::Point(sz.width/2, sz.height/2), (cv::Size2f)sz, 0);
cv::ellipse(mask, ellipseRect, cv::Scalar::all(255), cv::FILLED);//for very different mask alignments
Mat output_with_mask = cv::Mat::zeros(sz, input.type());
cv::thresholdWithMask(input, output_with_mask, mask, 127, 255, _threshType);
cv::bitwise_not(mask, mask);
input.copyTo(output_with_mask, mask);
Mat output_without_mask;
cv::threshold(input, output_without_mask, 127, 255, _threshType);
input.copyTo(output_without_mask, mask);
EXPECT_MAT_NEAR(output_with_mask, output_without_mask, 0);
}
INSTANTIATE_TEST_CASE_P(/*nothing*/, Imgproc_Threshold_Masked_Fixed,
testing::Combine(
testing::Values(false, true),//use roi
testing::Values(CV_8U, CV_16U, CV_16S, CV_32F, CV_64F),//depth
testing::Values(1, 3),//channels
testing::Values(THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV),// threshTypes
testing::Values(0)
)
);
typedef testing::TestWithParam< Imgproc_Threshold_Masked_Params_t > Imgproc_Threshold_Masked_Auto;
TEST_P(Imgproc_Threshold_Masked_Auto, threshold_mask_auto)
{
bool useROI = get<0>(GetParam());
int depth = get<1>(GetParam());
int cn = get<2>(GetParam());
int threshType = get<3>(GetParam());
int threshFlag = get<4>(GetParam());
if (threshFlag == THRESH_TRIANGLE && depth != CV_8U)
throw SkipTestException("THRESH_TRIANGLE option supports CV_8UC1 input only");
const int _threshType = threshType | threshFlag;
Size sz(127, 127);
Size wrapperSize = useROI ? Size(sz.width+4, sz.height+4) : sz;
Mat wrapper(wrapperSize, CV_MAKETYPE(depth, cn));
Mat input = useROI ? Mat(wrapper, Rect(Point(), sz)) : wrapper;
cv::randu(input, cv::Scalar::all(0), cv::Scalar::all(255));
//for OTSU and TRIANGLE, we use a rectangular mask that can be just cropped
//in order to compute the threshold of the non-masked version
Mat mask = cv::Mat::zeros(sz, CV_8UC1);
cv::Rect roiRect(sz.width/4, sz.height/4, sz.width/2, sz.height/2);
cv::rectangle(mask, roiRect, cv::Scalar::all(255), cv::FILLED);
Mat output_with_mask = cv::Mat::zeros(sz, input.type());
const double autoThreshWithMask = cv::thresholdWithMask(input, output_with_mask, mask, 127, 255, _threshType);
output_with_mask = Mat(output_with_mask, roiRect);
Mat output_without_mask;
const double autoThresholdWithoutMask = cv::threshold(Mat(input, roiRect), output_without_mask, 127, 255, _threshType);
ASSERT_EQ(autoThreshWithMask, autoThresholdWithoutMask);
EXPECT_MAT_NEAR(output_with_mask, output_without_mask, 0);
}
INSTANTIATE_TEST_CASE_P(/*nothing*/, Imgproc_Threshold_Masked_Auto,
testing::Combine(
testing::Values(false, true),//use roi
testing::Values(CV_8U, CV_16U),//depth
testing::Values(1),//channels
testing::Values(THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV),// threshTypes
testing::Values(THRESH_OTSU, THRESH_TRIANGLE)
)
);
TEST(Imgproc_Threshold, regression_THRESH_TOZERO_IPP_16085)
{