Today, if you are wondering how smart cars automatically follow the driverless lane line and go to the desired route, I have prepared an article for you using the image processing algorithm.Basically, the Hough Line Transform structure, which has similar logic, is used in all image processing algorithms. Today I will create an example scenario using the Python programming language. And at the end of my article, I will share these codes with you.
In fact, what is important here is the functionality of the cameras on the front bumpers of autonomous vehicles. While the vehicle is in motion, the cameras continuously process the image. The most important thing is to be able to detect the lane line. Today we will simulate, code and test the algorithm required to detect the lane. Let's take a look at how lane lines are detects on the roads.
I used the Python programming language to demonstrate this scenario. To process the image, I use the Open CV library and also add the numpy library. By the way, you can also develop more advanced image processing and lane tracking with structures such as tensorflow, but today we will use the opencv library, which is open source and accessible to everyone.
First, we open a Python editor. Then we include opencv and numpy libraries in our working environment. In this scenario, I will work on a single image, that is, a single frame processed by the camera. But it works in a similar manner in vehicle cameras. In fact, I will share an article and code in the coming days about how to process the image from a vehicle camera or any other camera.
First of all, we convert the image I took to grayscale to facilitate the masking process. Then, we create a sensitivity variable and use this value to detect lane lines by increasing or decreasing it. If the lane lines where we will process the image are white, we need to find the hsv color code range required to detect the white lane . You can easily find this yourself with the trackbar, or you can search it on the internet. If you search for the HSV color codes of white, you can easily find them, that's what I did.Accordingly, there is a lower value range and an upper value range. These values are as seen below.
After finding these values, we mask the image to leave only the lane lines. Then, we convert the masked areas into mathematical values using bitwise.Then we use the Canny function to detect the corners of the strips. As I mentioned at the beginning of my article, we detect lane lines using the HougLine transform method. Now that we know these points, let's color the inside of the lanes green using a for loop. As you can see, now that we have detected the location of the lanes, we can have our vehicle follow the lanes according to color or according to the shape we have masked.Here, we can direct our vehicle by detecting more than one criterion to further reduce the margin of error. Remember, in this project, we only saw how lane detection is done with opencv.
Nowadays, it is much easier to detect and track this with tensorflow and yolov8 models.You can access and use the source codes of the project here.