Skip to content

Commit 02b991a

Browse files
gmedanalalek
authored andcommitted
Merge pull request #1677 from gmedan:fix-charuco-topology
* fix #1665 ChAruco board topology (nearestMarkerIdx) is sensitive to scale
1 parent 2bd8d58 commit 02b991a

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

modules/aruco/src/charuco.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void CharucoBoard::_getNearestMarkerCorners() {
194194
double sqDistance;
195195
Point3f distVector = charucoCorner - center;
196196
sqDistance = distVector.x * distVector.x + distVector.y * distVector.y;
197-
if(j == 0 || fabs(sqDistance - minDist) < 0.0001) {
197+
if(j == 0 || fabs(sqDistance - minDist) < cv::pow(0.01 * _squareLength, 2)) {
198198
// if same minimum distance (or first iteration), add to nearestMarkerIdx vector
199199
nearestMarkerIdx[i].push_back(j);
200200
minDist = sqDistance;

modules/aruco/test/test_charucodetection.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,15 +538,55 @@ void CV_CharucoDiamondDetection::run(int) {
538538
}
539539
}
540540

541+
/**
542+
* @brief Check charuco board creation
543+
*/
544+
class CV_CharucoBoardCreation : public cvtest::BaseTest {
545+
public:
546+
CV_CharucoBoardCreation();
541547

548+
protected:
549+
void run(int);
550+
};
551+
552+
CV_CharucoBoardCreation::CV_CharucoBoardCreation() {}
553+
554+
void CV_CharucoBoardCreation::run(int)
555+
{
556+
Ptr<aruco::Dictionary> dictionary = aruco::getPredefinedDictionary(aruco::DICT_5X5_250);
557+
int n = 6;
558+
559+
float markerSizeFactor = 0.5f;
560+
561+
for (float squareSize_mm = 5.0f; squareSize_mm < 35.0f; squareSize_mm += 0.1f)
562+
{
563+
Ptr<aruco::CharucoBoard> board_meters = aruco::CharucoBoard::create(
564+
n, n, squareSize_mm*1e-3f, squareSize_mm * markerSizeFactor * 1e-3f, dictionary);
565+
566+
Ptr<aruco::CharucoBoard> board_millimeters = aruco::CharucoBoard::create(
567+
n, n, squareSize_mm, squareSize_mm * markerSizeFactor, dictionary);
568+
569+
for (size_t i = 0; i < board_meters->nearestMarkerIdx.size(); i++)
570+
{
571+
if (board_meters->nearestMarkerIdx[i].size() != board_millimeters->nearestMarkerIdx[i].size() ||
572+
board_meters->nearestMarkerIdx[i][0] != board_millimeters->nearestMarkerIdx[i][0])
573+
{
574+
ts->printf(cvtest::TS::LOG,
575+
cv::format("Charuco board topology is sensitive to scale with squareSize=%.1f\n",
576+
squareSize_mm).c_str());
577+
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
578+
break;
579+
}
580+
}
581+
}
582+
}
542583

543584

544585
TEST(CV_CharucoDetection, accuracy) {
545586
CV_CharucoDetection test;
546587
test.safe_run();
547588
}
548589

549-
550590
TEST(CV_CharucoPoseEstimation, accuracy) {
551591
CV_CharucoPoseEstimation test;
552592
test.safe_run();
@@ -557,4 +597,9 @@ TEST(CV_CharucoDiamondDetection, accuracy) {
557597
test.safe_run();
558598
}
559599

600+
TEST(CV_CharucoBoardCreation, accuracy) {
601+
CV_CharucoBoardCreation test;
602+
test.safe_run();
603+
}
604+
560605
}} // namespace

0 commit comments

Comments
 (0)