import cv2 import numpy as np blur = 3 canny_low = 255 canny_high = 50 def on_change(value): pass img = cv2.imread("./res/trees/berk_sq1_original.png") img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) width = int(img.shape[1] * 40 / 100) height = int(img.shape[0] * 40 / 100) dim = (width, height) # resize image img = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) cv2.imshow('frame', img) cv2.createTrackbar('Contrast', 'frame', 0, 25, on_change) cv2.createTrackbar('Canny low', 'frame', 0, 1000, on_change) cv2.createTrackbar('Canny high', 'frame', 0, 1000, on_change) while(1): # get data from trackbars blur = cv2.getTrackbarPos('Blur rate', 'frame') canny_low = cv2.getTrackbarPos('Canny low', 'frame') canny_high = cv2.getTrackbarPos('Canny high', 'frame') # Canny Edge Detection edges = cv2.Canny(image=img, threshold1=canny_low, threshold2=canny_high) # Display Canny Edge Detection Image cv2.imshow("Canny Edge Detection", edges) # wait for escape k = cv2.waitKey(5) & 0xFF if k == 27: break cv2.destroyAllWindows()