Skip to content

Commit 11b24eb

Browse files
author
Hans Gaiser
committed
Expose CirclesGridFinderParameters in findCirclesGrid.
1 parent f46fa6e commit 11b24eb

File tree

6 files changed

+62
-39
lines changed

6 files changed

+62
-39
lines changed

modules/calib3d/include/opencv2/calib3d.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,30 @@ found, or as colored corners connected with lines if the board was found.
714714
CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSize,
715715
InputArray corners, bool patternWasFound );
716716

717+
struct CV_EXPORTS_W_SIMPLE CirclesGridFinderParameters
718+
{
719+
CV_WRAP CirclesGridFinderParameters();
720+
CV_PROP_RW cv::Size2f densityNeighborhoodSize;
721+
CV_PROP_RW float minDensity;
722+
CV_PROP_RW int kmeansAttempts;
723+
CV_PROP_RW int minDistanceToAddKeypoint;
724+
CV_PROP_RW int keypointScale;
725+
CV_PROP_RW float minGraphConfidence;
726+
CV_PROP_RW float vertexGain;
727+
CV_PROP_RW float vertexPenalty;
728+
CV_PROP_RW float existingVertexGain;
729+
CV_PROP_RW float edgeGain;
730+
CV_PROP_RW float edgePenalty;
731+
CV_PROP_RW float convexHullFactor;
732+
CV_PROP_RW float minRNGEdgeSwitchDist;
733+
734+
enum GridType
735+
{
736+
SYMMETRIC_GRID, ASYMMETRIC_GRID
737+
};
738+
GridType gridType;
739+
};
740+
717741
/** @brief Finds centers in the grid of circles.
718742
719743
@param image grid view of input circles; it must be an 8-bit grayscale or color image.
@@ -726,6 +750,7 @@ CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSiz
726750
- **CALIB_CB_CLUSTERING** uses a special algorithm for grid detection. It is more robust to
727751
perspective distortions but much more sensitive to background clutter.
728752
@param blobDetector feature detector that finds blobs like dark circles on light background.
753+
@param parameters struct for finding circles in a grid pattern.
729754
730755
The function attempts to determine whether the input image contains a grid of circles. If it is, the
731756
function locates centers of the circles. The function returns a non-zero value if all of the centers
@@ -745,6 +770,12 @@ Sample usage of detecting and drawing the centers of circles: :
745770
@note The function requires white space (like a square-thick border, the wider the better) around
746771
the board to make the detection more robust in various environments.
747772
*/
773+
CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize,
774+
OutputArray centers, int flags,
775+
const Ptr<FeatureDetector> &blobDetector,
776+
CirclesGridFinderParameters parameters);
777+
778+
/** @overload */
748779
CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize,
749780
OutputArray centers, int flags = CALIB_CB_SYMMETRIC_GRID,
750781
const Ptr<FeatureDetector> &blobDetector = SimpleBlobDetector::create());

modules/calib3d/src/calibinit.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,7 +2093,8 @@ void cv::drawChessboardCorners( InputOutputArray _image, Size patternSize,
20932093
}
20942094

20952095
bool cv::findCirclesGrid( InputArray _image, Size patternSize,
2096-
OutputArray _centers, int flags, const Ptr<FeatureDetector> &blobDetector )
2096+
OutputArray _centers, int flags, const Ptr<FeatureDetector> &blobDetector,
2097+
CirclesGridFinderParameters parameters)
20972098
{
20982099
CV_INSTRUMENT_REGION()
20992100

@@ -2120,13 +2121,6 @@ bool cv::findCirclesGrid( InputArray _image, Size patternSize,
21202121
return !centers.empty();
21212122
}
21222123

2123-
CirclesGridFinderParameters parameters;
2124-
parameters.vertexPenalty = -0.6f;
2125-
parameters.vertexGain = 1;
2126-
parameters.existingVertexGain = 10000;
2127-
parameters.edgeGain = 1;
2128-
parameters.edgePenalty = -0.6f;
2129-
21302124
if(flags & CALIB_CB_ASYMMETRIC_GRID)
21312125
parameters.gridType = CirclesGridFinderParameters::ASYMMETRIC_GRID;
21322126
if(flags & CALIB_CB_SYMMETRIC_GRID)
@@ -2192,4 +2186,10 @@ bool cv::findCirclesGrid( InputArray _image, Size patternSize,
21922186
return false;
21932187
}
21942188

2189+
bool cv::findCirclesGrid( InputArray _image, Size patternSize,
2190+
OutputArray _centers, int flags, const Ptr<FeatureDetector> &blobDetector)
2191+
{
2192+
return cv::findCirclesGrid(_image, patternSize, _centers, flags, blobDetector, CirclesGridFinderParameters());
2193+
}
2194+
21952195
/* End of file. */

modules/calib3d/src/circlesgrid.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,11 @@ CirclesGridFinderParameters::CirclesGridFinderParameters()
551551
keypointScale = 1;
552552

553553
minGraphConfidence = 9;
554-
vertexGain = 2;
555-
vertexPenalty = -5;
554+
vertexGain = 1;
555+
vertexPenalty = -0.6f;
556556
edgeGain = 1;
557-
edgePenalty = -5;
558-
existingVertexGain = 0;
557+
edgePenalty = -0.6f;
558+
existingVertexGain = 10000;
559559

560560
minRNGEdgeSwitchDist = 5.f;
561561
gridType = SYMMETRIC_GRID;

modules/calib3d/src/circlesgrid.hpp

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -119,35 +119,11 @@ struct Path
119119
}
120120
};
121121

122-
struct CirclesGridFinderParameters
123-
{
124-
CirclesGridFinderParameters();
125-
cv::Size2f densityNeighborhoodSize;
126-
float minDensity;
127-
int kmeansAttempts;
128-
int minDistanceToAddKeypoint;
129-
int keypointScale;
130-
float minGraphConfidence;
131-
float vertexGain;
132-
float vertexPenalty;
133-
float existingVertexGain;
134-
float edgeGain;
135-
float edgePenalty;
136-
float convexHullFactor;
137-
float minRNGEdgeSwitchDist;
138-
139-
enum GridType
140-
{
141-
SYMMETRIC_GRID, ASYMMETRIC_GRID
142-
};
143-
GridType gridType;
144-
};
145-
146122
class CirclesGridFinder
147123
{
148124
public:
149125
CirclesGridFinder(cv::Size patternSize, const std::vector<cv::Point2f> &testKeypoints,
150-
const CirclesGridFinderParameters &parameters = CirclesGridFinderParameters());
126+
const cv::CirclesGridFinderParameters &parameters = cv::CirclesGridFinderParameters());
151127
bool findHoles();
152128
static cv::Mat rectifyGrid(cv::Size detectedGridSize, const std::vector<cv::Point2f>& centers, const std::vector<
153129
cv::Point2f> &keypoint, std::vector<cv::Point2f> &warpedKeypoints);
@@ -211,7 +187,7 @@ class CirclesGridFinder
211187
std::vector<std::vector<size_t> > *smallHoles;
212188

213189
const cv::Size_<size_t> patternSize;
214-
CirclesGridFinderParameters parameters;
190+
cv::CirclesGridFinderParameters parameters;
215191

216192
CirclesGridFinder& operator=(const CirclesGridFinder&);
217193
CirclesGridFinder(const CirclesGridFinder&);

modules/java/generator/gen_java.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
#core
1515
"FileNode", "FileStorage", "KDTree", "KeyPoint", "DMatch",
1616
#features2d
17-
"SimpleBlobDetector"
17+
"SimpleBlobDetector",
18+
"CirclesGridFinderParameters"
1819
)
1920

2021
const_ignore_list = (

modules/python/src2/cv2.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,21 @@ PyObject* pyopencv_from(const Size& sz)
798798
return Py_BuildValue("(ii)", sz.width, sz.height);
799799
}
800800

801+
template<>
802+
bool pyopencv_to(PyObject* obj, Size_<float>& sz, const char* name)
803+
{
804+
(void)name;
805+
if(!obj || obj == Py_None)
806+
return true;
807+
return PyArg_ParseTuple(obj, "ff", &sz.width, &sz.height) > 0;
808+
}
809+
810+
template<>
811+
PyObject* pyopencv_from(const Size_<float>& sz)
812+
{
813+
return Py_BuildValue("(ff)", sz.width, sz.height);
814+
}
815+
801816
template<>
802817
bool pyopencv_to(PyObject* obj, Rect& r, const char* name)
803818
{

0 commit comments

Comments
 (0)