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

features2d: improve detector parameter validation

This commit is contained in:
Primary-H
2026-05-31 23:40:50 +08:00
parent ebb46d5f17
commit a7bb1d1e1e
9 changed files with 72 additions and 4 deletions
+3
View File
@@ -8052,6 +8052,9 @@ void AGAST(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, boo
case AgastFeatureDetector::OAST_9_16:
OAST_9_16(_img, kpts, threshold);
break;
default:
CV_Error_(Error::StsBadArg,
("Unknown AgastFeatureDetector detector type: %d", static_cast<int>(type)));
}
cv::Mat img = _img.getMat();
+2
View File
@@ -104,6 +104,8 @@ public:
}
virtual void setPatternScale(float _patternScale) CV_OVERRIDE
{
CV_CheckGT(_patternScale, 0.f, "patternScale must be positive");
patternScale = _patternScale;
std::vector<float> rList;
std::vector<int> nList;
+10 -2
View File
@@ -441,6 +441,14 @@ void FAST(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bool
{
CV_INSTRUMENT_REGION();
if (type != FastFeatureDetector::TYPE_5_8 &&
type != FastFeatureDetector::TYPE_7_12 &&
type != FastFeatureDetector::TYPE_9_16)
{
CV_Error_(Error::StsBadArg,
("Unknown FastFeatureDetector detector type: %d", static_cast<int>(type)));
}
const size_t max_fast_features = std::max(_img.total()/100, size_t(1000)); // Simple heuristic that depends on resolution.
CV_OCL_RUN(_img.isUMat() && type == FastFeatureDetector::TYPE_9_16,
@@ -549,7 +557,7 @@ public:
else if(prop == FAST_N)
type = static_cast<FastFeatureDetector::DetectorType>(cvRound(value));
else
CV_Error(Error::StsBadArg, "");
CV_Error_(Error::StsBadArg, ("Unknown FastFeatureDetector property: %d", prop));
}
double get(int prop) const
@@ -560,7 +568,7 @@ public:
return nonmaxSuppression;
if(prop == FAST_N)
return static_cast<int>(type);
CV_Error(Error::StsBadArg, "");
CV_Error_(Error::StsBadArg, ("Unknown FastFeatureDetector property: %d", prop));
return 0;
}
+19 -1
View File
@@ -1266,7 +1266,25 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask,
Ptr<ORB> ORB::create(int nfeatures, float scaleFactor, int nlevels, int edgeThreshold,
int firstLevel, int wta_k, ORB::ScoreType scoreType, int patchSize, int fastThreshold)
{
CV_Assert(firstLevel >= 0);
CV_CheckGE(nfeatures, 0, "nfeatures must be non-negative");
CV_CheckGT(scaleFactor, 1.f, "scaleFactor must be greater than 1");
CV_CheckGT(nlevels, 0, "nlevels must be positive");
CV_CheckGE(edgeThreshold, 0, "edgeThreshold must be non-negative");
CV_CheckGE(firstLevel, 0, "firstLevel must be non-negative");
CV_CheckGE(patchSize, 2, "patchSize must be at least 2");
if (wta_k != 2 && wta_k != 3 && wta_k != 4)
{
CV_Error_(Error::StsBadArg,
("wta_k must be 2, 3, or 4, but got %d", wta_k));
}
if (scoreType != ORB::HARRIS_SCORE && scoreType != ORB::FAST_SCORE)
{
CV_Error_(Error::StsBadArg,
("Unknown ORB score type: %d", static_cast<int>(scoreType)));
}
return makePtr<ORB_Impl>(nfeatures, scaleFactor, nlevels, edgeThreshold,
firstLevel, wta_k, scoreType, patchSize, fastThreshold);
}