python opencv - blob detection or circle detection

后端 未结 2 1525
半阙折子戏
半阙折子戏 2020-12-24 03:02

I am having problems detecting circle areas. I tried it with the HoughCircles function from opencv. However even though the images are pretty similar the parameters for the

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 03:09

    As a starting point you may start with:

    • Find all the contours in the given image using cv2.findContours()
    • Iterate over each contour:
      • calculate the area, if the area of contour is in a given range say 70 < area < 150. This will filter out some extremely smaller and large contours.
      • After filtering the contours with the area threshold, you need to check the number of edges of contour, which can be done using: cv2.approxPolyDP(), for a circle len(approx) must be > 8 but < 23. Or you may apply some more sophisticated operations to detect circles here.

    You should try to implement this approach and update the question with the code that you will write henceforth.

    EDIT: As suggested by @Miki, there is a better and cleaner way of detecting if a geometrical shape is of circular shape using circularity = 4pi(area/perimeter^2), and decide a threshold such as 0.9, to check if the shape is circular. For perfect circle circularity == 1. You may fine tune this threshold as per your needs.

    You may consult arcLength to find the perimeter of the contour and contourArea to get the area of the contour which are required to calculate the circularity.

提交回复
热议问题