Ask Your Question
0

findCirclesGrid - no working example

asked 2014-10-02 04:29:09 -0600

elliotwoods gravatar image

updated 2014-10-02 05:57:04 -0600

Hi all

I can find a lot of examples of code + images for findCircles grid which does NOT work (according to the authors). Also I can find claims that findCirclesGrid works great for them. But I can't find a code example which is known to work against an image which can be downloaded to test with.

Essentially the example should comprise:

Hoping to post one here soon.. :)

[EDIT] I'm not allowed to answer my own question because i'm a new user, but I managed to get the image and code from: http://answers.opencv.org/question/3136/findcirclesgrid-in-python/ working in a cpp example [/EDIT]

edit retag flag offensive close merge delete

Comments

I added 50 karma so you can now answer your own question. As to the solution, please consider a pull request with this new sample on github. It will help all future users of this functionality.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-02 06:30:32 -0600 )edit
1

Thank you Steven

I didn't use highgui for my tests, as I'm working inside openFrameworks, so it doesn't make for a good sample for others to compile. I'll post my findings below.

elliotwoods gravatar imageelliotwoods ( 2014-10-02 09:42:43 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-10-02 09:55:09 -0600

elliotwoods gravatar image

updated 2014-10-02 09:56:04 -0600

Some findings:

  • Size must be odd in both dimensions (this makes sense when you consider how the found circles are ordered)
  • Using an adaptive threshold (with a blockSize ~3x the circle size works well for me)
  • The Size is supposed to be number of items per row, then number of rows (not the other way around as some suggest)
  • For assymetric circles, each row is a straight line of circles

Here's my code.... (i'm running inside openFrameworks, hence image.getPixelsRef():

Mat cvImage;
cvtColor(toCv(this->image.getPixelsRef()), cvImage, CV_RGB2GRAY);

int blockSize = sqrt(this->paramMaxArea) * 3.0f;
blockSize = (blockSize / 2) * 2 + 1;
if (blockSize <= 1) {
    blockSize = 3;
}

adaptiveThreshold(cvImage, cvImage, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, blockSize, 2);

imitate(this->thresholdedImage, cvImage);
memcpy(this->thresholdedImage.getPixels(), cvImage.data, this->thresholdedImage.getPixelsRef().size());
this->thresholdedImage.update();

SimpleBlobDetector::Params params;
params.maxArea = paramMaxArea; // 100 * 100
params.minArea = paramMinArea; // 10 * 10
Ptr<FeatureDetector> blobDetector = new SimpleBlobDetector(params);

auto success = findCirclesGrid(cvImage, cv::Size(5, 7), this->centers, CALIB_CB_ASYMMETRIC_GRID | CALIB_CB_CLUSTERING, blobDetector);
cout << (success ? "success" : "fail") << endl;

Here's the image i'm testing with: http://www.kimchiandchips.com/files/opencv/5x7.JPG (i can't attach directly here since it's larger than 1MB)

And here's a screenshot of the app running: Screen Shot

The full code can be found at: this gist

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-10-02 04:29:09 -0600

Seen: 5,846 times

Last updated: Oct 02 '14