Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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: C:\fakepath\Screen Shot 2014-10-02 at 23.52.34.png

The full code can be found at: this gist

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: C:\fakepath\Screen Shot 2014-10-02 at 23.52.34.pngScreen Shot

The full code can be found at: this gist