mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
imgproc: add parameter checks in calcHist and calcBackProj
This commit is contained in:
@@ -1957,5 +1957,42 @@ TEST(Imgproc_Hist_Calc, calcHist_regression_11544)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Imgproc_Hist_Calc, badarg)
|
||||
{
|
||||
const int channels[] = {0};
|
||||
float range1[] = {0, 10};
|
||||
float range2[] = {10, 20};
|
||||
const float * ranges[] = {range1, range2};
|
||||
Mat img = cv::Mat::zeros(10, 10, CV_8UC1);
|
||||
Mat imgInt = cv::Mat::zeros(10, 10, CV_32SC1);
|
||||
Mat hist;
|
||||
const int hist_size[] = { 100 };
|
||||
// base run
|
||||
EXPECT_NO_THROW(cv::calcHist(&img, 1, channels, noArray(), hist, 1, hist_size, ranges, true));
|
||||
// bad parameters
|
||||
EXPECT_THROW(cv::calcHist(NULL, 1, channels, noArray(), hist, 1, hist_size, ranges, true), cv::Exception);
|
||||
EXPECT_THROW(cv::calcHist(&img, 0, channels, noArray(), hist, 1, hist_size, ranges, true), cv::Exception);
|
||||
EXPECT_THROW(cv::calcHist(&img, 1, NULL, noArray(), hist, 2, hist_size, ranges, true), cv::Exception);
|
||||
EXPECT_THROW(cv::calcHist(&img, 1, channels, noArray(), noArray(), 1, hist_size, ranges, true), cv::Exception);
|
||||
EXPECT_THROW(cv::calcHist(&img, 1, channels, noArray(), hist, -1, hist_size, ranges, true), cv::Exception);
|
||||
EXPECT_THROW(cv::calcHist(&img, 1, channels, noArray(), hist, 1, NULL, ranges, true), cv::Exception);
|
||||
EXPECT_THROW(cv::calcHist(&imgInt, 1, channels, noArray(), hist, 1, hist_size, NULL, true), cv::Exception);
|
||||
// special case
|
||||
EXPECT_NO_THROW(cv::calcHist(&img, 1, channels, noArray(), hist, 1, hist_size, NULL, true));
|
||||
|
||||
Mat backProj;
|
||||
// base run
|
||||
EXPECT_NO_THROW(cv::calcBackProject(&img, 1, channels, hist, backProj, ranges, 1, true));
|
||||
// bad parameters
|
||||
EXPECT_THROW(cv::calcBackProject(NULL, 1, channels, hist, backProj, ranges, 1, true), cv::Exception);
|
||||
EXPECT_THROW(cv::calcBackProject(&img, 0, channels, hist, backProj, ranges, 1, true), cv::Exception);
|
||||
EXPECT_THROW(cv::calcBackProject(&img, 1, channels, noArray(), backProj, ranges, 1, true), cv::Exception);
|
||||
EXPECT_THROW(cv::calcBackProject(&img, 1, channels, hist, noArray(), ranges, 1, true), cv::Exception);
|
||||
EXPECT_THROW(cv::calcBackProject(&imgInt, 1, channels, hist, backProj, NULL, 1, true), cv::Exception);
|
||||
// special case
|
||||
EXPECT_NO_THROW(cv::calcBackProject(&img, 1, channels, hist, backProj, NULL, 1, true));
|
||||
}
|
||||
|
||||
|
||||
}} // namespace
|
||||
/* End Of File */
|
||||
|
||||
Reference in New Issue
Block a user