Front vehicle distance measurement method based on image features
Through a feedforward neural network based on image features, combined with vehicle recognition detection and camera imaging geometry calculation, the problem of low accuracy of monocular visual ranging in complex weather environments is solved, and high-precision, real-time vehicle ranging is achieved, which is suitable for in intelligent traffic management.
Patent Information
- Application Number
- CN202410829414.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-25
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-06-25
AI Technical Summary
Existing vehicle ranging methods have low accuracy in complex weather environments, and the cost and energy consumption are high. In particular, monocular visual ranging is difficult to achieve all-weather detection.
A feed-forward neural network based on image features is used to establish a complex mapping from vehicle feature data to distance measurement through vehicle recognition detection, camera imaging geometry calculation, vehicle feature extraction and feature fusion to achieve real-time distance measurement.
It improves the accuracy and environmental adaptability of vehicle ranging, achieves high-precision, high-stability, and real-time ranging of forward targets, and is suitable for various complex weather environments.
Smart Images

Figure CN118710698A
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of intelligent traffic management and control, and in particular to a method for measuring the distance of a vehicle ahead based on image features. Background Art
[0002] With the development of computer vision algorithms based on deep learning in the field of traffic management and control, advanced driver assistance systems are now able to use cameras, sensors, radars, lasers and other equipment to perceive the vehicle's surroundings. Vehicle ranging is an important part of the advanced driver assistance system's perception of the vehicle's surroundings, which helps improve traffic collision avoidance, hazard warning, automatic cruise control and other performance, thereby effectively reducing the incidence of traffic accidents.
[0003] There are two main methods of vehicle ranging: non-visual ranging and visual ranging. Non-visual ranging generally measures the distance to surrounding obstacles through a LiDAR or ultrasonic sensor installed on the vehicle body. LiDAR provides high-resolution three-dimensional point cloud data, which has the advantages of high precision and accuracy, but has high manufacturing costs and energy consumption, and the field of view is affected by the geometry and reflectivity of the object. Compared with LiDAR, ultrasonic sensors are low in cost and small in size, but are more suitable for close-range measurement and obstacle detection applications, and have low measurement accuracy for long-distance or high-speed moving targets.
[0004] In contrast, visual ranging, as a basic technology of computer vision, is more widely used, mainly including monocular vision, binocular vision, and structured light vision. Considering the economic and practicality, monocular cameras have the advantages of low cost, easy maintenance, wide field of view, and intuitiveness. However, the optical characteristics of the camera make it difficult to achieve all-weather detection in complex weather environments. Therefore, using monocular vision to achieve real-time ranging of the vehicle ahead based on image features and improve measurement accuracy and environmental adaptability is of great significance for intelligent traffic management and control. Summary of the invention
[0005] In order to solve the shortcomings of the background technology, the present invention provides a method for measuring the distance of a vehicle in front based on image features. The method establishes a feedforward neural network to learn the complex mapping from input vehicle feature data to output the distance of the vehicle in front, realizes real-time distance measurement between the vehicle and the target vehicle in front based on image features, and improves the distance measurement accuracy by combining the feature information of the vehicle detection frame and the vehicle image features. The method is suitable for various complex weather environments.
[0006] To achieve the above object, the present invention adopts the following technical solution: a method for measuring the distance of a vehicle ahead based on image features, comprising the following steps:
[0007] S1. Vehicle identification and detection
[0008] Detect the front target vehicle in the image through the target detection model, and obtain the category information of the front target vehicle and the feature information of the vehicle detection frame;
[0009] The vehicle recognition detection is implemented by combining the S11 road vehicle image acquisition module, the S12 data set production module, the S13 data set training module and the S14 front vehicle image recognition detection module; wherein the S11 road vehicle image acquisition module uses the vehicle image set and the self-built shot image, covering a variety of road traffic scenes under various weather conditions; the S12 data set production module classifies the image by marking the category information of the front target vehicle, and makes it into a data set for network reading; the S13 data set training module uses the target detection model to train the data set and saves the detection optimal weight file; the S14 front vehicle image recognition detection module uses the detection optimal weight file to recognize and detect the input front target vehicle image, and outputs the category information of the front target vehicle and the vehicle detection frame feature information. The vehicle detection frame feature information calculation formula is as follows:
[0010]
[0011] h=v max -v min
[0012] W=u max -u min
[0013] s=h×w
[0014] In the formula, (u min, v min ) represents the coordinates of the upper left corner of the vehicle detection box, (u max , v max ) represents the coordinates of the vertex of the lower right corner of the vehicle detection frame, and then the coordinates of the center point of the bottom edge of the vehicle detection frame p(u, v), the height h, width w and area s of the vehicle detection frame are obtained;
[0015] S2. Camera imaging geometry calculation
[0016] The camera is calibrated to obtain the internal parameters of the camera. The vehicle's lateral and longitudinal distance calculation formula is derived based on the camera imaging principle and geometric relationship to calculate the lateral and longitudinal distances of the camera relative to the target vehicle in front.
[0017] The camera imaging geometry calculation is implemented by combining the S21 camera calibration module, the S22 geometry derivation module and the S23 geometry calculation module; wherein the S21 camera calibration module obtains the internal parameters of the camera; the S22 geometry derivation module derives the vehicle lateral and longitudinal distance geometry calculation formula according to the camera imaging principle as follows:
[0018]
[0019] Where LD represents the longitudinal distance of the vehicle relative to the camera, TD represents the lateral distance of the vehicle relative to the camera, H represents the preset height of the camera, α represents the pitch angle of the camera, f represents the focal length of the camera, and f y represents the pixel describing the focal length in the y-axis direction, m represents the vertical distance from point a to the origin O of the image coordinate system, m=(v-v0)dy, t represents the horizontal distance from point a to the center point p of the bottom edge of the vehicle detection frame, t=(u-u0)dx, point a is the intersection of the vertical line of the center point p of the bottom edge of the vehicle detection frame and the y-axis in the image coordinate system; the S23 geometric calculation module substitutes the parameter values required by the geometric calculation formula of the vehicle's horizontal and vertical distances into the calculation to obtain the horizontal and vertical distances of the camera relative to the target vehicle in front;
[0020] S3. Vehicle feature extraction
[0021] Design a convolutional neural network to extract vehicle feature vectors;
[0022] The vehicle feature extraction is implemented by combining the S31 vehicle image preprocessing module and the S32 vehicle feature extraction module; wherein the S31 vehicle image preprocessing module crops the front target vehicle image according to the coordinates of the two corner vertices of the vehicle detection frame, and adjusts the image to a uniform size through preprocessing so that the shape of the vehicle in the image and the image pixels have characteristics; the S32 vehicle feature extraction module adopts a convolutional neural network, after inputting the preprocessed image, uses convolution and pooling operations to gradually reduce the image size, applies the ReLU activation function after the convolution operation, so that the convolution layer can retain the different levels of features of the image, uses the maximum pooling layer after the activation function, and halves the image size to reduce the computational complexity, and finally generates the vehicle feature vector through flattening processing;
[0023] S4. Vehicle image feature fusion
[0024] The vehicle detection frame feature information, the horizontal and vertical distances of the camera relative to the target vehicle in front, and the vehicle feature vector are integrated to generate a vehicle image feature vector;
[0025] The vehicle image feature fusion is implemented in combination with the S41 image feature fusion module; the S41 image feature fusion module fuses the obtained vehicle detection frame feature information, the horizontal and vertical distances of the camera relative to the front target vehicle, and the vehicle feature vector into a vehicle image feature vector;
[0026] S5. Neural Network Distance Measurement
[0027] Establish a vehicle ranging neural network to measure the distance between the camera and the target vehicle in front according to the fused vehicle image feature vector;
[0028] The neural network ranging is implemented by combining S51 front vehicle image and distance acquisition module, S52 ranging data set preprocessing module and S53 neural network ranging module; wherein, the S51 front vehicle image and distance acquisition module obtains multiple groups of front target vehicle images with a vehicle-mounted camera of preset height and angle, and measures the actual distance to the front target vehicle at the same time, and forms a ranging data set by one-to-one correspondence between the front target vehicle image and the actual distance, and the front target vehicle image in the ranging data set is passed through S14 front vehicle image recognition and detection module, S23 geometric calculation module, S31 vehicle image preprocessing module, S32 vehicle feature extraction module and S41 image feature fusion module to obtain a vehicle image feature vector; the S52 ranging data set preprocessing module divides the ranging data set into two parts: a ranging data training set and a ranging data test set, and saves the vehicle image feature vector of the ranging data training set in the feature_train.txt file format, and the corresponding actual distance is saved in the distance_train.txt file format, and the vehicle image feature vector of the ranging data test set is saved in the feature_test.txt file format, and the corresponding actual distance is saved in the distance_train.txt file format. The S53 neural network ranging module establishes a feedforward neural network, including six fully connected layers, and extracts features by processing data through linear transformation of six-dimensional fully connected layers. The ReLU activation function is applied between the fully connected layers, wherein the front-end fully connected layer is used as the input layer to input the fused vehicle image feature vector, and the terminal fully connected layer contains only one neuron as the output layer to output the predicted distance; the S53 neural network ranging module is divided into two stages: training and reasoning; in the training stage, the ranging data training set obtained by the S52 ranging data set preprocessing module is used for the training of the feedforward neural network, the feature_train.txt file is the vehicle image feature vector data as the feedforward neural network input, and the distance_train.txt file is the actual distance as the true value of the feedforward neural network; in the reasoning stage, the feature_test.txt file of the ranging data test set is input into the feedforward neural network, and according to the ranging optimal weight file generated by the feedforward neural network in the training stage, the input data is transmitted layer by layer through forward propagation, and finally the predicted distance from the target vehicle in front to the camera is obtained in the output layer.
[0029] Furthermore, in step S2, the camera calibration module S21 selects a chessboard calibration plate with a specification of 12×9 and a cell side length of 30 mm, and obtains the camera internal parameters through Zhang's calibration method and OpenCV calibration toolbox.
[0030] Compared with the prior art, the beneficial effects of the present invention are as follows: the present invention utilizes a vehicle-mounted camera to collect images in real time, obtains category information of the front target vehicle and vehicle detection frame feature information through a target detection model, derives the horizontal and vertical distances of the camera relative to the front target vehicle according to the camera imaging principle and geometric relationship, extracts vehicle feature vectors through a convolutional neural network, can adjust the network structure according to the needs of specific application scenarios, establishes a feedforward neural network, learns the complex mapping from input vehicle feature data to output front vehicle distance, realizes real-time distance measurement between the vehicle and the front target vehicle based on image features, and the vehicle detection frame feature information and vehicle image features make up for the problem of low ranging accuracy caused by traditional monocular ranging relying only on geometric algorithms, and is suitable for various complex weather environments, realizes high-precision, high-stability, and real-time front target ranging, and helps to improve the level of vehicle perception technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 It is a flowchart of the steps of the method of the present invention;
[0032] Figure 2 It is a module flow chart of the method of the present invention;
[0033] Figure 3 is a schematic diagram of the geometric relationship between the camera and the front target vehicle in the method of the present invention;
[0034] Figure 4 is a schematic diagram of a convolutional neural network of a vehicle feature extraction module in the method of the present invention;
[0035] Figure 5 It is a schematic diagram of a feedforward neural network of a neural network ranging module in the method of the present invention. DETAILED DESCRIPTION
[0036] The technical solution of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0037] like Figure 1 to Figure 5 As shown in FIG. 1 , a method for measuring the distance of a vehicle ahead based on image features is provided. The process is combined with Figure 1 As shown, the following steps are included:
[0038] S1. Vehicle identification and detection
[0039] The target detection model is used to detect the front target vehicle in the image, and obtain the category information of the front target vehicle and the feature information of the vehicle detection frame.
[0040] Combination Figure 2 As shown, the vehicle recognition detection is implemented by combining S11 road vehicle image acquisition module, S12 data set production module, S13 data set training module and S14 front vehicle image recognition detection module. Among them, the S11 road vehicle image acquisition module uses vehicle-mounted image sets and self-built shooting images, which should cover various road traffic scenes such as urban roads and road intersections under various weather conditions such as sunny days, cloudy days, rainy days, and snowy days. Images can be randomly extracted and data enhanced by cropping, color jittering and Gaussian noise to ensure the subsequent training effect; the S12 data set production module uses the labelImg annotation tool to manually set the category information of the front target vehicle for classification, and after the manual annotation is completed, an xml file is generated and made into a data set for network reading; the S13 data set training module uses the target detection model to train the data set and save the detection optimal weight file; the S14 front vehicle image recognition detection module uses the detection optimal weight file to detect the input front target vehicle image recognition, and outputs the category information of the front target vehicle and the vehicle detection box feature information (u, v, h, w, s). The vehicle detection box feature information calculation formula is as follows:
[0041]
[0042] h=v max -v min
[0043] W=u max -u min
[0044] s=h×w
[0045] In the formula, (u min , v min ) represents the coordinates of the upper left corner of the vehicle detection box, (u max , v max ) represents the coordinates of the vertex of the lower right corner of the vehicle detection frame, and then the coordinates of the center point of the bottom edge of the vehicle detection frame p(u, v), the height h, width w and area s of the vehicle detection frame are obtained.
[0046] S2. Camera imaging geometry calculation
[0047] The camera internal parameters are obtained by camera calibration. The vehicle lateral and longitudinal distance calculation formula is derived based on the camera imaging principle and geometric relationship to calculate the lateral and longitudinal distances of the camera relative to the target vehicle in front.
[0048] Combination Figure 2As shown in the figure, the camera imaging geometry calculation is implemented by combining the S21 camera calibration module, the S22 geometry derivation module and the S23 geometry calculation module. Among them, the S21 camera calibration module uses a chessboard calibration plate with a specification of 12×9 and a cell side length of 30mm, and obtains the camera internal parameters through Zhang's calibration method and OpenCV calibration toolbox; the S22 geometry derivation module is based on the camera imaging principle and combined with Figure 3 As shown, using the world coordinate system O W -X W Y W Z W , camera coordinate system O C -X C Y C Z C , the geometric relationship is established by the conversion relationship between the image coordinate system O-xy and the pixel coordinate system O0-uv, and the geometric calculation formula for the vehicle's lateral and longitudinal distance is derived as follows:
[0049]
[0050] Where LD represents the longitudinal distance of the vehicle relative to the camera, TD represents the lateral distance of the vehicle relative to the camera, H represents the preset height of the camera, α represents the pitch angle of the camera, f represents the focal length of the camera, and f y Represents the pixel describing the focal length in the y-axis direction, m represents the vertical distance from point a to the origin O of the image coordinate system, m=(v-v0)dy, t represents the horizontal distance from point a to the center point p of the bottom edge of the vehicle detection frame, t=(u-u0)dx, point a is the intersection of the vertical line of the center point p of the bottom edge of the vehicle detection frame and the y-axis in the image coordinate system; the S23 geometric calculation module substitutes the parameter values required by the vehicle's lateral and longitudinal distance geometric calculation formula to calculate the lateral and longitudinal distances (TD, LD) of the camera relative to the target vehicle in front.
[0051] S3. Vehicle feature extraction
[0052] Design a convolutional neural network to extract vehicle feature vectors.
[0053] Combination Figure 2 As shown, the vehicle feature extraction is implemented by combining the S31 vehicle image preprocessing module and the S32 vehicle feature extraction module. The S31 vehicle image preprocessing module crops the front target vehicle image according to the coordinates of the two corner vertices of the vehicle detection frame. The length, width, pixel size and presentation features of the front target vehicle image will change with the distance. Therefore, the image must be adjusted to a uniform size through preprocessing so that the shape of the vehicle in the image and the image pixels have characteristics; the S32 vehicle feature extraction module adopts a convolutional neural network. The convolutional neural network can adjust the number of convolution kernels according to the different types of the front target vehicles to extract the optimal vehicle feature vector. Figure 4As shown in the figure, after inputting the preprocessed image, the image size is gradually reduced by using convolution and pooling operations. The ReLU activation function is applied after the convolution operation so that the convolution layer can retain the different levels of image features. A 2×2 maximum pooling layer is used after the activation function, and the image size is halved to reduce the computational complexity. Finally, the vehicle feature vector is generated by flattening.
[0054] S4. Vehicle image feature fusion
[0055] The vehicle detection frame feature information, the horizontal and vertical distances of the camera relative to the target vehicle in front, and the vehicle feature vector are fused to generate a vehicle image feature vector.
[0056] Combination Figure 2 As shown, the vehicle image feature fusion is implemented in combination with the S41 image feature fusion module. The S41 image feature fusion module fuses the obtained vehicle detection frame feature information (u, v, h, w, s), the horizontal and vertical distances (TD, LD) of the camera relative to the front target vehicle, and the vehicle feature vector into a vehicle image feature vector.
[0057] S5. Neural Network Distance Measurement
[0058] A vehicle ranging neural network is established to measure the distance between the camera and the target vehicle in front according to the fused vehicle image feature vector.
[0059] Combination Figure 2 As shown, the neural network distance measurement is implemented by combining S51 a front vehicle image and distance acquisition module, S52 a distance measurement data set preprocessing module and S53 a neural network distance measurement module. Among them, the S51 front vehicle image and distance acquisition module obtains multiple groups of front target vehicle images with a vehicle-mounted camera of preset height and angle, and measures the actual distance to the front target vehicle at the same time, and forms a distance measurement data set by corresponding the front target vehicle image and the actual distance one by one. The front target vehicle image in the distance measurement data set is passed through the S14 front vehicle image recognition and detection module, the S23 geometric calculation module, the S31 vehicle image preprocessing module, the S32 vehicle feature extraction module and the S41 image feature fusion module to obtain a vehicle image feature vector; the S52 distance measurement data set preprocessing module divides the distance measurement data set into two parts: a distance measurement data training set and a distance measurement data test set, and saves the vehicle image feature vector of the distance measurement data training set in the feature_train.txt file format, and the corresponding actual distance is saved in the distance_train.txt file format; the vehicle image feature vector of the distance measurement data test set is saved in the feature_test.txt file format, and the corresponding actual distance is saved in the distance_test.txt file format; the S53 neural network distance measurement module establishes a feedforward neural network, combined with Figure 5As shown, it includes six fully connected layers, and the data is processed by linear transformation of six-dimensional fully connected layers to extract high-dimensional and low-dimensional features. The ReLU activation function is applied between the fully connected layers. The front-end fully connected layer is used as the input layer to input the fused vehicle image feature vector to provide raw data for subsequent feature extraction. The terminal fully connected layer contains only one neuron as the output layer to output the predicted distance. In addition, the S53 neural network ranging module is divided into two stages: training and reasoning. In the training stage, the ranging data training set obtained by the S52 ranging data set preprocessing module is used for the training of the feedforward neural network. The feature_train.txt file is the vehicle image feature vector data as the feedforward neural network input, and the distance_train.txt file is the actual distance as the true value of the feedforward neural network. The training phase of the feedforward neural network includes forward propagation and back propagation. Forward propagation calculates the output of neurons in each layer, from the input layer to the output layer. Back propagation calculates the loss function to measure the error between the predicted distance and the actual distance, propagates the error forward from the output layer to the input layer, calculates the gradient of the error layer by layer, updates the weight and bias of each connection according to the error gradient to reduce the overall error, and learns the complex mapping relationship between the input vehicle image feature vector data and the actual distance. The internal weight parameters are continuously adjusted, and finally the optimal weight file for ranging is generated and saved, recording the optimal weights and biases learned by the feedforward neural network during the training process. In the inference phase, the feature_test.txt file of the ranging data test set is input into the feedforward neural network. According to the optimal weight file for ranging generated in the training phase, the input data is passed layer by layer through forward propagation. Using the trained optimal weights and biases, after the weighted sum of neurons in each layer and the processing of the ReLU activation function, the predicted distance from the target vehicle in front to the camera is finally obtained in the output layer, realizing the mapping from input features to output results.
[0060] Example
[0061] S1. Detect the front target vehicle in the image through the target detection model, and obtain the category information of the front target vehicle and the feature information of the vehicle detection frame.
[0062] The S11 road vehicle image acquisition module uses a total of 3,800 images from the BDD 100K vehicle image set and self-shot images, covering a variety of road traffic scenes such as urban roads and road intersections in various weather conditions such as sunny, cloudy, rainy, and snowy days. Images are randomly selected for data enhancement through cropping, color jittering, and Gaussian noise, and expanded to 5,200 images to ensure the subsequent training effect.
[0063] The S12 dataset production module manually annotates images using the labelImg annotation tool, sets the category information of four types of vehicles: car, truck, van, and bus. After the manual annotation is completed, an xml file is generated and made into a dataset for network reading.
[0064] The S13 data set training module uses the target detection model to train the data set. The conventional target detection model mainly includes a feature extraction network and a detection network. The feature extraction network usually uses a pre-trained convolutional neural network to extract the features of the input image. The detection network is the convolution layer and the fully connected layer after the feature extraction network, and predicts the position and category of the bounding box. This embodiment optimizes and improves the target detection model. On the basis of the conventional target detection model, an attention mechanism is added to the feature extraction network structure, a small target detection layer is added, and a loss function is replaced; the EMA attention mechanism (Efficient Multi-Scale Attention) is used to enhance the target detection model's overall speech The target detection model pays less attention to local noise in the input sequence, improves robustness and generalization ability, reduces the amount of calculation, and adapts to large-scale data and high-performance computing environments in real-time processing; the small target detection layer enhances the small target detection performance and accuracy of the target detection model; the Wise-IoU loss function is used to achieve multi-level feature fusion and multi-scale detection, adapt to multi-scale changes, and solve the detection problem of occluded targets; the optimized target detection model is more adaptable to various complex weather environments, provides accurate detection box feature information, and provides accurate data for vehicle ranging; the data set is trained in the optimized target detection model, and the optimal weight file best.pt is saved.
[0065] S14 The front vehicle image recognition and detection module uses the optimal weight file best.pt to recognize and detect the input front target vehicle image test.jpg, and outputs the category information (car), type confidence (96%) and the coordinates of the upper left corner vertex of the vehicle detection box (1069.0, 495.0), and the coordinates of the lower right corner vertex (1173.0, 566.0). The feature information of the vehicle detection box is obtained by calculation. The calculation formula is as follows:
[0066]
[0067] h=566.0-495.0=71.0
[0068] w=1173.0-1069.0=104.0
[0069] s = 71.0 × 104.0 = 7384.0
[0070] Thus, the coordinates of the bottom center point of the vehicle detection frame p (1121.0, 566.0), the height h = 71.0, the width w = 104.0 and the area s = 7384.0 of the vehicle detection frame are obtained, that is, the feature information (u, v, h, w, s) of the vehicle detection frame is (1121.0, 566.0, 71.0, 104.0, 7384.0).
[0071] S2. Camera calibration obtains the internal parameters of the camera, and the horizontal and vertical distance calculation formulas are derived based on the camera imaging principle and geometric relationship to calculate the horizontal and vertical distances of the camera relative to the target vehicle in front.
[0072] The S21 camera calibration module uses a Sony HDR-CX680 camera with a lens focal length of 1.9mm, and selects a chessboard calibration board with a specification of 12×9 and a cell side length of 30mm. The camera position is fixed, and the chessboard orientation and angle are changed to capture images, and 20 images are taken. The camera internal parameters are obtained through Zhang's calibration method and OpenCV calibration toolbox. The OpenCV calibration toolbox obtains the coordinates of the inner corner points of the image, passes the coordinates to the CalibrateCamera function, establishes the correspondence from the three-dimensional coordinate point to the two-dimensional coordinate point, maps the two-dimensional image coordinates to the three-dimensional world coordinates, and obtains the internal parameters of the camera, f x is 1422.86 pixels, f y is 1422.73 pixels, u0 is 953.46 pixels, and v0 is 542.27 pixels.
[0073] The S22 geometry derivation module is based on the camera imaging principle and combines Figure 3 As shown, using the world coordinate system O W -X W Y W Z W , camera coordinate system O C -X C Y C Z C , the conversion relationship between the image coordinate system O-xy and the pixel coordinate system O0-uv establishes a geometric relationship. In this embodiment, the preset height of the camera is 1.4m, the focal length is 1.9mm, the pitch angle of the camera is 2°, the ranging feature point of the target vehicle in front is P, and the point mapped on the image is p(1121.0, 566.0).
[0074] The S23 geometry calculation module substitutes the required parameter values into the vehicle's lateral and longitudinal distance geometry calculation formula to perform the following calculation:
[0075]
[0076] The horizontal and vertical distances of the camera relative to the target vehicle in front are (3.08099, 27.9150), the actual measured distance is (3.0, 28.0), and the calculated error is (0.0809, 0.0850).
[0077] S3. Design a convolutional neural network to extract vehicle feature vectors.
[0078] The S31 vehicle image preprocessing module crops the front target vehicle image according to the coordinates of the two corner vertices of the vehicle detection frame. The length, width, pixel size and presentation characteristics of the front target vehicle image will change with the distance. The image is adjusted to a uniform size of 128×128 through preprocessing to make the shape and image pixels of the vehicle in the image have characteristics.
[0079] The S32 vehicle feature extraction module uses a convolutional neural network to establish five 3×3 convolutional neural networks and combine Figure 4 As shown in the figure, after the preprocessed image is input, conv1 contains 64 convolution kernels, and extracts the edge and texture features of the image by performing convolution operations; conv2 extracts high-level features, generates a 128-channel feature map, and mines complex features; conv3 and conv4 perform dimensionality reduction operations to reduce the number of channels and reduce network complexity; conv5 generates a single-channel feature map, and finally flattens all subsets into a one-dimensional array to generate a 16-dimensional vehicle feature vector. The ReLU activation function is applied after the convolution operation, so that the convolution layer can retain the different levels of features of the image. A 2×2 maximum pooling layer is used after the activation function, and the image size is halved to reduce the computational complexity.
[0080] S4, integrating the vehicle detection frame feature information, the horizontal and vertical distances of the camera relative to the front target vehicle and the vehicle feature vector, and generating a vehicle image feature vector.
[0081] The S41 image feature fusion module fuses the obtained vehicle detection frame feature information (u, v, h, w, s), the horizontal and vertical distances of the camera relative to the target vehicle in front (TD, LD), and the 16-dimensional vehicle feature vector into a 23-dimensional vehicle image feature vector. Specifically: the obtained vehicle detection frame feature information (1121.0, 566.0, 71.0, 104.0, 7384.0), the horizontal and vertical distances of the camera relative to the target vehicle in front (3.0 8099, 27.9150), 16-dimensional vehicle feature vector (0.039285928, 0.039868373, 0.03859806, 0.043999564, 0.034194592, 0.03373158, 0.03706052, 0.0332656, 0.032308687, 0.03551898, 0.034619715, 0. 0.035736978, 0.032287486, 0.034737445, 0.03438149, 0.03596463, fused into a 23-dimensional vehicle image feature vector (0.039285928, 0.039868373, 0.03859806, 0.043999564, 0.034194592, 0.03373158, 0.03706052 , 0.0332656, 0.032308687, 0.03551898, 0.034619715, 0.035736978, 0.032287486, 0.034737445, 0.03438149, 0.03596463, 1121.0, 566.0, 71.0, 104.0, 7384.0, 3.08099, 27.9150).
[0082] S5. Establish a vehicle ranging neural network to measure the distance between the camera and the target vehicle in front according to the fused vehicle image feature vector.
[0083] The S51 front vehicle image and distance acquisition module uses a vehicle-mounted camera with a preset height of 1.4m and an angle of 2° to collect images of the front target vehicle within a lateral distance of 12m and a longitudinal distance of 50m and measure the actual distance to it, obtaining a total of 61 sets of ranging data sets. The front target vehicle images in the ranging data sets are processed by the S14 front vehicle image recognition and detection module, the S23 geometric calculation module, the S31 vehicle image preprocessing module, the S32 vehicle feature extraction module and the S41 image feature fusion module to obtain the vehicle image feature vector.
[0084] The S52 ranging data set preprocessing module divides the 61 ranging data sets into 50 ranging data training sets and 11 ranging data test sets. The vehicle image feature vectors of the ranging data training set are saved in the feature_train.txt file format, and the corresponding actual distances are saved in the distance_train.txt file format. The vehicle image feature vectors of the ranging data test set are saved in the feature_test.txt file format, and the corresponding actual distances are saved in the distance_test.txt file format.
[0085] S53 neural network ranging module establishes a feedforward neural network, combined with Figure 5As shown in the figure, it includes six fully connected layers. The input layer inputs the 23-dimensional vehicle image feature vector to provide raw data for subsequent feature extraction. The fully connected layer F1 contains 32 neurons, the fully connected layer F2 contains 48 neurons, the fully connected layer F3 contains 16 neurons, and the fully connected layer F4 contains 8 neurons. The ReLU activation function is applied between the fully connected layers to capture the complex module features in the data. The output layer contains only one neuron. The data is processed by linear transformation of the six-dimensional fully connected layers to extract high-dimensional and low-dimensional features. In the training phase, 50 sets of distance measurement data training sets are input into the feedforward neural network for training. The batch_size is set to 1, the Adam optimizer is used, and the learning rate is set to 0.0001. In the training phase, the feedforward neural network calculates the output of neurons in each layer through forward propagation and back propagation, from the input layer to the output layer, and uses the loss function to measure the error between the predicted distance and the actual distance. The error is propagated forward from the output layer to the input layer, and the gradient of the error is calculated layer by layer. The weight and bias of each connection are updated according to the error gradient. A total of 3000 rounds of training are performed to achieve the learning input feature_train.txt file The vehicle image feature vector data and the actual distance in the distance_train.txt file are connected. The complex mapping relationship between distances is continuously adjusted, and the internal weight parameters are finally generated and saved. In the inference stage, the feature_test.txt files of the 11 sets of distance measurement data test sets are input into the feedforward neural network. According to the distance measurement optimal weight file generated in the training stage, the input data is transmitted layer by layer through forward propagation. The trained optimal weights and biases are used, and the weighted sum of neurons in each layer and the ReLU activation function are processed. Finally, the predicted distance from the target vehicle in front to the camera is obtained in the output layer, realizing the mapping from input features to output results. Finally, the predicted distance is compared with the corresponding actual distance in the distance_test.txt file to verify the feasibility of neural network distance measurement.Taking the above example as a set of test data in the range measurement data test set, the 23-dimensional vehicle image feature vector (0.039285928, 0.039868373, 0.03859806, 0.043999564, 0.034194592, 0.03373158, 0.03706052, 0.0332656, 0.032308687, 0.03551898, 0.034619715, 0.03 5736978, 0.032287486, 0.034737445, 0.03438149, 0.03596463, 1121.0, 566.0, 71.0, 104.0, 7384.0, 3.08099, 27.9150) Input the ranging neural network, and output the distance from the camera to the target vehicle in front as 28.29m. The actual distance measured is 28.37m, with an error of 0.08m, which is within a reasonable range.
[0086] It will be apparent to those skilled in the art that the invention is not limited to the details of the exemplary embodiments described above and that the invention can be implemented in other forms of assembly without departing from the spirit or essential features of the invention. Therefore, the embodiments should be considered in all respects as exemplary and non-restrictive, and the scope of the invention is defined by the appended claims rather than the foregoing description, and it is intended that all variations within the meaning and range of equivalents of the claims be included in the invention. Any reference numeral in a claim should not be considered as limiting the claim to which it relates.
[0087] In addition, it should be understood that although the present specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.
Claims
1. A method for measuring the distance of a vehicle ahead based on image features, characterized in that: The following steps are involved: S1. Vehicle identification and detection Detect the front target vehicle in the image through the target detection model, and obtain the category information of the front target vehicle and the feature information of the vehicle detection frame; The vehicle recognition detection is implemented by combining the S11 road vehicle image acquisition module, the S12 data set production module, the S13 data set training module and the S14 front vehicle image recognition detection module; wherein the S11 road vehicle image acquisition module uses the vehicle image set and the self-built shot image, covering a variety of road traffic scenes under various weather conditions; the S12 data set production module classifies the image by marking the category information of the front target vehicle, and makes it into a data set for network reading; the S13 data set training module uses the target detection model to train the data set and saves the detection optimal weight file; the S14 front vehicle image recognition detection module uses the detection optimal weight file to recognize and detect the input front target vehicle image, and outputs the category information of the front target vehicle and the vehicle detection frame feature information. The vehicle detection frame feature information calculation formula is as follows: h=v max -v min W=u max -u min s=h×w In the formula, (u min , v min ) represents the coordinates of the upper left corner of the vehicle detection box, (u max , v max ) represents the coordinates of the vertex of the lower right corner of the vehicle detection frame, and then the coordinates of the center point of the bottom edge of the vehicle detection frame p(u, v), the height h, width w and area s of the vehicle detection frame are obtained; S2. Camera imaging geometry calculation The camera is calibrated to obtain the internal parameters of the camera. The vehicle's lateral and longitudinal distance calculation formula is derived based on the camera imaging principle and geometric relationship to calculate the lateral and longitudinal distances of the camera relative to the target vehicle in front. The camera imaging geometry calculation is implemented by combining the S21 camera calibration module, the S22 geometry derivation module and the S23 geometry calculation module; wherein the S21 camera calibration module obtains the internal parameters of the camera; the S22 geometry derivation module derives the vehicle lateral and longitudinal distance geometry calculation formula according to the camera imaging principle as follows: Where LD represents the longitudinal distance of the vehicle relative to the camera, TD represents the lateral distance of the vehicle relative to the camera, H represents the preset height of the camera, α represents the pitch angle of the camera, f represents the focal length of the camera, and f y represents the pixel describing the focal length in the y-axis direction, m represents the vertical distance from point a to the origin O of the image coordinate system, m=(v-v0)dy, t represents the horizontal distance from point a to the center point p of the bottom edge of the vehicle detection frame, t=(u-u0)dx, point a is the intersection of the vertical line of the center point p of the bottom edge of the vehicle detection frame and the y-axis in the image coordinate system; the S23 geometric calculation module substitutes the parameter values required by the geometric calculation formula of the vehicle's horizontal and vertical distances into the calculation to obtain the horizontal and vertical distances of the camera relative to the target vehicle in front; S3. Vehicle feature extraction Design a convolutional neural network to extract vehicle feature vectors; The vehicle feature extraction is implemented by combining the S31 vehicle image preprocessing module and the S32 vehicle feature extraction module; wherein the S31 vehicle image preprocessing module crops the front target vehicle image according to the coordinates of the two corner vertices of the vehicle detection frame, and adjusts the image to a uniform size through preprocessing so that the shape of the vehicle in the image and the image pixels have characteristics; the S32 vehicle feature extraction module adopts a convolutional neural network, after inputting the preprocessed image, uses convolution and pooling operations to gradually reduce the image size, applies the ReLU activation function after the convolution operation, so that the convolution layer can retain the different levels of features of the image, uses the maximum pooling layer after the activation function, and halves the image size to reduce the computational complexity, and finally generates the vehicle feature vector through flattening processing; S4. Vehicle image feature fusion The vehicle detection frame feature information, the horizontal and vertical distances of the camera relative to the target vehicle in front, and the vehicle feature vector are integrated to generate a vehicle image feature vector; The vehicle image feature fusion is implemented in combination with the S41 image feature fusion module; the S41 image feature fusion module fuses the obtained vehicle detection frame feature information, the horizontal and vertical distances of the camera relative to the front target vehicle, and the vehicle feature vector into a vehicle image feature vector; S5. Neural Network Distance Measurement Establish a vehicle ranging neural network to measure the distance between the camera and the target vehicle in front according to the fused vehicle image feature vector; The neural network ranging is implemented by combining S51 front vehicle image and distance acquisition module, S52 ranging data set preprocessing module and S53 neural network ranging module; wherein, the S51 front vehicle image and distance acquisition module obtains multiple groups of front target vehicle images with a vehicle-mounted camera of preset height and angle, and measures the actual distance to the front target vehicle at the same time, and forms a ranging data set by one-to-one correspondence between the front target vehicle image and the actual distance, and the front target vehicle image in the ranging data set is passed through S14 front vehicle image recognition and detection module, S23 geometric calculation module, S31 vehicle image preprocessing module, S32 vehicle feature extraction module and S41 image feature fusion module to obtain a vehicle image feature vector; the S52 ranging data set preprocessing module divides the ranging data set into two parts: a ranging data training set and a ranging data test set, and saves the vehicle image feature vector of the ranging data training set in the feature_train.txt file format, and the corresponding actual distance is saved in the distance_train.txt file format, and the vehicle image feature vector of the ranging data test set is saved in the feature_test.txt file format, and the corresponding actual distance is saved in the distance_train.txt file format. The S53 neural network ranging module establishes a feedforward neural network, including six fully connected layers, and extracts features by processing data through linear transformation of six-dimensional fully connected layers. The ReLU activation function is applied between the fully connected layers, wherein the front-end fully connected layer is used as the input layer to input the fused vehicle image feature vector, and the terminal fully connected layer contains only one neuron as the output layer to output the predicted distance; the S53 neural network ranging module is divided into two stages: training and reasoning; in the training stage, the ranging data training set obtained by the S52 ranging data set preprocessing module is used for the training of the feedforward neural network, the feature_train.txt file is the vehicle image feature vector data as the feedforward neural network input, and the distance_train.txt file is the actual distance as the true value of the feedforward neural network; in the reasoning stage, the feature_test.txt file of the ranging data test set is input into the feedforward neural network, and according to the ranging optimal weight file generated by the feedforward neural network in the training stage, the input data is transmitted layer by layer through forward propagation, and finally the predicted distance from the target vehicle in front to the camera is obtained in the output layer.
2. The method for measuring the distance of a vehicle ahead based on image features according to claim 1, characterized in that: In the step S2, the camera calibration module S21 selects a chessboard calibration plate with a specification of 12×9 and a cell side length of 30 mm, and obtains the camera internal parameters through Zhang's calibration method and OpenCV calibration toolbox.
Citation Information
Patent Citations
Vehicle ranging method based on depth learning
CN109509223A
Vehicle detection method based on unmanned aerial vehicle and anchor-frame-free network
CN111626987A
Vehicle tracking method and device and electronic equipment
CN111709328A
Method and equipment for transversely and longitudinally positioning and ranging rear vehicle
CN112070839A
Front vehicle detection and distance measurement method based on convolutional neural network
CN113111707A
