How can I select the best set of parameters in the Canny edge detection algorithm implemented in OpenCV?

后端 未结 2 1188
独厮守ぢ
独厮守ぢ 2020-12-13 14:59

I am working with OpenCV on the Android platform. With the tremendous help from this community and techies, I am able to successfully detect a sheet out of the image.

<
相关标签:
2条回答
  • 2020-12-13 15:41

    You could calculate your thresholds using Otsu’s method.

    The (Python) code would look like this:

    high_thresh, thresh_im = cv2.threshold(im, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
    lowThresh = 0.5*high_thresh
    
    0 讨论(0)
  • 2020-12-13 15:46

    Use the following snippet which I obtained from this blog:

    v = np.median(gray_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(gray_image, lower, upper)
    cv2.imshow('Edges',edged)
    

    So what am I doing here?

    I am taking the median value of the gray scale image. The sigma value of 0.33 is chosen to set the lower and upper threshold. 0.33 value is generally used by statisticians for data science. So it is considered here as well.

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