How can I get the minimum enclosing circle with OPENCV?

前端 未结 1 976
别那么骄傲
别那么骄傲 2021-01-24 06:07

I\'m using cv::minEnclosingCircle(...) in order to get the minimum circle that exactly evolves my contour, but I\'m getting a circle a little big bigger.

In

相关标签:
1条回答
  • 2021-01-24 07:05

    My result is OK.


    1. for only one region

    ## only one region
    cnts = cv2.findContours(threshed, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2]
    
    (x,y), r = cv2.minEnclosingCircle(cnts[0])
    


    2. for more than one region

    ## more than one region
    mask = threshed.copy()
    
    ## find centers 
    for cnt in cnts:
        (x,y), r = cv2.minEnclosingCircle(cnt)
        pt = (int(x), int(y))
        centers.append(pt)
    
    ## connect the `centers`
    for i in range(1, len(centers)):
        cv2.line(mask, centers[i-1], centers[i], 255, 2)
    
    ## find the center 
    cnts = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2]
    (x,y), r = cv2.minEnclosingCircle(cnts[0])
    

    0 讨论(0)
提交回复
热议问题