ellipse detection in opencv python

后端 未结 2 2088
感动是毒
感动是毒 2021-01-07 00:51

My image is here:

\"my

i\'m looking for a better solution or algorithm to detect the

2条回答
  •  不要未来只要你来
    2021-01-07 01:28

    APPROACH 1:

    As suggested by Miki, I was able to detect the ellipse in the given image using contour properties (in this I used the area property).

    CODE:

    #--- First obtain the threshold using the greyscale image ---
    ret,th = cv2.threshold(gray,127,255, 0)
    
    #--- Find all the contours in the binary image ---
    _, contours,hierarchy = cv2.findContours(th,2,1)
    cnt = contours
    big_contour = []
    max = 0
    for i in cnt:
       area = cv2.contourArea(i) #--- find the contour having biggest area ---
        if(area > max):
            max = area
            big_contour = i 
    
    final = cv2.drawContours(img, big_contour, -1, (0,255,0), 3)
    cv2.imshow('final', final)
    

    This is what I obtained:

    APPROACH 2:

    You can also use the approach suggested by you in this case. Hough detection of ellipse/circle.

    You have to pre-process the image. I performed adaptive threshold and obtained this:

    Now you can perform Hough circle detection on this image.

    Hope it is not a mouthful!! :D

提交回复
热议问题