Robustly find N circles with the same diameter: alternative to bruteforcing Hough transform threshold

前端 未结 3 1228
再見小時候
再見小時候 2021-02-07 08:31

I am developing application to track small animals in Petri dishes (or other circular containers). Before any tracking takes place, the first few frames are used to define areas

3条回答
  •  情话喂你
    2021-02-07 09:23

    The following approach should work pretty well for your case:

    1. Binarize your image (you might need to do this on several levels of threshold to make algorithm independent of the lighting conditions)
    2. Find contours
    3. For each contour calculate the moments
    4. Filter them by area to remove too small contours
    5. Filter contours by circularity:

      double area = moms.m00;
      double perimeter = arcLength(Mat(contours[contourIdx]), true);
      double ratio = 4 * CV_PI * area / (perimeter * perimeter);
      

      ratio close to 1 will give you circles.

    6. Calculate radius and center of each circle

      center = Point2d(moms.m10 / moms.m00, moms.m01 / moms.m00);
      

    And you can add more filters to improve the robustness.

    Actually you can find an implementation of the whole procedure in OpenCV. Look how the SimpleBlobDetector class and findCirclesGrid function are implemented.

提交回复
热议问题