Skip to content

Commit 9f2b371

Browse files
add check corners and ids
1 parent 3d855aa commit 9f2b371

File tree

2 files changed

+104
-6
lines changed

2 files changed

+104
-6
lines changed

modules/aruco/test/test_arucodetection.cpp

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,30 @@ TEST(CV_ArucoTutorial, can_find_singlemarkersoriginal)
564564
vector< int > ids;
565565
vector< vector< Point2f > > corners, rejected;
566566
Ptr<aruco::DetectorParameters> detectorParams = aruco::DetectorParameters::create();
567+
const size_t N = 6ull;
568+
// corners of ArUco markers with indices goldCornersIds
569+
const int goldCorners[N][8] = { {359,310, 404,310, 410,350, 362,350}, {427,255, 469,256, 477,289, 434,288},
570+
{233,273, 190,273, 196,241, 237,241}, {298,185, 334,186, 335,212, 297,211},
571+
{425,163, 430,186, 394,186, 390,162}, {195,155, 230,155, 227,178, 190,178} };
572+
const int goldCornersIds[N] = { 40, 98, 62, 23, 124, 203};
573+
map<int, const int*> mapGoldCorners;
574+
for (size_t i = 0; i < N; i++)
575+
mapGoldCorners[goldCornersIds[i]] = goldCorners[i];
567576

568577
aruco::detectMarkers(image, dictionary, corners, ids, detectorParams, rejected);
569-
EXPECT_EQ(6, (int)ids.size());
578+
579+
ASSERT_EQ(N, ids.size());
580+
for (size_t i = 0; i < N; i++)
581+
{
582+
int arucoId = ids[i];
583+
ASSERT_EQ(4ull, corners[i].size());
584+
ASSERT_TRUE(mapGoldCorners.find(arucoId) != mapGoldCorners.end());
585+
for (int j = 0; j < 4; j++)
586+
{
587+
EXPECT_NEAR(static_cast<float>(mapGoldCorners[arucoId][j * 2]), corners[i][j].x, 1.f);
588+
EXPECT_NEAR(static_cast<float>(mapGoldCorners[arucoId][j * 2 + 1]), corners[i][j].y, 1.f);
589+
}
590+
}
570591
}
571592

572593
TEST(CV_ArucoTutorial, can_find_gboriginal)
@@ -581,9 +602,45 @@ TEST(CV_ArucoTutorial, can_find_gboriginal)
581602
vector< int > ids;
582603
vector< vector< Point2f > > corners, rejected;
583604
Ptr<aruco::DetectorParameters> detectorParams = aruco::DetectorParameters::create();
605+
const size_t N = 35ull;
606+
// corners of ArUco markers with indices 0, 1, ..., 34
607+
const int goldCorners[N][8] = { {252,74, 286,81, 274,102, 238,95}, {295,82, 330,89, 319,111, 282,104},
608+
{338,91, 375,99, 365,121, 327,113}, {383,100, 421,107, 412,130, 374,123},
609+
{429,109, 468,116, 461,139, 421,132}, {235,100, 270,108, 257,130, 220,122},
610+
{279,109, 316,117, 304,140, 266,133}, {324,119, 362,126, 352,150, 313,143},
611+
{371,128, 410,136, 400,161, 360,152}, {418,139, 459,145, 451,170, 410,163},
612+
{216,128, 253,136, 239,161, 200,152}, {262,138, 300,146, 287,172, 248,164},
613+
{309,148, 349,156, 337,183, 296,174}, {358,158, 398,167, 388,194, 346,185},
614+
{407,169, 449,176, 440,205, 397,196}, {196,158, 235,168, 218,195, 179,185},
615+
{243,170, 283,178, 269,206, 228,197}, {293,180, 334,190, 321,218, 279,209},
616+
{343,192, 385,200, 374,230, 330,220}, {395,203, 438,211, 429,241, 384,233},
617+
{174,192, 215,201, 197,231, 156,221}, {223,204, 265,213, 249,244, 207,234},
618+
{275,215, 317,225, 303,257, 259,246}, {327,227, 371,238, 359,270, 313,259},
619+
{381,240, 426,249, 416,282, 369,273}, {151,228, 193,238, 173,271, 130,260},
620+
{202,241, 245,251, 228,285, 183,274}, {255,254, 300,264, 284,299, 238,288},
621+
{310,267, 355,278, 342,314, 295,302}, {366,281, 413,290, 402,327, 353,317},
622+
{125,267, 168,278, 147,314, 102,303}, {178,281, 223,293, 204,330, 157,317},
623+
{233,296, 280,307, 263,346, 214,333}, {291,310, 338,322, 323,363, 274,349},
624+
{349,325, 399,336, 386,378, 335,366} };
625+
map<int, const int*> mapGoldCorners;
626+
for (int i = 0; i < static_cast<int>(N); i++)
627+
mapGoldCorners[i] = goldCorners[i];
584628

585629
aruco::detectMarkers(image, dictionary, corners, ids, detectorParams, rejected);
586-
EXPECT_EQ(35, (int)ids.size());
630+
631+
632+
ASSERT_EQ(N, ids.size());
633+
for (size_t i = 0; i < N; i++)
634+
{
635+
int arucoId = ids[i];
636+
ASSERT_EQ(4ull, corners[i].size());
637+
ASSERT_TRUE(mapGoldCorners.find(arucoId) != mapGoldCorners.end());
638+
for (int j = 0; j < 4; j++)
639+
{
640+
EXPECT_NEAR(static_cast<float>(mapGoldCorners[arucoId][j*2]), corners[i][j].x, 1.f);
641+
EXPECT_NEAR(static_cast<float>(mapGoldCorners[arucoId][j*2+1]), corners[i][j].y, 1.f);
642+
}
643+
}
587644
}
588645

589646
}} // namespace

modules/aruco/test/test_charucodetection.cpp

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ or tort (including negligence or otherwise) arising in any way out of
3636
the use of this software, even if advised of the possibility of such damage.
3737
*/
3838

39-
4039
#include "test_precomp.hpp"
4140
#include "../samples/samples_utility.hpp"
4241

@@ -687,9 +686,35 @@ TEST(CV_ArucoTutorial, can_find_choriginal)
687686
vector< int > ids;
688687
vector< vector< Point2f > > corners, rejected;
689688
Ptr<aruco::DetectorParameters> detectorParams = aruco::DetectorParameters::create();
689+
const size_t N = 17;
690+
// corners of aruco markers with indices goldCornersIds
691+
const int goldCorners[N][8] = { {268, 77,290, 80,286, 97,263, 94}, {360, 90,382, 93,379, 111,357, 108},
692+
{211, 106,233, 109,228, 127,205, 123}, {306, 120,328, 124,325, 142,302, 138},
693+
{402, 135,425, 139,423, 157,400, 154}, {247, 152,271, 155,267, 174,242, 171},
694+
{347, 167,371, 171,369, 191,344, 187}, {185, 185,209, 189,203, 210,178, 206},
695+
{288, 201,313, 206,309, 227,284, 223}, {393, 218,418, 222,416, 245,391, 241},
696+
{223, 240,250, 244,244, 268,217, 263}, {333, 258,359, 262,356, 286,329, 282},
697+
{152, 281,179, 285,171, 312,143, 307}, {267, 300,294, 305,289, 331,261, 327},
698+
{383, 319,410, 324,408, 351,380, 347}, {194, 347,223, 352,216, 382,186, 377},
699+
{315, 368,345, 373,341, 403,310, 398} };
700+
map<int, const int*> mapGoldCorners;
701+
for (int i = 0; i < static_cast<int>(N); i++)
702+
mapGoldCorners[i] = goldCorners[i];
690703

691704
aruco::detectMarkers(image, dictionary, corners, ids, detectorParams, rejected);
692-
EXPECT_EQ(17, (int)ids.size());
705+
706+
ASSERT_EQ(N, ids.size());
707+
for (size_t i = 0; i < N; i++)
708+
{
709+
int arucoId = ids[i];
710+
ASSERT_EQ(4ull, corners[i].size());
711+
ASSERT_TRUE(mapGoldCorners.find(arucoId) != mapGoldCorners.end());
712+
for (int j = 0; j < 4; j++)
713+
{
714+
EXPECT_NEAR(static_cast<float>(mapGoldCorners[arucoId][j * 2]), corners[i][j].x, 1.f);
715+
EXPECT_NEAR(static_cast<float>(mapGoldCorners[arucoId][j * 2 + 1]), corners[i][j].y, 1.f);
716+
}
717+
}
693718
}
694719

695720
TEST(CV_ArucoTutorial, can_find_chocclusion)
@@ -701,9 +726,11 @@ TEST(CV_ArucoTutorial, can_find_chocclusion)
701726
vector< int > ids;
702727
vector< vector< Point2f > > corners, rejected;
703728
Ptr<aruco::DetectorParameters> detectorParams = aruco::DetectorParameters::create();
729+
const size_t N = 13;
704730

705731
aruco::detectMarkers(image, dictionary, corners, ids, detectorParams, rejected);
706-
EXPECT_EQ(13, (int)ids.size());
732+
733+
EXPECT_EQ(N, ids.size());
707734
}
708735

709736
TEST(CV_ArucoTutorial, can_find_diamondmarkers)
@@ -722,9 +749,23 @@ TEST(CV_ArucoTutorial, can_find_diamondmarkers)
722749
Ptr<aruco::DetectorParameters> detectorParams = aruco::DetectorParameters::create();
723750
readDetectorParameters(detectorPath, detectorParams);
724751
detectorParams->cornerRefinementMethod = 3;
752+
const size_t N = 12;
753+
// corner indices of ArUco markers
754+
const int goldCornersIds[N] = { 4, 12, 11, 3, 12, 10, 12, 10, 10, 11, 2, 11 };
755+
map<int, int> counterGoldCornersIds;
756+
for (int i = 0; i < static_cast<int>(N); i++)
757+
counterGoldCornersIds[goldCornersIds[i]]++;
725758

726759
aruco::detectMarkers(image, dictionary, corners, ids, detectorParams, rejected);
727-
EXPECT_EQ(12, (int)ids.size());
760+
map<int, int> counterRes;
761+
for (size_t i = 0; i < N; i++)
762+
{
763+
int arucoId = ids[i];
764+
counterRes[arucoId]++;
765+
}
766+
767+
ASSERT_EQ(N, ids.size());
768+
EXPECT_EQ(counterGoldCornersIds, counterRes); // check the number of ArUco markers
728769
}
729770

730771
}} // namespace

0 commit comments

Comments
 (0)