Lane Detection - Python OpenCV Project - with code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone how's it going so today we're looking into lane detection using opencv in the description below you'll find the collab link which is the source code and you can simply run it on your browser and you can also download that code or the whole github repository if you want to run it on your desktop using your own webcam or dash cam videos so coming down to the github so this is the gentleman and he basically open sourced this code it's a very nice code i mean among all the other lane detection codes that i've seen this has made things very easy to understand and he has gone through all the basics he has also taken up all the best practices or especially for lane detection perspective so if you come down to the code and this is the collapse file that you can open up in your browser and the first thing is you want to run this code and it will download all these repository files and this is basically the code which is coming from his repo now i i made a few things in refresh to the code right here this one so there are a few changes that we had to do in order for it to run nicely with the colab file but uh it should i mean the same thing should also run for you if you're running it on your desktop but nevertheless let's look into the code so there are basically four or five things that are happening in this particular code and if you just simply run this it'll ask you the video that you want to upload so yeah in the bro if you go back to the folder and under the advanced lane lines so this folder will pop up once you run the clone repository and it'll take care of this so coming down here in fact let me refresh the runtime if i say factory reset it'll basically reset everything and it'll be brand new as if you guys were opening it but let me show you what what happens now if you run this code right now this particular directory is zero there is nothing in it because we have we don't have anything put up here now if i run this it will clone the repository and it will create this folder called advanced lane lines for us and it's basically copying the whole repo for us in a few seconds it should be all done and if we open this folder there are some videos like the challenge video the horror challenge video the project video so these are all dot mp4 files which the the author of this repo he had taken and he was kind enough to share it with everyone so he it's basically the video of all the lanes the video which you saw in the beginning and it's able to describe where the output is and uh able to give out the whole name for us so coming here if you just replace this video with whatever you video you want of course you would have to upload it you'll have to come here to this folder and click over here and upload the video which you want to run or test the system on if not you can always choose from one of the two three videos that are available here like the project video just type the name of this video here and dot mp4 and this output.mp4 is the output format or the name of the format or name of the file that will be generated once the application is run so if if i were to run this basically it will create an output.mp4 file for us it should pop up any minute right now and it will give us and once it's done once the loading is done once all the videos run you can simply download it from here so it's still is it ready no we don't see it maybe if you refresh this close it and open it back again you can see there is this output dot mp4 value right now it's only 457 kb but if you download this once it's done you can simply download and see what the output is but with uh that we're not concerned about that right now let's look into the code let's what is let's see what is happening so there are basically these four or five things that are the crucial aspect of the whole application the first thing is camera calibration and camera calibration is a function it's uh it's a system that is allowed that allows us to remove any errors in the video that can occur because of the camera irregularities what do i mean by that so i have this video page opened up here it's from the opencv camera calibration page so if you look just look into google and look for opencv camera calibration and docs folder of opencv you'll get this page now what is happening is if you notice this chess chessboard and refer to this red lines so even though it's one image even though it's one frame you can see this red line which is basically connecting the two corners of the these two blocks the chess pieces you can see that the red line is not crossing through everyone as it should have been so it's basically telling you that there's this some sort of distortion that is happening in the image and similarly at the same when you look into the vertical aspect you can still see that some of some places the line is crossing the black box more often than uh basic than the ones on the corners but there is some sort of distortion that is happening and that's not good because this can cause errors in your especially if you're using it for your self-driving purposes where you're trying to control the vehicle and any small errors like this can cause bigger problems in with respect to controlling a machine so you want to be careful about that and for that purpose we use a calibration and opencv has this calibration system it has its own calibration function and it basically looks into the corners of the chest pieces so you have these chest pieces and chest chest pieces is a very good uh system a very good image for us to use in order for to calibrate and the author had for the camera that he used he provided a camera calibration folder which has all the images of the chessboard pieces that he took and this uh so it's the same camera that he used to record the lane detection and that has allowed him to control the calibration aspect for the camera so it looks into the corners of these and tries to maintain the perspective of the image in the right in the right calibration so it basically understands what the calibration means now once you're done with the calibration the second step is thresholding and thresholding is nothing but filtering filtering out of the end so that that way you can emphasize the region that is more important for you thresholding opencv has this very nice image so look at this image this is the original image and it's a gradient image it's starting from white white section from here and going all the way here which makes it darker gradually now if you were to give out a threshold and say okay anything beyond this line anything beyond this pixel should be black and anything before this pixel should be white that threshold that central line between the image is what is causing the is what is filtering it all about thresholding all about and if you give that uh section or if you give that mark or filter value and say okay anything before this is zero anything after that is one so it basically makes an image black and white uh it uh it converts or anything below the pixel values in one color and the other in other colors so it basically uh differentiates between the or filters all the pixel values based on what we want the best use of that is to emphasize on some information that is important for us so if you notice this particular image here with with the sudoku box you can see that it has a lot of information the gray color the font and all this information that is available here is not so much of concern for us and we are we are more interested in the boxes and the numbers available here you can see these numbers and the boxes are a little bit different compared to the text that is written here the images that are available here the color of the page so everything is different and you can change that by using thresholding and by using thresholding you can remove all the unnecessary information that is available and just emphasize on the portion that you are interested in so you can see this particular threshold image uh it's a different type of thresholding which is not so much of concern right now but as long as we understand what thresholding is that's good enough for this video so this is you can see that it's able to emphasize the content of the image and then basically uh embossing or giving out more information about what is important and in our case it's the boxes and the numbers so with that that's where thresholding helps and uh in our case uh when we're doing lane detection we want to emphasize only on the regions the way the lanes are available and for that purpose we use thresholding the next purpose uh the next second thing he's going to do is perspective transformation and this is a very interesting phenomena as well uh if you come down to this image i think uh if i just google respective transform there are some very nice images that help understand what is is all about so this is a very good image and if i open this up i think it's from the pi image search website so you can see this card which is basically present over here and on the ground and you can see the levee it's lay down the edges of this side is smaller than the edges of this side even though it's a it's a solid rectangle of same breadth and same width but since it's available since it's present or since it's kept in such a way and if you're taking the camera image it looks as though the size of these two boxes see these two sides are different but if you use perspective transformation you can you can basically pick it up and place it over here so that it looks you know you're just concentrating on information and not reflecting it with respect to the background so what i mean by that is it's able to remove the issues remove the errors that are occurring with the distances with the perspective so the way you because the way you perceive or the the way you're having your perspective vision that can distort the image and to remove that you're using this perspective transformer that can help us make the image more regular size so coming down here i mean these images are very good in understanding you can see that it looks like a trapezoid so where the edge this is a smaller edge compared to this one but if you if you were to use the perspective transform you can basically look in the size and then it's where it's making the size of the other side of the image same as well so that that's what perspective transform is all about now coming back to lean lines so this is the last function one of the most important functions this is where you're detecting the lanes and getting the lines and there are other functions uh other uh functions available in this program where uh it's they're able to differentiate where the direction is going whether it's going left or right and based on those images they they are able to keep that give out those instructions for the machine now coming down to the lane lines so this is a very interesting one uh if you look into the uh if you look at the lane from a car's perspective imagine the car had some eyes and it had the headlight basically a dash cam for example and if you open up this image for example and you can see uh that let me open up this yeah you can see that this image of a lane it has this uh the lanes that are available or you can delete that the car is able to see it's on the lower half of the image right the upper half has the sky and all this other information which is not important for us as long as i mean for a self-driving purpose you're only interested in the lane you know and where the lanes are going and for that purpose you can neglect all the information which is on the top and just concentrate on what is available in the bottom so if you are doing lane detection and if you're able to if you're trying to detect all the lines that are available in the image you want to uh maybe crop the image from the lower half so you're not interested in top half and that's where some of the function of the lane lines is being done in this project and once the upper portion is removed you can then only focus on the lanes or the lines that are available at the bottom and uh in order for us to detect the lines you have two other functions one is the canon edge detection and the canon edge detection is right here where you can see that uh it's able to it's detect so for example open up one of the images right here where you can see this person and this is the image it's a grayscale image it's able to identify the outer edges of a burst of the person and then also after doing some sort of noise removal which is you know these are called as morphological operations uh no need to get confused right now basically you're just removing some nice pixels that are not important you and then just emphasizing on what is important you can see the tie over here it had all these textures which was also being detected but you know we were only interested in the outer edge of the of the tie and for that purpose you can simply erode all the unnecessary information and that's what the canyon edge detection is all about once you do the kanye edge detection then there is another application called as hook or who transform i'm not sure how it's exactly called but uh this who transformation it's able to identify from basically basically if you look into these lines and uh it's able to see from these lines there are different types of lines but the who transformation is able to identify and and detect a straight line from given a set of edge directions so it's able to take an image which has all these edges but come up with uh it's kind of a machine learning approach but what it does is it takes the edges it takes all these edges and then try to identify a line based on some of the parallel parameters that you can give basically if you say okay there is if there is an edge of so and so length yes that is the edge that i am interested in and if there is an edge maybe of so and so curvature yes that is the edge that i am interested in rest all i am not interested in so that's where some of the who transformation application comes in so you can see here different different types of lanes and uh even in lane detection how you can basically emphasize or basically take out and you can eliminate all the other noise pixels here so you you can see all of these are images all of these are edges but you are only interested in the edge that is representing the lane of the road and for that purpose you you're using something called as food transformation where it can uh only only concentrate on the edge that you specify maybe you can say that okay i'm interested in the edge which could be of so and so length or it could be of so and so it could be at a different set angle so those are some of the features that you can specify and then who transformation can help you only extract that particular edge so with that uh we basically run into lane detection with all that we can simply take care of the lane detection for us with that i mean this was not normal not more into the coding aspect but more about understanding and the theory behind lane detection hope it helps someone understanding the phenomena yeah i mean if you're just looking to run the code you can copy the same thing in this run and it will take care of it for you with that we come to the conclusion of this video if you guys liked it please let me know and if uh let me know what kind of other projects that you are working on on what kind of projects you want me to work on and if it's something interesting and yeah let's let's get into it with that you guys take care stay safe bye
Info
Channel: Misbah Mohammed
Views: 71,830
Rating: undefined out of 5
Keywords:
Id: iRTuCYx6quQ
Channel Id: undefined
Length: 16min 54sec (1014 seconds)
Published: Thu Nov 12 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.