From 629a06d9b673745c9d17bb006fc673d5cfc525b0 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Fri, 8 Sep 2017 16:35:23 +0200 Subject: [PATCH] calib3d: export parameters of CALIB_CB_CLUSTERING --- modules/calib3d/include/opencv2/calib3d.hpp | 14 +++++++++++ modules/calib3d/misc/java/gen_dict.json | 3 ++- modules/calib3d/src/calibinit.cpp | 28 ++++++++++++++------- modules/calib3d/src/circlesgrid.cpp | 7 ++++++ modules/calib3d/src/circlesgrid.hpp | 8 +++--- 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/modules/calib3d/include/opencv2/calib3d.hpp b/modules/calib3d/include/opencv2/calib3d.hpp index 343ca95792..e3783c035a 100644 --- a/modules/calib3d/include/opencv2/calib3d.hpp +++ b/modules/calib3d/include/opencv2/calib3d.hpp @@ -783,6 +783,14 @@ struct CV_EXPORTS_W_SIMPLE CirclesGridFinderParameters GridType gridType; }; +struct CV_EXPORTS_W_SIMPLE CirclesGridFinderParameters2 : public CirclesGridFinderParameters +{ + CV_WRAP CirclesGridFinderParameters2(); + + CV_PROP_RW float squareSize; //!< Distance between two adjacent points. Used by CALIB_CB_CLUSTERING. + CV_PROP_RW float maxRectifiedDistance; //!< Max deviation from predicion. Used by CALIB_CB_CLUSTERING. +}; + /** @brief Finds centers in the grid of circles. @param image grid view of input circles; it must be an 8-bit grayscale or color image. @@ -820,6 +828,12 @@ CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize, const Ptr &blobDetector, CirclesGridFinderParameters parameters); +/** @overload */ +CV_EXPORTS_W bool findCirclesGrid2( InputArray image, Size patternSize, + OutputArray centers, int flags, + const Ptr &blobDetector, + CirclesGridFinderParameters2 parameters); + /** @overload */ CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize, OutputArray centers, int flags = CALIB_CB_SYMMETRIC_GRID, diff --git a/modules/calib3d/misc/java/gen_dict.json b/modules/calib3d/misc/java/gen_dict.json index 0e3519608b..4c2d9d2f86 100644 --- a/modules/calib3d/misc/java/gen_dict.json +++ b/modules/calib3d/misc/java/gen_dict.json @@ -1,6 +1,7 @@ { "class_ignore_list": [ - "CirclesGridFinderParameters" + "CirclesGridFinderParameters", + "CirclesGridFinderParameters2" ], "missing_consts" : { "Calib3d": { diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index c93415c326..ad08f3ed6d 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -2094,9 +2094,19 @@ void cv::drawChessboardCorners( InputOutputArray _image, Size patternSize, nelems, patternWasFound ); } -bool cv::findCirclesGrid( InputArray _image, Size patternSize, +bool cv::findCirclesGrid( InputArray image, Size patternSize, + OutputArray centers, int flags, + const Ptr &blobDetector, + CirclesGridFinderParameters parameters) +{ + CirclesGridFinderParameters2 parameters2; + *((CirclesGridFinderParameters*)¶meters2) = parameters; + return cv::findCirclesGrid2(image, patternSize, centers, flags, blobDetector, parameters2); +} + +bool cv::findCirclesGrid2( InputArray _image, Size patternSize, OutputArray _centers, int flags, const Ptr &blobDetector, - CirclesGridFinderParameters parameters) + CirclesGridFinderParameters2 parameters) { CV_INSTRUMENT_REGION() @@ -2115,19 +2125,19 @@ bool cv::findCirclesGrid( InputArray _image, Size patternSize, points.push_back (keypoints[i].pt); } + if(flags & CALIB_CB_ASYMMETRIC_GRID) + parameters.gridType = CirclesGridFinderParameters::ASYMMETRIC_GRID; + if(flags & CALIB_CB_SYMMETRIC_GRID) + parameters.gridType = CirclesGridFinderParameters::SYMMETRIC_GRID; + if(flags & CALIB_CB_CLUSTERING) { - CirclesGridClusterFinder circlesGridClusterFinder(isAsymmetricGrid); + CirclesGridClusterFinder circlesGridClusterFinder(parameters); circlesGridClusterFinder.findGrid(points, patternSize, centers); Mat(centers).copyTo(_centers); return !centers.empty(); } - if(flags & CALIB_CB_ASYMMETRIC_GRID) - parameters.gridType = CirclesGridFinderParameters::ASYMMETRIC_GRID; - if(flags & CALIB_CB_SYMMETRIC_GRID) - parameters.gridType = CirclesGridFinderParameters::SYMMETRIC_GRID; - const int attempts = 2; const size_t minHomographyPoints = 4; Mat H; @@ -2191,7 +2201,7 @@ bool cv::findCirclesGrid( InputArray _image, Size patternSize, bool cv::findCirclesGrid( InputArray _image, Size patternSize, OutputArray _centers, int flags, const Ptr &blobDetector) { - return cv::findCirclesGrid(_image, patternSize, _centers, flags, blobDetector, CirclesGridFinderParameters()); + return cv::findCirclesGrid2(_image, patternSize, _centers, flags, blobDetector, CirclesGridFinderParameters2()); } /* End of file. */ diff --git a/modules/calib3d/src/circlesgrid.cpp b/modules/calib3d/src/circlesgrid.cpp index 4cf0779bbe..b55101a4b4 100644 --- a/modules/calib3d/src/circlesgrid.cpp +++ b/modules/calib3d/src/circlesgrid.cpp @@ -559,6 +559,13 @@ CirclesGridFinderParameters::CirclesGridFinderParameters() gridType = SYMMETRIC_GRID; } +CirclesGridFinderParameters2::CirclesGridFinderParameters2() +: CirclesGridFinderParameters() +{ + squareSize = 1.0f; + maxRectifiedDistance = squareSize/2.0f; +} + CirclesGridFinder::CirclesGridFinder(Size _patternSize, const std::vector &testKeypoints, const CirclesGridFinderParameters &_parameters) : patternSize(static_cast (_patternSize.width), static_cast (_patternSize.height)) diff --git a/modules/calib3d/src/circlesgrid.hpp b/modules/calib3d/src/circlesgrid.hpp index 8f55f6c5ef..ad0f916eed 100644 --- a/modules/calib3d/src/circlesgrid.hpp +++ b/modules/calib3d/src/circlesgrid.hpp @@ -56,11 +56,11 @@ class CirclesGridClusterFinder CirclesGridClusterFinder& operator=(const CirclesGridClusterFinder&); CirclesGridClusterFinder(const CirclesGridClusterFinder&); public: - CirclesGridClusterFinder(bool _isAsymmetricGrid) + CirclesGridClusterFinder(const cv::CirclesGridFinderParameters2 ¶meters) { - isAsymmetricGrid = _isAsymmetricGrid; - squareSize = 1.0f; - maxRectifiedDistance = (float)(squareSize / 2.0); + isAsymmetricGrid = parameters.gridType == cv::CirclesGridFinderParameters::ASYMMETRIC_GRID; + squareSize = parameters.squareSize; + maxRectifiedDistance = parameters.maxRectifiedDistance; } void findGrid(const std::vector &points, cv::Size patternSize, std::vector& centers);