日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

Python?cv.Canny()方法參數(shù)與使用方法_python

作者:?jiǎn)糖?? 更新時(shí)間: 2022-09-09 編程語(yǔ)言

函數(shù)原型與參數(shù)詳解

OpenCV提供了cv.Canny()方法,該方法將輸入的原始圖像轉(zhuǎn)換為邊緣圖像。

該方法的原型為:

cv.Canny(image, threshold1, threshold2[, edges[, apertureSize[, L2gradient]]]) -> 	edges
cv.Canny(dx, dy, threshold1, threshold2[, edges[, L2gradient]]) -> edges
  • image參數(shù)是array格式的輸入圖像。
  • threshold1與threshold2分別是我們的下界閾值與上界閾值。
  • apertureSize是用于查找圖像梯度的Sobel核的大小,默認(rèn)為3。
  • L2gradient指定了求梯度幅值的公式,是一個(gè)布爾型變量,默認(rèn)為False。當(dāng)它為T(mén)rue時(shí),使用L2,否則使用L1。

下面是具體代碼:

def canny_detect(image_path, show=True):
    # 讀取圖像
    image = cv2.imread(image_path, 0)
    # 獲取結(jié)果
    edges = cv2.Canny(image, 100, 200)
    if show:
        # 繪制原圖
        plt.subplot(121)
        plt.imshow(image, cmap='gray')
        plt.title('Original Image')
        plt.xticks([])
        plt.yticks([])

        # 繪制邊緣圖
        plt.subplot(122)
        plt.imshow(edges, cmap='gray')
        plt.title('Edge Image')
        plt.xticks([])
        plt.yticks([])
        plt.show()
    return edges
canny_detect('images/2.jpeg')

效果

原文鏈接:https://qiaoxs.blog.csdn.net/article/details/125728902

欄目分類(lèi)
最近更新