In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to use OpenCV to achieve lane detection, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Computer vision plays an important role in observing the environment and predicting the input value of the controller of the automatic system. This paper introduces the process of lane detection using computer vision technology, and guides us to complete the steps of identifying lane regions, calculating road RoC and estimating lane center distance.
Camera Calibration (calibrateCamera.py)
Almost all cameras use lenses that have some error in focusing light to capture an image because the light bends at the edge of the lens due to refraction. This phenomenon will lead to distortion of the edge of the image. The following video illustrates the two main types of distortion with examples and is strongly recommended.
Assuming that we now know what radial distortion is, we need to use distortion coefficients (K1, K2 and K3) to correct radial distortion. CalibrateCamera.py is a camera calibration program that is not run by default. It is recommended to use at least 20 chessboard images in the process of generating feature points on the target and feature points on the image. Calibrate () in Main will look for images in / data/calibration, but we can also select other directories.
Figure 1 left: image distortion; right: undistorted image
The whole process of removing image distortion is quite interesting, and OpenCV has a good tutorial that explains the concept and gives some examples.
Perspective transformation (preprocess.py:8-19)
The first step in detecting the driveway is to adjust our visual system to look at the road ahead with a bird's-eye view, which will help us to calculate the curvature of the road and therefore help us to predict the steering angle of a few hundred meters in the future. Another benefit of the top-down view is that it solves the problem of lane intersection. In fact, as long as you drive along the road, the lane is parallel.
The aerial view can be realized by applying perspective transformation, that is, four points in the lane area of the input image are mapped to the desired points to generate a top-down view. These points are determined on a case-by-case basis, and the determining factors are mainly the position of the camera in the vehicle and its field of view. The picture in figure 2 represents the input image and the converted output image respectively.
Figure 2 left: before, right: after
Threshold (preprocess.py:22)
Now that the lanes are parallel, the next step is to segment them from the input image. The input image contains RGB3 channels, and the lane lines are white or yellow. Based on this assumption, the input image can be converted into a single channel grayscale image, thus eliminating the channels we do not need. Another color space to convert to is the HLS color space, where the S channel may provide better results depending on the lighting. In the following example, the image threshold is used because it works properly in a given input image. Figure 3 visualizes the output after threshold processing.
Figure 3 cv2.threshold (image, 220,225, cv2.THRESH_BINARY)
The lower threshold (220) and the upper threshold (225) will be manually adjusted according to the input image. OpenCV has advanced techniques based on overall nested edge detection without any manual adjustment to the threshold, but this paper still uses a simple threshold technique.
Lane Pixel search (laneDetection.py:4~70)
After preprocessing the input image, the lanes are determined and drawn in the image space. The method is to draw a non-zero pixel histogram in the lower half of the binary image (threshold image) to observe the mode:
Fig. 4 histogram x = pixels, y = count
Because the pixel value is binary and the peak represents the location of most non-zero pixels, it is a good indication of the lane. The x coordinates in the histogram are used as the starting point for searching for the corresponding channel. The concept of the sliding window method will be applied here. The following video illustrates the concept of the sliding window, which is the result in figure 5.
Figure 5. The concept of a sliding window is applied to the results of figure 4.
Identify Lane area (laneDetection.py:85~149)
The sliding window helps to estimate the center of each lane area, and these x and y pixel positioning functions search_around_poly () can be used to fit the second-order polynomial curve. This function is suitable for f (y) rather than f (x) because the channel is vertical in the image. Figure 6 illustrates this step very well.
Fig. 6 second-order polynomials detected on these channels
The next step is to calculate the radius of curvature, which can be calculated using a circle that closely fits the point near the local part of the curve, as shown in figure 7. The radius of curvature of a curve at a particular point can be defined as the radius of an approximate circle. This radius can be calculated using the formula in figure 7.
Fig. 7 Radius of curvature concept graph and equation used to calculate RoC
The final step is to place a polygon between these points and project it back to the original image to highlight the driveway area. The lane area and radius of curvature are calculated based on pixel values, which are different from real-world space, so they must be converted to real-world values, which involves measuring the length and width of the lane part of the distorted image we project. For simplicity, we can assume that most lanes are usually 30 meters long and 3.7 meters wide, and that the code uses these values to convert pixel space values into actual meter measurements.
Figure 8 the final expected result highlights the lane area
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.