Ask Your Question
1

findCirclesGrid throws Exception

asked 2019-07-09 04:00:16 -0600

llena gravatar image

updated 2019-07-09 04:47:39 -0600

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:

  1. how did it work and not trigger exceptions before?

  2. why does it not work now?

  3. 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.

edit retag flag offensive close merge delete

Comments

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

CirclesGridFinder boxFinder(patternSize, points, parameters);

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?

llena gravatar imagellena ( 2019-07-09 05:27:38 -0600 )edit

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!

llena gravatar imagellena ( 2019-07-09 05:41:02 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-07-11 07:23:17 -0600

llena gravatar image

updated 2019-07-11 07:23:48 -0600

Mystery resolved: opencv throws and catches an exception internally. Enabling the flag <All C++ Exceptions not in this list> (in "C++ Exceptions" in Visual Studio 2019) makes VS catch it even though it's within try-catch block. I don't know if it's by design, but changing that flag (it is disabled by default) seems to be cause and the solution of the problem.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-07-09 04:00:16 -0600

Seen: 916 times

Last updated: Jul 11 '19