函数原型
 
1 edge = cv2.Canny(image, threshold1, threshold2[, edges[, apertureSize[, L2gradient ]]])

 

 
参数解释
  • image:源图像
  • threshold1:阈值1
  • threshold2:阈值2
  • apertureSize:可选参数,Sobel算子的大小
其中,较大的阈值2用于检测图像中明显的边缘,但一般情况下检测的效果不会那么完美,边缘检测出来是断断续续的。所以这时候用较小的第一个阈值用于将这些间断的边缘连接起来。
函数返回的是二值图,包含检测出的边缘
 
使用
 1 import numpy as np
 2 import cv2 as cv
 3 cv.namedWindow("images")
 4 def nothing():
 5     pass
 6 cv.createTrackbar("s1","images",0,255,nothing)
 7 cv.createTrackbar("s2","images",0,255,nothing)
 8 img = cv.imread("test/scene2.png",0)
 9 while(1):
10     s1 = cv.getTrackbarPos("s1","images")
11     s2 = cv.getTrackbarPos("s2","images")
12     out_img = cv.Canny(img,s1,s2)
13     cv.imshow("img",out_img)
14     k = cv.waitKey(1)
15     if k==ord("q"):
16         break
17 cv.destroyAllWindows()

 

相关文章:

  • 2021-06-22
猜你喜欢
  • 2021-05-23
  • 2022-12-23
  • 2022-01-05
  • 2021-11-28
  • 2021-06-01
  • 2022-01-09
  • 2022-12-23
相关资源
相似解决方案