Skip to content

Commit 2d95eba

Browse files
authored
Merge pull request #3713 from AleksandrPanov:update_diamond_test
add detectDiamonds to diamond test
2 parents ab82106 + 101c4d8 commit 2d95eba

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

modules/aruco/test/test_aruco_tutorial.cpp

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,36 @@ TEST(CV_ArucoTutorial, can_find_diamondmarkers)
190190
detectorParams.readDetectorParameters(fs.root());
191191
detectorParams.cornerRefinementMethod = aruco::CORNER_REFINE_APRILTAG;
192192

193-
aruco::ArucoDetector detector(dictionary, detectorParams);
193+
aruco::CharucoBoard charucoBoard(Size(3, 3), 0.4f, 0.25f, dictionary);
194+
aruco::CharucoDetector detector(charucoBoard, aruco::CharucoParameters(), detectorParams);
194195

195-
vector< int > ids;
196-
vector< vector< Point2f > > corners, rejected;
196+
vector<int> ids;
197+
vector<vector<Point2f> > corners, diamondCorners;
198+
vector<Vec4i> diamondIds;
197199
const size_t N = 12ull;
198200
// corner indices of ArUco markers
199201
const int goldCornersIds[N] = { 4, 12, 11, 3, 12, 10, 12, 10, 10, 11, 2, 11 };
200202
map<int, int> counterGoldCornersIds;
201203
for (int i = 0; i < static_cast<int>(N); i++)
202204
counterGoldCornersIds[goldCornersIds[i]]++;
203205

204-
detector.detectMarkers(image, corners, ids, rejected);
206+
const size_t diamondsN = 3;
207+
// corners of diamonds with Vec4i indices
208+
const float goldDiamondCorners[diamondsN][8] = {{195.6f,150.9f, 213.5f,201.2f, 136.4f,215.3f, 122.4f,163.5f},
209+
{501.1f,171.3f, 501.9f,208.5f, 446.2f,199.8f, 447.8f,163.3f},
210+
{343.4f,361.2f, 359.7f,328.7f, 400.8f,344.6f, 385.7f,378.4f}};
211+
auto comp = [](const Vec4i& a, const Vec4i& b) {
212+
if (a[0] < b[0]) return true;
213+
if (a[1] < b[1]) return true;
214+
if (a[2] < b[2]) return true;
215+
return a[3] < b[3];
216+
};
217+
map<Vec4i, const float*, decltype(comp)> goldDiamonds(comp);
218+
goldDiamonds[Vec4i(10, 4, 11, 12)] = goldDiamondCorners[0];
219+
goldDiamonds[Vec4i(10, 3, 11, 12)] = goldDiamondCorners[1];
220+
goldDiamonds[Vec4i(10, 2, 11, 12)] = goldDiamondCorners[2];
221+
222+
detector.detectDiamonds(image, diamondCorners, diamondIds, corners, ids);
205223
map<int, int> counterRes;
206224

207225
ASSERT_EQ(N, ids.size());
@@ -211,7 +229,19 @@ TEST(CV_ArucoTutorial, can_find_diamondmarkers)
211229
counterRes[arucoId]++;
212230
}
213231

214-
EXPECT_EQ(counterGoldCornersIds, counterRes); // check the number of ArUco markers
232+
ASSERT_EQ(counterGoldCornersIds, counterRes); // check the number of ArUco markers
233+
ASSERT_EQ(goldDiamonds.size(), diamondIds.size()); // check the number of diamonds
234+
235+
for (size_t i = 0; i < goldDiamonds.size(); i++)
236+
{
237+
Vec4i diamondId = diamondIds[i];
238+
ASSERT_TRUE(goldDiamonds.find(diamondId) != goldDiamonds.end());
239+
for (int j = 0; j < 4; j++)
240+
{
241+
EXPECT_NEAR(goldDiamonds[diamondId][j * 2], diamondCorners[i][j].x, 0.5f);
242+
EXPECT_NEAR(goldDiamonds[diamondId][j * 2 + 1], diamondCorners[i][j].y, 0.5f);
243+
}
244+
}
215245
}
216246

217247
}} // namespace

0 commit comments

Comments
 (0)