OpenCV Python Tutorial For Beginners 20 - Canny Edge Detection in OpenCV

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to the next video on open CV tutorials for beginners using Python in this video we will talk about kenny edge detector in open CV so first of all what is canny edge detector so the canny edge detector is an edge detection operator that uses multistage algorithm to detect a wide range of edges in images now this canny edge detector was written and developed by John F Kennedy in 1986 that's why it's named after his name which is Kenny as detector now the process of canny edge detection algorithm can be broken down in five different steps the first step is to apply gaussian filter to smooth the image in order to remove the noise the second step is to find the intensity gradients of the image the third step is to apply the non maximum suppression to get rid of spurious response to edge detection the fourth step is to apply double threshold to determine the potential edges and the fifth step is to track edges by hysteresis that is to finalize the detection of the edges by suppressing all the other edges that are weak or not connected to strong edges so this seems a little bit complicated but in open CV it's really simple to use so there is a built-in function in open CV which is called Kenny and we are going to use this function so to start with I have this sample code which loads this image which is called messy dot jpg using the matplotlib library I'm going to just run this to show you the result so this is the image and we want to they take the edges of this image so what we are going to do is we are going to first of all declare a variable called Kenny and then there is a method as I already said inside your CV to library which is called Kenny method which takes few arguments so the first argument here is the image source itself the second argument and the third argument as you can see is the first threshold value and the second threshold value so this first threshold value and the second threshold value you need to provide for the hysteresis procedure so there is the last step as I mentioned and in that step hysteresis take place and for that procedure we need to provide the values of the threshold one and the threshold two so for now I'm going to provide hundred as the threshold one and 200 as the threshold two but later you might want to add a track bar in order to see the changes in the edges when you just move the track bar from left to right for the threshold one and the threshold two so this might be a small assignment for you you can just add the track bar and see how the edge detection changes when you change the value of threshold one and threshold two and I have already explained how you can use track bars with open CV so just watch that video and you will be good to go so now we have the result of canny edge detection function so we are going to just add it to our list first to the list of titles and then second to the list of images and the range we are going to increase it to two and this we are going to just see the images in one by two format so going to just run this button script and see the result so you can see we have the original image here which we have loaded in the grayscale and on the right hand side you can see the result of the canny edge detection methods so you can see all the edges which are available here on this messy five dot jpg image you can use this on the other images also so for example I have the Lenna dot jpg image let's see the result of that and this is the result of the canny edge detection method on this Lana dot jpg method so this canny edge detection is really useful because in the last video we have seen how to find out the image gradients and let's see in comparison to those image gradient methods how Kenny edge detection method performs so these are all the methods I have explained in the last video laplacian Sobel X and Sobel Y and I have shown you how to combine the result of Sobel X and Sobel why and additionally I have added this line to the previous code which I have shown you in the last video which is a J's is equal to CB 2 dot canny which it gives us the result on the same image using the canny edge detection method and I have added it to the title and the image right so let's run this script once again and let's see the differences in the result using all these methods so you can see all the six results this is the original image this is the result of the laplacian method this is the result of Sobel x and this is a result of Sobel y and this is the combination of Sobel x and y and you can see canny edge detection gives us the result which contains lesser noises so you can see there is a lot of noise present in the other matters you can see here all the noise is present which is removed using Kenny edge detection or in the laplacian method also you can see some noises around but in the Kenny edge detection method you can see you get the proper edges and more precise edges without any noise so this is the benefit of using Kenny edge detection so this is how you can use Kenny edge detection in OpenCV I hope you enjoyed this video and I will see you in the next video you
Info
Channel: ProgrammingKnowledge
Views: 87,498
Rating: undefined out of 5
Keywords: OpenCV Tutorial, Python (Programming Language), Python 3.6, Python, Python Tutorial, Python course, Online Course, OpenCV, OpenCV Tutorial for Beginners, Computer Vision, Computer Vision Basics, Computer Vision Tutorial, Windows, Linux, Image Processing, OpenCV Python Tutorial, OpenCV Python, matplotlib with OpenCV, blurring images, Image Gradients, Edge Detection, High-pass filters, Sobel, Scharr, Laplacian, Canny Edge Detection, Canny
Id: CGfXCkHNemo
Channel Id: undefined
Length: 7min 40sec (460 seconds)
Published: Sat May 25 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.