mirror of
https://github.com/opencv/opencv.git
synced 2026-09-11 04:43:22 -05:00
Merge pull request #29855 from lazerg:fix/issue-29854-empty-input-crash
imgproc: reject empty input in connected components
This commit is contained in:
@@ -5650,6 +5650,7 @@ namespace cv{
|
||||
template<typename StatsOp>
|
||||
static
|
||||
int connectedComponents_sub1(const cv::Mat& I, cv::Mat& L, int connectivity, int ccltype, StatsOp& sop){
|
||||
CV_Assert(!I.empty());
|
||||
CV_Assert(L.channels() == 1 && I.channels() == 1);
|
||||
CV_Assert(connectivity == 8 || connectivity == 4);
|
||||
CV_Assert(ccltype == CCL_SPAGHETTI || ccltype == CCL_BBDT || ccltype == CCL_SAUF || ccltype == CCL_BOLELLI || ccltype == CCL_GRANA || ccltype == CCL_WU || ccltype == CCL_DEFAULT);
|
||||
|
||||
@@ -795,5 +795,25 @@ TEST(Imgproc_ConnectedComponents, regression_27568)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Imgproc_ConnectedComponents, regression_29854)
|
||||
{
|
||||
for (const Size& size : {Size(400, 0), Size(0, 400), Size(0, 0)})
|
||||
{
|
||||
Mat image = Mat::zeros(size, CV_8UC1);
|
||||
|
||||
for (const int connectivity : {4, 8})
|
||||
{
|
||||
for (const int ccltype : {CCL_DEFAULT, CCL_WU, CCL_GRANA, CCL_BOLELLI, CCL_SAUF, CCL_BBDT, CCL_SPAGHETTI})
|
||||
{
|
||||
Mat labels, stats, centroids;
|
||||
EXPECT_THROW(connectedComponents(
|
||||
image, labels, connectivity, CV_32S, ccltype), Exception);
|
||||
EXPECT_THROW(connectedComponentsWithStats(
|
||||
image, labels, stats, centroids, connectivity, CV_32S, ccltype), Exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user