Skip to content

Commit

Permalink
add axes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrPanov committed Mar 3, 2022
1 parent c8936ad commit 63204ac
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
22 changes: 22 additions & 0 deletions modules/aruco/test/test_aruco_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@
namespace opencv_test {
namespace {

static inline vector<Point2f> getAxis(InputArray _cameraMatrix, InputArray _distCoeffs,
InputArray _rvec, InputArray _tvec, float length,
const float offset = 0.f)
{
vector<Point3f> axis;
axis.push_back(Point3f(offset, offset, 0.f));
axis.push_back(Point3f(length+offset, offset, 0.f));
axis.push_back(Point3f(offset, length+offset, 0.f));
axis.push_back(Point3f(offset, offset, -length));
vector<Point2f> axis_to_img;
projectPoints(axis, _rvec, _tvec, _cameraMatrix, _distCoeffs, axis_to_img);
return axis_to_img;
}

static inline vector<Point2f> getMarkerById(int id, const vector<vector<Point2f> >& corners, const vector<int>& ids)
{
for (size_t i = 0ull; i < ids.size(); i++)
if (ids[i] == id)
return corners[i];
return vector<Point2f>();
}

static inline double deg2rad(double deg) { return deg * CV_PI / 180.; }

/**
Expand Down
26 changes: 17 additions & 9 deletions modules/aruco/test/test_boarddetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ void CV_ArucoBoardPose::run(int) {
Mat distCoeffs(5, 1, CV_64FC1, Scalar::all(0));

// for different perspectives
for(double distance = 0.2; distance <= 0.4; distance += 0.2) {
for(int yaw = -60; yaw <= 60; yaw += 30) {
for(int pitch = -60; pitch <= 60; pitch += 30) {
for(double distance = 0.2; distance <= 0.4; distance += 0.15) {
for(int yaw = -55; yaw <= 50; yaw += 25) {
for(int pitch = -55; pitch <= 50; pitch += 25) {
for(unsigned int i = 0; i < gridboard->ids.size(); i++)
gridboard->ids[i] = (iter + int(i)) % 250;
int markerBorder = iter % 2 + 1;
Expand All @@ -87,17 +87,25 @@ void CV_ArucoBoardPose::run(int) {
params->markerBorderBits = markerBorder;
aruco::detectMarkers(img, dictionary, corners, ids, params);

if(ids.size() == 0) {
ts->printf(cvtest::TS::LOG, "Marker detection failed in Board test");
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
return;
}
ASSERT_EQ(ids.size(), gridboard->ids.size());

// estimate pose
Mat rvec, tvec;
aruco::estimatePoseBoard(corners, ids, board, cameraMatrix, distCoeffs, rvec, tvec);

// check result
// check axes
vector<Point2f> axes = getAxis(cameraMatrix, distCoeffs, rvec, tvec, gridboard->rightBottomBorder.x);
vector<Point2f> topLeft = getMarkerById(gridboard->ids[0], corners, ids);
ASSERT_NEAR(topLeft[0].x, axes[0].x, 2.f);
ASSERT_NEAR(topLeft[0].y, axes[0].y, 2.f);
vector<Point2f> topRight = getMarkerById(gridboard->ids[2], corners, ids);
ASSERT_NEAR(topRight[1].x, axes[1].x, 2.f);
ASSERT_NEAR(topRight[1].y, axes[1].y, 2.f);
vector<Point2f> bottomLeft = getMarkerById(gridboard->ids[6], corners, ids);
ASSERT_NEAR(bottomLeft[3].x, axes[2].x, 2.f);
ASSERT_NEAR(bottomLeft[3].y, axes[2].y, 2.f);

// check estimate result
for(unsigned int i = 0; i < ids.size(); i++) {
int foundIdx = -1;
for(unsigned int j = 0; j < gridboard->ids.size(); j++) {
Expand Down
18 changes: 12 additions & 6 deletions modules/aruco/test/test_charucodetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,7 @@ void CV_CharucoPoseEstimation::run(int) {
params->markerBorderBits = markerBorder;
aruco::detectMarkers(img, dictionary, corners, ids, params);

if(ids.size() == 0) {
ts->printf(cvtest::TS::LOG, "Marker detection failed");
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
return;
}
ASSERT_EQ(ids.size(), board->ids.size());

// interpolate charuco corners
vector< Point2f > charucoCorners;
Expand All @@ -291,7 +287,17 @@ void CV_CharucoPoseEstimation::run(int) {
distCoeffs, rvec, tvec);


// check result
// check axes
const float offset = (board->getSquareLength() - board->getMarkerLength()) / 2.f;
vector<Point2f> axes = getAxis(cameraMatrix, distCoeffs, rvec, tvec, board->getSquareLength(), offset);
vector<Point2f> topLeft = getMarkerById(board->ids[0], corners, ids);
ASSERT_NEAR(topLeft[0].x, axes[1].x, 3.f);
ASSERT_NEAR(topLeft[0].y, axes[1].y, 3.f);
vector<Point2f> bottomLeft = getMarkerById(board->ids[2], corners, ids);
ASSERT_NEAR(bottomLeft[0].x, axes[2].x, 3.f);
ASSERT_NEAR(bottomLeft[0].y, axes[2].y, 3.f);

// check estimate result
vector< Point2f > projectedCharucoCorners;

projectPoints(board->chessboardCorners, rvec, tvec, cameraMatrix, distCoeffs,
Expand Down

0 comments on commit 63204ac

Please sign in to comment.