Cannny edge detection
- Use Gaussian filter to smooth the image and filter out noise
- Calculate the gradient intensity and direction of each pixel in the image
- Apply non-maximum suppression to eliminate spurious responses from edge detection
- Apply double thresholds, detection to determine real and potential borders
- Weak edges encouraged by suppression eventually complete edge detection
Code:
Import CV2 Import numpy AS NP DEF cv_show (IMG, name): cv2.imshow (name, IMG) cv2.waitKey (0) cv2.destroyAllWindows () # Loading grayscale image IMG = cv2.imread ( ' E: / IMG / 4.jpg ' , cv2.IMREAD_GRAYSCALE) # threshold range V1 = cv2.Canny (IMG, of 80, 150 ) V2 = cv2.Canny (IMG, 80,100 ) # juxtaposed display RES = np.hstack ((V1, V2)) cv_show (RES, ' RES ' ) # Loading grayscale IMG = cv2.imread ( ' E: /img/4.jpg ' , cv2.IMREAD_GRAYSCALE) # Threshold range V1 = cv2.Canny (IMG, 120,250 ) V2 = cv2.Canny (IMG, 50,100 ) # juxtaposed display RES = np.hstack ((V1, V2)) cv_show (RES, ' RES ' )
Threshold:
80-150
80-100 effect is
120-150
50-100