Automatic calculation of low and high thresholds for the Canny operation in opencv

后端 未结 7 911
孤独总比滥情好
孤独总比滥情好 2020-11-28 03:15

In openCV, the low and high thresholds for the canny operator are mandatory:

cvCanny(input,output,thresh1,thresh2)

In Matlab, there\'s an o

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 03:19

    Check out this link: http://www.pyimagesearch.com/2015/04/06/zero-parameter-automatic-canny-edge-detection-with-python-and-opencv/

    They implement a similar solution using basic statistics to determine the low and high threshold for Canny edge detection.

    def auto_canny(image, sigma=0.33):
         # compute the median of the single channel pixel intensities
         v = np.median(image)
    
        # apply automatic Canny edge detection using the computed median
        lower = int(max(0, (1.0 - sigma) * v))
        upper = int(min(255, (1.0 + sigma) * v))
        edged = cv2.Canny(image, lower, upper)
    
        # return the edged image
        return edged
    

提交回复
热议问题