mirror of
https://github.com/opencv/opencv.git
synced 2025-01-19 06:53:50 +08:00
fix detect rotated grid, added test
This commit is contained in:
parent
8f83540018
commit
eaa88e7bc7
@ -701,22 +701,26 @@ bool CirclesGridFinder::isDetectionCorrect()
|
||||
{
|
||||
case CirclesGridFinderParameters::SYMMETRIC_GRID:
|
||||
{
|
||||
if (holes.size() != patternSize.height)
|
||||
rotatedGrid = holes.size() != patternSize.height && holes.size() == patternSize.width;
|
||||
if (holes.size() != patternSize.height && holes.size() != patternSize.width)
|
||||
return false;
|
||||
|
||||
std::set<size_t> vertices;
|
||||
size_t num_vertices = 0ull;
|
||||
for (size_t i = 0; i < holes.size(); i++)
|
||||
{
|
||||
if (holes[i].size() != patternSize.width)
|
||||
return false;
|
||||
|
||||
for (size_t j = 0; j < holes[i].size(); j++)
|
||||
if (holes[i].size() != patternSize.width && rotatedGrid == false)
|
||||
{
|
||||
vertices.insert(holes[i][j]);
|
||||
return false;
|
||||
}
|
||||
else if (holes[i].size() != patternSize.height && rotatedGrid == true)
|
||||
{
|
||||
rotatedGrid = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return vertices.size() == patternSize.area();
|
||||
num_vertices += holes[i].size();
|
||||
}
|
||||
return num_vertices == patternSize.area();
|
||||
}
|
||||
|
||||
case CirclesGridFinderParameters::ASYMMETRIC_GRID:
|
||||
@ -1431,12 +1435,32 @@ Size CirclesGridFinder::getDetectedGridSize() const
|
||||
void CirclesGridFinder::getHoles(std::vector<Point2f> &outHoles) const
|
||||
{
|
||||
outHoles.clear();
|
||||
|
||||
for (size_t i = 0; i < holes.size(); i++)
|
||||
if (rotatedGrid == false)
|
||||
{
|
||||
for (size_t j = 0; j < holes[i].size(); j++)
|
||||
for (size_t i = 0ull; i < holes.size(); i++)
|
||||
{
|
||||
outHoles.push_back(keypoints[holes[i][j]]);
|
||||
for (size_t j = 0ull; j < holes[i].size(); j++)
|
||||
{
|
||||
outHoles.push_back(keypoints[holes[i][j]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool visit_all = false;
|
||||
size_t j = 0ull;
|
||||
while (visit_all != true)
|
||||
{
|
||||
visit_all = true;
|
||||
for (size_t i = 0ull; i < holes.size(); i++)
|
||||
{
|
||||
if (j < holes[i].size())
|
||||
{
|
||||
outHoles.push_back(keypoints[holes[i][j]]);
|
||||
visit_all = false;
|
||||
}
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -186,6 +186,7 @@ private:
|
||||
|
||||
const cv::Size_<size_t> patternSize;
|
||||
cv::CirclesGridFinderParameters parameters;
|
||||
bool rotatedGrid = false;
|
||||
|
||||
CirclesGridFinder& operator=(const CirclesGridFinder&);
|
||||
CirclesGridFinder(const CirclesGridFinder&);
|
||||
|
@ -792,5 +792,42 @@ TEST(Calib3d_AsymmetricCirclesPatternDetector, regression_19498)
|
||||
EXPECT_FALSE(res);
|
||||
}
|
||||
|
||||
TEST(Calib3d_RotatedCirclesPatternDetector, issue_24964)
|
||||
{
|
||||
string path = cvtest::findDataFile("cv/cameracalibration/circles/circles_24964.png");
|
||||
Mat image = cv::imread(path);
|
||||
ASSERT_FALSE(image.empty()) << "Can't read image: " << path;
|
||||
|
||||
vector<Point2f> centers;
|
||||
Size parrernSize(7, 6);
|
||||
Mat goldCenters(parrernSize.height, parrernSize.width, CV_32FC2);
|
||||
Point2f firstGoldCenter(380.f, 430.f);
|
||||
for (int i = 0; i < parrernSize.height; i++)
|
||||
{
|
||||
for (int j = 0; j < parrernSize.width; j++)
|
||||
{
|
||||
goldCenters.at<Point2f>(i, j) = Point2f(firstGoldCenter.x + j * 100.f, firstGoldCenter.y + i * 100.f);
|
||||
}
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
found = findCirclesGrid(image, parrernSize, centers, CALIB_CB_SYMMETRIC_GRID);
|
||||
|
||||
EXPECT_TRUE(found);
|
||||
ASSERT_EQ(centers.size(), (size_t)parrernSize.area());
|
||||
double error = calcError(centers, goldCenters);
|
||||
EXPECT_LE(error, precise_success_error_level);
|
||||
|
||||
// "rotate" the circle grid by 90 degrees
|
||||
swap(parrernSize.height, parrernSize.width);
|
||||
|
||||
found = findCirclesGrid(image, parrernSize, centers, CALIB_CB_SYMMETRIC_GRID);
|
||||
error = calcError(centers, goldCenters.t());
|
||||
|
||||
EXPECT_TRUE(found);
|
||||
ASSERT_EQ(centers.size(), (size_t)parrernSize.area());
|
||||
EXPECT_LE(error, precise_success_error_level);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
/* End of file. */
|
||||
|
Loading…
Reference in New Issue
Block a user