cv2Canny边缘检测

import cv2


# 回调函数
def nothing(pos):
    pass


if __name__ == '__main__':
    img = cv2.imread('1.jpg')
    edges = img
    cv2.namedWindow('Original')
    cv2.namedWindow('Canny')
    cv2.createTrackbar('Min', 'Canny', 0, 100, nothing)
    cv2.createTrackbar('Max', 'Canny', 100, 200, nothing)

    while True:
        cv2.imshow('Original', img)
        cv2.imshow('Canny', edges)
        min = cv2.getTrackbarPos('Min', 'Canny')
        max = cv2.getTrackbarPos('Max', 'Canny')
        edges = cv2.Canny(img, min, max)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cv2.destroyAllWindows()

你可能感兴趣的:(Python,OpenCV)