From 2c2466fb25b2b769368563f60db76042c5aadb59 Mon Sep 17 00:00:00 2001 From: Smirnov Egor Date: Wed, 22 Jun 2022 15:04:46 +0300 Subject: [PATCH] Add symmetric circles board --- apps/interactive-calibration/calibCommon.hpp | 2 +- .../frameProcessor.cpp | 22 +++++++++++++++++++ .../frameProcessor.hpp | 1 + apps/interactive-calibration/main.cpp | 2 +- .../parametersController.cpp | 6 ++++- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/apps/interactive-calibration/calibCommon.hpp b/apps/interactive-calibration/calibCommon.hpp index 617c17dbcf..f94ee4ecf9 100644 --- a/apps/interactive-calibration/calibCommon.hpp +++ b/apps/interactive-calibration/calibCommon.hpp @@ -21,7 +21,7 @@ namespace calib enum InputType { Video, Pictures }; enum InputVideoSource { Camera, File }; - enum TemplateType { AcirclesGrid, Chessboard, chAruco, DoubleAcirclesGrid }; + enum TemplateType { AcirclesGrid, Chessboard, chAruco, DoubleAcirclesGrid, CirclesGrid }; static const std::string mainWindowName = "Calibration"; static const std::string gridWindowName = "Board locations"; diff --git a/apps/interactive-calibration/frameProcessor.cpp b/apps/interactive-calibration/frameProcessor.cpp index 2c2a1cd5aa..85514a9136 100644 --- a/apps/interactive-calibration/frameProcessor.cpp +++ b/apps/interactive-calibration/frameProcessor.cpp @@ -108,6 +108,16 @@ bool CalibProcessor::detectAndParseChAruco(const cv::Mat &frame) return false; } +bool CalibProcessor::detectAndParseCircles(const cv::Mat &frame) +{ + bool isTemplateFound = findCirclesGrid(frame, mBoardSize, mCurrentImagePoints, cv::CALIB_CB_SYMMETRIC_GRID, mBlobDetectorPtr); + if(isTemplateFound) { + mTemplateLocations.insert(mTemplateLocations.begin(), mCurrentImagePoints[0]); + cv::drawChessboardCorners(frame, mBoardSize, cv::Mat(mCurrentImagePoints), isTemplateFound); + } + return isTemplateFound; +} + bool CalibProcessor::detectAndParseACircles(const cv::Mat &frame) { bool isTemplateFound = findCirclesGrid(frame, mBoardSize, mCurrentImagePoints, cv::CALIB_CB_ASYMMETRIC_GRID, mBlobDetectorPtr); @@ -160,6 +170,14 @@ void CalibProcessor::saveFrameData() mCalibData->allCharucoCorners.push_back(mCurrentCharucoCorners); mCalibData->allCharucoIds.push_back(mCurrentCharucoIds); break; + case CirclesGrid: + objectPoints.reserve(mBoardSize.height*mBoardSize.width); + for( int i = 0; i < mBoardSize.height; i++ ) + for( int j = 0; j < mBoardSize.width; j++ ) + objectPoints.push_back(cv::Point3f(j*mSquareSize, i*mSquareSize, 0)); + mCalibData->imagePoints.push_back(mCurrentImagePoints); + mCalibData->objectPoints.push_back(objectPoints); + break; case AcirclesGrid: objectPoints.reserve(mBoardSize.height*mBoardSize.width); for( int i = 0; i < mBoardSize.height; i++ ) @@ -278,6 +296,7 @@ CalibProcessor::CalibProcessor(cv::Ptr data, captureParameters capParams.charucoMarkerSize, mArucoDictionary); #endif break; + case CirclesGrid: case AcirclesGrid: mBlobDetectorPtr = cv::SimpleBlobDetector::create(); break; @@ -308,6 +327,9 @@ cv::Mat CalibProcessor::processFrame(const cv::Mat &frame) case chAruco: isTemplateFound = detectAndParseChAruco(frameCopy); break; + case CirclesGrid: + isTemplateFound = detectAndParseCircles(frameCopy); + break; case AcirclesGrid: isTemplateFound = detectAndParseACircles(frameCopy); break; diff --git a/apps/interactive-calibration/frameProcessor.hpp b/apps/interactive-calibration/frameProcessor.hpp index 88e87f7b98..b5418cdecf 100644 --- a/apps/interactive-calibration/frameProcessor.hpp +++ b/apps/interactive-calibration/frameProcessor.hpp @@ -54,6 +54,7 @@ protected: bool detectAndParseChessboard(const cv::Mat& frame); bool detectAndParseChAruco(const cv::Mat& frame); + bool detectAndParseCircles(const cv::Mat& frame); bool detectAndParseACircles(const cv::Mat& frame); bool detectAndParseDualACircles(const cv::Mat& frame); void saveFrameData(); diff --git a/apps/interactive-calibration/main.cpp b/apps/interactive-calibration/main.cpp index b5c3642bb6..27e8467d1f 100644 --- a/apps/interactive-calibration/main.cpp +++ b/apps/interactive-calibration/main.cpp @@ -30,7 +30,7 @@ const std::string keys = "{v | | Input from video file }" "{ci | 0 | Default camera id }" "{flip | false | Vertical flip of input frames }" - "{t | circles | Template for calibration (circles, chessboard, dualCircles, charuco) }" + "{t | circles | Template for calibration (circles, chessboard, dualCircles, charuco, symcircles) }" "{sz | 16.3 | Distance between two nearest centers of circles or squares on calibration board}" "{dst | 295 | Distance between white and black parts of daulCircles template}" "{w | | Width of template (in corners or circles)}" diff --git a/apps/interactive-calibration/parametersController.cpp b/apps/interactive-calibration/parametersController.cpp index 5659b0e469..6124831465 100644 --- a/apps/interactive-calibration/parametersController.cpp +++ b/apps/interactive-calibration/parametersController.cpp @@ -107,7 +107,11 @@ bool calib::parametersController::loadFromParser(cv::CommandLineParser &parser) std::string templateType = parser.get("t"); - if(templateType.find("circles", 0) == 0) { + if(templateType.find("symcircles", 0) == 0) { + mCapParams.board = CirclesGrid; + mCapParams.boardSize = cv::Size(4, 11); + } + else if(templateType.find("circles", 0) == 0) { mCapParams.board = AcirclesGrid; mCapParams.boardSize = cv::Size(4, 11); }