findCirclesGrid throws Exception
Here is a small code snippet that tries to search for a circles grid on a black image. I expect it to find nothing, return false and finish.
const cv::Size patternsize(6, 5);
std::vector<cv::Point2f> centers;
cv::Mat debug(100, 100, CV_8U, cv::Scalar(0));
bool detectedCircles = cv::findCirclesGrid(debug, patternsize, centers, cv::CALIB_CB_SYMMETRIC_GRID);
Instead, it triggers a cv::Exception
.
Tracing it back we find that it is thrown from a function filterOutliersByDensity
:
void CirclesGridFinder::filterOutliersByDensity(const std::vector<Point2f> &samples, std::vector<Point2f> &filteredSamples)
{
if (samples.empty())
CV_Error( 0, "samples is empty" );
which is to be expected asfilterOutliersByDensity
is called like so, with an empty freshly created vectors
vector as a first parameter:
bool CirclesGridFinder::findHoles()
{
switch (parameters.gridType)
{
case CirclesGridFinderParameters::SYMMETRIC_GRID:
{
std::vector<Point2f> vectors, filteredVectors, basis;
Graph rng(0);
computeRNG(rng, vectors);
filterOutliersByDensity(vectors, filteredVectors);
I'm running opencv 4.1.0 All related opencv functions were last changed >5 years ago. This problem arouse when I've tried to run some code that worked 2 weeks ago and that I have not touched since.
Actual questions:
how did it work and not trigger exceptions before?
why does it not work now?
how should i detect circles in an image then?
P.S.: it's my first post here and I'm very, very confused, but I hope my question is still clear. I'm happy to provide more/less detail.
ok, so 'computeRNG(rng, vectors)' is supposed to fill the vectors array, but it doesn't because it's member 'keypoints' is emply.
I've found that it happens exactly when there are no points in the image, thus 'findCirclesGrid' finds none and
is called with an empty 'points' vector (link to that line in the source code)
'CirclesGridFinder' constructor, in it's turn, initializes the member 'keypoints' with that empty array.
Is it a bug? Should I report it?
this whole function 'filterOutliersByDensity' puzzles me, it throws an error if called to filter an empty array, and if it has not filter anything. source
I can understand that first might be by design, but I can't find a reason to justify the second!