Skip to content

Commit beb5140

Browse files
author
AleksandrPanov
committed
fix search for one contour in _filterTooCloseCandidates() + add regression_3192 test
1 parent b18c34a commit beb5140

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

modules/aruco/src/aruco.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ static void _filterTooCloseCandidates(const vector< vector< Point2f > > &candida
284284
candGroup.resize(candidatesIn.size(), -1);
285285
vector< vector<unsigned int> > groupedCandidates;
286286
for(unsigned int i = 0; i < candidatesIn.size(); i++) {
287+
bool isSingleContour = true;
287288
for(unsigned int j = i + 1; j < candidatesIn.size(); j++) {
288289

289290
int minimumPerimeter = min((int)contoursIn[i].size(), (int)contoursIn[j].size() );
@@ -304,6 +305,7 @@ static void _filterTooCloseCandidates(const vector< vector< Point2f > > &candida
304305
// if mean square distance is too low, remove the smaller one of the two markers
305306
double minMarkerDistancePixels = double(minimumPerimeter) * minMarkerDistanceRate;
306307
if(distSq < minMarkerDistancePixels * minMarkerDistancePixels) {
308+
isSingleContour = false;
307309
// i and j are not related to a group
308310
if(candGroup[i]<0 && candGroup[j]<0){
309311
// mark candidates with their corresponding group number
@@ -334,6 +336,14 @@ static void _filterTooCloseCandidates(const vector< vector< Point2f > > &candida
334336
}
335337
}
336338
}
339+
if (isSingleContour && candGroup[i] < 0)
340+
{
341+
candGroup[i] = (int)groupedCandidates.size();
342+
vector<unsigned int> grouped;
343+
grouped.push_back(i);
344+
grouped.push_back(i);
345+
groupedCandidates.push_back( grouped );
346+
}
337347
}
338348

339349
// save possible candidates

modules/aruco/test/test_arucodetection.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ TEST(CV_ArucoTutorial, can_find_gboriginal)
594594
string imgPath = cvtest::findDataFile("gboriginal.png", false);
595595
Mat image = imread(imgPath);
596596
string dictPath = cvtest::findDataFile("tutorial_dict.yml", false);
597-
cv::Ptr<cv::aruco::Dictionary> dictionary;
597+
Ptr<aruco::Dictionary> dictionary = makePtr<aruco::Dictionary>();
598598

599599
FileStorage fs(dictPath, FileStorage::READ);
600600
dictionary->aruco::Dictionary::readDictionary(fs.root()); // set marker from tutorial_dict.yml
@@ -644,4 +644,20 @@ TEST(CV_ArucoTutorial, can_find_gboriginal)
644644
}
645645
}
646646

647+
TEST(CV_ArucoTutorial, regression_3192)
648+
{
649+
Ptr<aruco::Dictionary> dictionary = aruco::getPredefinedDictionary(aruco::DICT_4X4_50);
650+
Ptr<aruco::DetectorParameters> detectorParams = aruco::DetectorParameters::create();
651+
//detectorParams->cornerRefinementMethod = aruco::CORNER_REFINE_APRILTAG;
652+
vector< int > markerIds;
653+
vector<vector<Point2f> > markerCorners;
654+
655+
string imgPath = cvtest::findDataFile("aruco/regression_3192.png", true);
656+
Mat image = imread(imgPath);
657+
658+
aruco::detectMarkers(image, dictionary, markerCorners, markerIds, detectorParams);
659+
ASSERT_EQ(2ull, markerIds.size());
660+
661+
}
662+
647663
}} // namespace

modules/aruco/test/test_charucodetection.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ TEST(CV_ArucoTutorial, can_find_diamondmarkers)
695695
Mat image = imread(imgPath);
696696

697697
string dictPath = cvtest::findDataFile("tutorial_dict.yml", false);
698-
Ptr<cv::aruco::Dictionary> dictionary;
698+
Ptr<aruco::Dictionary> dictionary = makePtr<aruco::Dictionary>();
699699
FileStorage fs(dictPath, FileStorage::READ);
700700
dictionary->aruco::Dictionary::readDictionary(fs.root()); // set marker from tutorial_dict.yml
701701

@@ -745,15 +745,16 @@ TEST(Charuco, issue_14014)
745745
ASSERT_EQ(corners.size(), 19ull);
746746
EXPECT_EQ(Size(4, 1), corners[0].size()); // check dimension of detected corners
747747

748-
ASSERT_EQ(rejectedPoints.size(), 21ull);
748+
size_t numRejPoints = rejectedPoints.size();
749+
ASSERT_TRUE(numRejPoints > 0ull);
749750
EXPECT_EQ(Size(4, 1), rejectedPoints[0].size()); // check dimension of detected corners
750751

751752
aruco::refineDetectedMarkers(img, board, corners, ids, rejectedPoints);
752753

753754
ASSERT_EQ(corners.size(), 20ull);
754755
EXPECT_EQ(Size(4, 1), corners[0].size()); // check dimension of rejected corners after successfully refine
755756

756-
ASSERT_EQ(rejectedPoints.size(), 20ull);
757+
ASSERT_EQ(rejectedPoints.size() + 1, numRejPoints);
757758
EXPECT_EQ(Size(4, 1), rejectedPoints[0].size()); // check dimension of rejected corners after successfully refine
758759
}
759760

0 commit comments

Comments
 (0)