Canny 边缘检测
def cv_show(neme, img):
# cv2.namedWindow(neme, cv2.WINDOW_NORMAL)
cv2.imshow(neme, img)
cv2.waitKey(0)
cv2.destroyAllWindows()
img = cv2.imread('1.png', 0)
# Canny 边缘检测(图像、min值、max值)
edges = cv2.Canny(img, 100, 200)
cv_show("s", edges)
进度条调节
import cv2
def nothing(x):
pass
cv2.namedWindow('res')
cv2.createTrackbar('max', 'res', 0, 255, nothing)
cv2.createTrackbar('min', 'res', 0, 255, nothing)
img = cv2.imread('1.png', 0)
maxVal = 200
minVal = 100
while (1):
if cv2.waitKey(20) & 0xFF == 27:
break
maxVal = cv2.getTrackbarPos('min', 'res')
minVal = cv2.getTrackbarPos('max', 'res')
if minVal < maxVal:
edge = cv2.Canny(img, 100, 200)
cv2.imshow('res', edge)
else:
edge = cv2.Canny(img, minVal, maxVal)
cv2.imshow('res', edge)
cv2.destoryAllWindows()