mirror of
https://github.com/opencv/opencv.git
synced 2025-01-19 06:53:50 +08:00
Added checks for incorrect results in the circles grid pattern detection.
This commit is contained in:
parent
37cd2b6f25
commit
a811a08d0d
@ -107,6 +107,10 @@ void CirclesGridClusterFinder::hierarchicalClustering(const vector<Point2f> poin
|
|||||||
void CirclesGridClusterFinder::findGrid(const std::vector<cv::Point2f> points, cv::Size patternSize, vector<Point2f>& centers)
|
void CirclesGridClusterFinder::findGrid(const std::vector<cv::Point2f> points, cv::Size patternSize, vector<Point2f>& centers)
|
||||||
{
|
{
|
||||||
centers.clear();
|
centers.clear();
|
||||||
|
if(points.empty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
vector<Point2f> patternPoints;
|
vector<Point2f> patternPoints;
|
||||||
hierarchicalClustering(points, patternSize, patternPoints);
|
hierarchicalClustering(points, patternSize, patternPoints);
|
||||||
@ -117,18 +121,30 @@ void CirclesGridClusterFinder::findGrid(const std::vector<cv::Point2f> points, c
|
|||||||
|
|
||||||
vector<Point2f> hull2f;
|
vector<Point2f> hull2f;
|
||||||
convexHull(Mat(patternPoints), hull2f, false);
|
convexHull(Mat(patternPoints), hull2f, false);
|
||||||
|
const size_t cornersCount = 6;
|
||||||
|
if(hull2f.size() < cornersCount)
|
||||||
|
return;
|
||||||
|
|
||||||
vector<Point2f> corners;
|
vector<Point2f> corners;
|
||||||
findCorners(hull2f, corners);
|
findCorners(hull2f, corners);
|
||||||
|
if(corners.size() != cornersCount)
|
||||||
|
return;
|
||||||
|
|
||||||
vector<Point2f> outsideCorners;
|
vector<Point2f> outsideCorners;
|
||||||
findOutsideCorners(corners, outsideCorners);
|
findOutsideCorners(corners, outsideCorners);
|
||||||
|
const size_t outsideCornersCount = 2;
|
||||||
|
if(outsideCorners.size() != outsideCornersCount)
|
||||||
|
return;
|
||||||
|
|
||||||
vector<Point2f> sortedCorners;
|
vector<Point2f> sortedCorners;
|
||||||
getSortedCorners(hull2f, corners, outsideCorners, sortedCorners);
|
getSortedCorners(hull2f, corners, outsideCorners, sortedCorners);
|
||||||
|
if(sortedCorners.size() != cornersCount)
|
||||||
|
return;
|
||||||
|
|
||||||
vector<Point2f> rectifiedPatternPoints;
|
vector<Point2f> rectifiedPatternPoints;
|
||||||
rectifyPatternPoints(patternSize, patternPoints, sortedCorners, rectifiedPatternPoints);
|
rectifyPatternPoints(patternSize, patternPoints, sortedCorners, rectifiedPatternPoints);
|
||||||
|
if(patternPoints.size() != rectifiedPatternPoints.size())
|
||||||
|
return;
|
||||||
|
|
||||||
parsePatternPoints(patternSize, patternPoints, rectifiedPatternPoints, centers);
|
parsePatternPoints(patternSize, patternPoints, rectifiedPatternPoints, centers);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user