Image-based vehicle orientation and head-tail identification method
By combining edge detection and line detection with image preprocessing and Hough transform techniques, the rotation angle and head-to-tail direction of the vehicle are automatically calculated, solving the misjudgment problem of vehicle orientation and head-to-tail recognition in traditional methods, and achieving low-cost, high-efficiency vehicle detection accuracy and semantic understanding.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI QISHENG TIMES TECHNOLOGY CO LTD
- Filing Date
- 2025-12-19
- Publication Date
- 2026-07-14
Smart Images

Figure CN121788906B_ABST
Abstract
Description
Technical Field
[0001] This invention generally relates to the field of intelligent transportation technology, and specifically to an image-based method for vehicle direction and head-and-tail recognition. Background Technology
[0002] In traffic accident reconstruction, traffic flow dynamic analysis, autonomous driving perception, and intelligent transportation systems, identifying the orientation and head-to-tail position of vehicles in images is crucial for subsequent trajectory analysis and event reconstruction.
[0003] However, traditional object detection algorithms (such as YOLO and Faster R-CNN) typically output rectangular boxes aligned with the image coordinate axes, which are difficult to accurately reflect the actual orientation of the vehicle and cannot distinguish the front and rear positions of the vehicle. Especially when the vehicle is turning or tilting, the risk of misjudgment increases significantly. At the same time, if manual annotation is still relied upon for vehicle orientation recognition, the annotation cost is high. If model annotation is relied upon, the model's generalization ability across different scenarios and vehicle models is limited, and its transfer adaptability is weak. Therefore, there is an urgent need for an automated, robust, and widely applicable method for vehicle orientation and front / rear recognition. Summary of the Invention
[0004] In view of the above-mentioned defects or deficiencies in the prior art, it is desirable to provide an image-based vehicle orientation and head-and-tail recognition method.
[0005] This invention provides an image-based method for vehicle orientation and head-and-tail recognition, comprising: Acquire an image of the target vehicle and read at least one set of vehicle information corresponding to the target vehicle image; the vehicle information includes at least the vertex coordinates of the initial rectangular bounding box of the vehicle corresponding to the target vehicle. Based on the target vehicle image, edge detection and line detection are performed on the target vehicle to obtain a set of lines that meet preset conditions; the set of lines includes multiple lines corresponding to the length of the target vehicle body; Based on the set of lines, the main direction angle of the target vehicle is determined, and based on the main direction angle and the vertex coordinates of the initial rectangular frame outside the vehicle, a rotating rectangle that matches the outline of the target vehicle is constructed. Based on the rotating rectangle, a dividing line is set, and image corner points distributed on both sides of the dividing line are obtained. Based on the distribution of the image corner points, the locations of the head and tail of the target vehicle are determined.
[0006] According to the technical solution provided by the present invention, the step of performing edge detection and line detection on the target vehicle based on the target vehicle image to obtain a set of lines that meet preset conditions includes: The target vehicle image is preprocessed to obtain a preprocessed target vehicle image; The Canny operator is used to perform edge detection on the processed target vehicle image to obtain an image with vehicle edge points. Apply the probabilistic Hough transform to the image containing vehicle edge points to detect the line segments contained therein, and obtain a candidate set of line segments; The line segments in the candidate set of line segments are sorted according to their Manhattan length, and a preset number of line segments are selected in sequence according to the sorting results to form the line set.
[0007] According to the technical solution provided by the present invention, the step of preprocessing the target vehicle image to obtain a preprocessed target vehicle image includes: The target vehicle image is converted into a grayscale image, and a Gaussian filter is applied to the grayscale target vehicle image to obtain the processed target vehicle image.
[0008] According to the technical solution provided by the present invention, determining the principal heading angle of the target vehicle based on the set of lines includes: The horizontal angles formed by all line segments within the set of lines are counted, and all singular angles within the horizontal angles are removed to obtain the filtered horizontal angle data. The mean of the horizontal angle data is calculated, and the horizontal angle corresponding to the mean is taken as the main direction angle of the target vehicle.
[0009] According to the technical solution provided by the present invention, constructing a rotating rectangle that matches the outline of the target vehicle based on the principal direction angle and the vertex coordinates of the initial rectangular frame outside the vehicle includes: Obtain the vertex coordinates of the initial rectangle outside the vehicle, and determine the aspect ratio of the initial rectangle outside the vehicle based on the vertex coordinates; Based on the aspect ratio, the length and width of the minimum bounding rectangle corresponding to the target vehicle are estimated. Based on the principal direction angle, the long side direction vector and the short side direction vector of the minimum bounding rectangle are calculated. Obtain the center point of the initial rectangular frame outside the vehicle. Based on the center point, the length and width of the minimum bounding rectangle, the direction vector of the long side, and the direction vector of the short side, calculate the actual vertex coordinates used to construct the rotating rectangle to obtain the rotating rectangle.
[0010] According to the technical solution provided by the present invention, the step of estimating the length and width of the minimum bounding rectangle corresponding to the target vehicle based on the aspect ratio includes: Obtain the length and aspect ratio of the initial rectangular frame outside the vehicle; The aspect ratio is compared with a preset ratio range to determine the target aspect ratio of the minimum bounding rectangle; The length of the initial rectangular frame outside the vehicle is used as the length of the minimum bounding rectangle. The width of the minimum bounding rectangle is calculated based on the target length-to-width ratio and the length of the minimum bounding rectangle.
[0011] According to the technical solution provided by the present invention, the step of comparing the aspect ratio with a preset ratio range to determine the target aspect ratio of the minimum bounding rectangle includes: If the aspect ratio is within a preset range, the aspect ratio of the initial rectangular frame outside the vehicle is taken as the target aspect ratio of the minimum bounding rectangle. If the aspect ratio is less than the lower boundary value of the preset ratio range, the aspect ratios of the initial bounding rectangles of all auxiliary vehicles in the target vehicle image are averaged and the average aspect ratio is used as the target aspect ratio of the minimum bounding rectangle; wherein, the auxiliary vehicle is a vehicle whose aspect ratio of the initial bounding rectangles of all vehicles in the target vehicle image is within the preset ratio range.
[0012] According to the technical solution provided by the present invention, the step of setting a dividing line based on the rotating rectangle, obtaining image corner points distributed on both sides of the dividing line, and determining the location of the head and rear of the target vehicle based on the distribution of the image corner points includes: Based on the rotating rectangle, a straight line passing through the center of the rotating rectangle and perpendicular to the main direction angle is constructed as a dividing line; Using the dividing line as the boundary, the corner points distributed on both sides of the dividing line are obtained using a corner point algorithm. The number of corner points on both sides of the dividing line is counted and recorded as the first corner point number and the second corner point number. If the number of the first corner points is greater than the number of the second corner points, then the side corresponding to the number of the first corner points is determined to be the front of the target vehicle, and the side corresponding to the number of the second corner points is determined to be the rear of the target vehicle; otherwise, then the side corresponding to the number of the second corner points is determined to be the front of the target vehicle, and the side corresponding to the number of the first corner points is determined to be the rear of the target vehicle.
[0013] According to the technical solution provided by the present invention, after determining the locations of the head and rear of the target vehicle, the method further includes: The coordinates of the two actual vertices of the rotating rectangle located at the head of the target vehicle are taken as the head point of the rotating rectangle of the target vehicle, and the coordinates of the two actual vertices of the rotating rectangle located at the tail of the target vehicle are taken as the tail point of the rotating rectangle of the target vehicle. The head and tail points of the rotating rectangle are sorted and output in a clockwise direction to construct a rotating rectangle with directional semantics.
[0014] In summary, this technical solution specifically discloses an image-based vehicle orientation and head / tail recognition method, comprising: acquiring a target vehicle image and reading vehicle information corresponding to the target vehicle image; the vehicle information includes at least the vertex coordinates of the initial bounding box outside the vehicle; performing edge detection on the target vehicle based on the target vehicle image to obtain a set of straight lines that meet preset conditions; the set of straight lines includes multiple straight lines corresponding to the length of the target vehicle body; determining the main orientation angle of the target vehicle based on the set of straight lines, and constructing a rotating rectangle that matches the outline of the target vehicle based on the main orientation angle and the vertex coordinates of the initial bounding box outside the vehicle; setting a dividing line based on the rotating rectangle, acquiring image corner points distributed on both sides of the dividing line, and determining the positions of the head and tail of the target vehicle based on the distribution of the image corner points.
[0015] Beneficial Effects: This invention determines the principal orientation angle by extracting edge lines from the target vehicle image, transforming the original axis-aligned bounding box into a rotated rectangle conforming to the vehicle's contour, and combining corner point distribution analysis to automatically distinguish the front and rear of the vehicle. This method can identify vehicle orientation and front / rear position without relying on large-scale labeled data or complex deep learning models, offering advantages such as high computational efficiency and low deployment cost. Simultaneously, the output rotated bounding box with directional semantics enhances the geometric accuracy and behavioral interpretability of the vehicle detection results, providing more reliable and effective information for practical applications such as vehicle trajectory analysis, traffic event judgment, and accident reconstruction. Attached Figure Description
[0016] Other features, objects, and advantages of the invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings: Figure 1 This is a schematic diagram of generating a rotated rectangle.
[0017] Figure 2 This is a schematic diagram of a rotating rectangle with semantic direction.
[0018] Figure 3 This is a flowchart illustrating an image-based method for vehicle orientation and head / tail recognition.
[0019] Figure 4 This is a flowchart of S200 in an image-based vehicle direction and head / tail recognition method.
[0020] Figure 5 This is a flowchart of S300 in an image-based vehicle direction and head / tail recognition method.
[0021] Figure 6 This is a flowchart illustrating S304 in an image-based vehicle direction and head / tail recognition method.
[0022] Figure 7 This is a flowchart of S400 in an image-based vehicle direction and head-and-tail recognition method.
[0023] Figure 8 A schematic diagram illustrating the principle of solving for vertex coordinates.
[0024] Figure 9 This is a schematic diagram of the initial rectangular frame of the vehicle's exterior under the traditional method in practical applications.
[0025] Figure 10 This is a schematic diagram of the rotating rectangle generated by this method in a practical application. Detailed Implementation
[0026] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings.
[0027] It should be noted that, unless otherwise specified, the embodiments and features described in the present invention can be combined with each other. The present invention will now be described in detail with reference to the accompanying drawings and embodiments.
[0028] Example 1 To make the technical solutions of the embodiments of the present invention clearer and easier to understand, the application background of the embodiments of the present invention will be introduced below.
[0029] In fields such as intelligent traffic management, automated traffic accident reconstruction, traffic flow dynamics analysis, and autonomous driving perception, accurately identifying the precise orientation and head-to-tail position of vehicles in images or video sequences is a crucial prerequisite for achieving vehicle trajectory tracking, behavioral intent prediction, and incident liability determination. Especially in typical application scenarios such as drone traffic inspections and overhead camera surveillance, the superior perspective allows for the acquisition of wide-coverage, blind-spot-free top-view images of vehicles, providing an important data source for vision-based traffic parameter extraction and event analysis.
[0030] However, current deep learning methods widely used in vehicle detection (such as YOLO, SSD, and Faster R-CNN) typically output rectangular bounding boxes aligned with the image coordinate axes. These boxes don't accurately reflect the vehicle's actual contour when the vehicle is rotated or at an angle to the imaging plane, failing to directly indicate the vehicle's direction of travel and unable to distinguish between the front and rear of the vehicle. For example, at intersections or in congested areas, vehicle orientations can change frequently, and relying solely on axis-aligned boxes makes it difficult to determine whether a vehicle is illegally turning, driving against traffic, or skidding, severely limiting the accuracy of subsequent advanced traffic semantic analysis. It's worth noting that although deep learning-based methods have been widely applied to vehicle detection and recognition in recent years, they often rely on a large number of manually labeled directional tags, resulting in high training costs and weak transfer adaptability.
[0031] To determine vehicle orientation, existing improvement solutions mainly fall into two categories: one is to introduce orientation-aware deep learning detection models (such as rotating object detectors). While these methods can output angular detection boxes, they rely on a large amount of accurate orientation-labeled data for training, resulting in high costs. Furthermore, the model's generalization ability is greatly affected by the distribution of training data, and its performance is prone to degradation under overhead views that differ from the training scenario. The other category is geometric methods based on vehicle key points or symmetry features. However, in actual overhead images, due to the similarity of vehicle top-view contours and the susceptibility of local features to occlusion or lighting effects, their stability and robustness face challenges.
[0032] In view of this, the present invention proposes an image-based vehicle orientation and head / tail recognition method, the method comprising: acquiring a target vehicle image and reading at least one set of vehicle information corresponding to the target vehicle image; the vehicle information includes at least: vertex coordinates of the initial rectangular bounding box of the vehicle corresponding to the target vehicle; performing edge detection on the target vehicle based on the target vehicle image to obtain a set of straight lines that meet preset conditions; the set of straight lines includes multiple straight lines corresponding to the length of the target vehicle body; determining the main orientation angle of the target vehicle based on the set of straight lines, and constructing a rotating rectangle that matches the outline of the target vehicle based on the main orientation angle and the vertex coordinates of the initial rectangular bounding box of the vehicle body; setting a dividing line based on the rotating rectangle, acquiring image corner points distributed on both sides of the dividing line, and determining the positions of the head and tail of the target vehicle based on the distribution of the image corner points.
[0033] Therefore, the present invention aims to provide an automatic vehicle direction and heading / tail direction determination method. It can automatically calculate the vehicle's rotation angle and heading / tail direction by fusing the straight line features of the vehicle's edges and the distribution features of corner points, even when only a conventional overhead image or detection box is provided. This results in an accurate output of a rotating rectangle that matches the vehicle's outline, improving the accuracy and semantic understanding of vehicle detection. It has high accuracy and engineering applicability, and can provide low-cost, easy-to-deploy, and highly available enhanced perception capabilities for intelligent transportation systems.
[0034] Please refer to the following. Figure 3 The flowchart shown in this embodiment illustrates a vehicle direction and head-and-tail recognition method based on images. The executing entity of this embodiment can be an intelligent transportation system, and no specific limitations are imposed. The following is a further explanation of each step of this invention, which includes the following steps: S100. Acquire the target vehicle image and read at least one set of vehicle information corresponding to the target vehicle image; the vehicle information includes at least the vertex coordinates of the initial bounding box of the vehicle corresponding to the target vehicle. The target vehicle image can be an overhead traffic image captured by equipment such as drones or high-altitude fixed surveillance cameras. After processing by any general object detection model (such as YOLO, Faster R-CNN, etc.), the resulting object detection image contains an initial bounding box around the vehicle. This initial bounding box is aligned with the image coordinate axes. See [link to relevant documentation] for details. Figure 1 The traditional target detection bounding box is shown.
[0035] The vehicle information here mainly refers to the vertex coordinates of the initial bounding box outside the target vehicle. However, it may also include information such as the aspect ratio of the initial bounding box outside the vehicle. No specific restrictions are imposed here. At the same time, since the number of vehicles contained in a target vehicle image is random, each detected vehicle has a corresponding set of vehicle information. For ease of understanding and explanation, we will take the reading of the vehicle information of the target vehicle as an example for further explanation.
[0036] Specifically, the vertex coordinates of the initial rectangular frame outside the vehicle can be found in [reference needed]. Figure 1 The traditional object detection bounding box uses the coordinates A, B, C, and D; simultaneously, the image coordinate system can be set with point D as the origin, and the line connecting points D and C extending horizontally to the right as the coordinate system. X The positive direction of the axis, with the line connecting points A and D pointing vertically upwards as... Y The coordinate system formed by the positive axis; of course, the image coordinate system can also be based on the center point of the target vehicle as the origin, with two mutually perpendicular straight lines drawn through that origin as the coordinates. X shaft and Y The axes (positive and negative directions can be set by technicians) are used to determine the vertex coordinates of the vehicle's external initial rectangle, since the initial rectangle is aligned with the image coordinate axes. The length and width of the traditional target detection rectangle can be used to determine the coordinates of the other image coordinate system settings.
[0037] S200. Based on the target vehicle image, perform edge detection and line detection on the target vehicle to obtain a set of lines that meet preset conditions; the set of lines includes multiple lines corresponding to the length of the target vehicle body; After obtaining the target vehicle image and the vehicle information corresponding to the target vehicle image, the present invention automatically extracts key straight line features that can characterize the orientation of the vehicle's main structure to assist in the subsequent accurate estimation of the target vehicle's main orientation angle.
[0038] To ensure accurate extraction of key straight line features, a series of image preprocessing and feature filtering operations were first performed on the target vehicle image during the extraction process. Noise and detail interference were filtered out from the complex original image, and finally a set of high-quality straight line segments that are highly correlated with the long side direction of the vehicle body were obtained.
[0039] Specifically, see Figure 4 The aforementioned step S200 includes the following steps: S201. Preprocess the target vehicle image to obtain the preprocessed target vehicle image; Specifically, in this embodiment of the invention, the preprocessing process for the target vehicle image is as follows: converting the target vehicle image into a grayscale image, and performing Gaussian filtering on the converted grayscale target vehicle image to obtain the processed target vehicle image.
[0040] First, the RGB three-channel information of the color target vehicle image is converted into single-channel brightness information, with each pixel value representing its grayscale intensity. In this way, subsequent image processing can be based on grayscale images for recognition and calculation, thereby reducing data dimensionality and computational load.
[0041] Gaussian filtering is a linear smoothing filter that uses a Gaussian function as a weight template to convolve an image. It can effectively suppress noise that follows a normal distribution while preserving edge information well. Therefore, Gaussian filtering of grayscale images can effectively smooth the image and suppress noise.
[0042] As can be seen, preprocessing the target vehicle image reduces the complexity of subsequent processing and effectively reduces the interference of image noise on edge detection, ensuring the stability and accuracy of subsequent edge extraction and providing a clean input for obtaining a clear vehicle structure outline.
[0043] S202. Use the Canny operator to perform edge detection on the processed target vehicle image to obtain an image with vehicle edge points; Among them, the Canny operator is a multi-stage optimized edge detection algorithm. Through Gaussian filtering smoothing, calculation of gradient magnitude and direction, non-maximum suppression, and double threshold detection and edge connection, it can output a single-pixel wide and well-connected edge. Therefore, the Canny operator can accurately locate the region with drastic intensity changes in the processed target vehicle image, and reliably draw multiple binary edge points associated with the outline of the target vehicle in the processed target vehicle image, that is, obtain the binary edge point image of the target vehicle, where the pixel value represents whether the point is an edge point.
[0044] S203. Apply probabilistic Hough transform to the image containing vehicle edges to detect the line segments contained therein and obtain a candidate set of line segments. The Hough transform can detect straight lines in an image through random sampling and can also directly return the coordinates of the endpoints of the line segments that make up these lines, which can effectively improve computational efficiency.
[0045] After obtaining the image with vehicle edge points through step S202, the probabilistic Hough transform is applied to detect potential straight line segments from the discrete edge points and obtain the start and end coordinates of each straight line segment to form an initial candidate set of straight line segments. It should be noted that the straight line segments in the current candidate set of straight line segments can directly correspond to components with obvious linear structures such as vehicle body (such as the lower edge of the door, roof) and windows.
[0046] S204. Sort the line segments in the candidate set of line segments according to the Manhattan length, and select a preset number of line segments in sequence according to the sorting results to form a line set.
[0047] Since the set of straight lines serves to determine the main orientation angle of the target vehicle, based on the prior knowledge that straight lines representing the length of the vehicle body are usually relatively long, this embodiment of the invention selects to filter the candidate set of straight line segments by Manhattan length. This method can more simply and efficiently eliminate short and trivial interference line segments caused by textures, stains or local details, retain the main structural lines that best represent the overall orientation of the vehicle, and effectively improve the robustness of subsequent orientation angle calculations.
[0048] For example, the Manhattan length is calculated as follows: For a line from endpoint and The Manhattan length of a defined line segment is calculated using the following formula: It reflects the extent of the line segment's extension in the image coordinate system.
[0049] Now suppose we have a candidate set of line segments sorted by Manhattan length. ,and Let be the Manhattan lengths of the line segments arranged in descending order. n=100 The preset quantity is set to 50% of the total straight line segments, so in the example, the preset quantity is 50; The following can be used to form a set of lines by selecting the first 50 line segments corresponding to Manhattan lengths from the candidate set of line segments sorted by Manhattan length.
[0050] It should be noted that in practical applications, the number of line segments in the candidate set is large. Setting the preset number to 50% of the total number of line segments and obtaining a number with decimals (discarding the decimals or rounding up) will not affect the selection of the overall line segments. For example, when the preset number is calculated to be 100.5, the line segments corresponding to the Manhattan lengths of the first 100 or the first 101 can be selected.
[0051] S300. Based on the set of lines, determine the main direction angle of the target vehicle, and based on the main direction angle and the vertex coordinates of the initial rectangular frame outside the vehicle, construct a rotating rectangle that matches the outline of the target vehicle. After obtaining the set of straight lines that best represent the overall orientation of the vehicle, the main direction angle of the vehicle can be determined by statistically analyzing the angles of the straight line segments within the set. Then, by combining the vertex coordinates of the initial rectangular frame outside the vehicle with the main direction angle, a rotating rectangle that matches and aligns with the actual contour of the vehicle can be constructed through geometric calculations.
[0052] In this embodiment of the invention, the principal direction angle is an angle value between [-90°, 90°), which is defined here as representing the direction of the vehicle's longitudinal axis (the direction of the line connecting the front and rear of the vehicle) in the image plane. X The directional angle between the positive axes, where 0° indicates that the target vehicle is pointing horizontally to the right, i.e., with... X The axis is horizontal; however, the specific setting method can be flexibly adjusted according to the actual application scenario. There is no special limitation here. It is only set for the sake of clarity in the following introduction. It can be understood as a functional parameter used to characterize the longitudinal axis direction of the target vehicle, with the main direction angle as the parameter.
[0053] Specifically, see Figure 5 The step S300, "determine the principal heading angle of the target vehicle based on the set of lines," includes the following: S301. Calculate the horizontal angles formed by all line segments in the set of lines, and remove all singular angles within the horizontal angles to obtain the filtered horizontal angle data. S302. Calculate the mean value based on the horizontal angle data, and use the horizontal angle corresponding to the mean value as the main direction angle of the target vehicle.
[0054] Considering that the most frequently occurring angle values or ranges in straight-line angle statistics represent the most common target vehicle heading, making it easier to determine the subsequent main direction angle, this embodiment of the invention further filters all straight-line segments within the straight-line set. It uses the method of statistically analyzing the horizontal angles formed by all straight-line segments in the image plane to remove straight-line segments corresponding to angles that deviate excessively from the mode, obtaining the filtered horizontal angle data. Here, singular angles are those that deviate excessively from the mode. For example, most straight-line segments correspond to a horizontal angle of approximately 45°, but if one or two straight-line segments correspond to a horizontal angle of 85°, then the data with a horizontal angle of 85° can be removed.
[0055] Specifically, the process of "removing line segments corresponding to angles that deviate too much from the mode" includes: First, calculating the mode and standard deviation of all statistically obtained horizontal angles, and then calculating the absolute offset of each horizontal angle relative to the mode; Next, setting a threshold of 1 standard deviation, and determining whether the absolute offset corresponding to each horizontal angle is less than the threshold, thereby filtering out horizontal angles that deviate too far from the main direction; This design takes into account that the mode is not affected by extreme values, and the standard deviation can measure the dispersion of the entire angle data distribution, thus effectively filtering out singular angles and obtaining accurate main direction angles.
[0056] Finally, after obtaining the filtered horizontal angle data, the principal direction angle can be obtained by averaging these horizontal angle data. For details, please refer to the following formula (1): Formula (1); in, Main direction angle; For the filtered horizontal angle data, the first i A horizontal angle; This represents the total number of horizontal angles.
[0057] As can be seen, through statistical analysis and outlier removal mechanisms, this method can effectively resist individual false detections of straight lines or interference from the vehicle's internal structure, thereby stably and accurately estimating the main direction angle representing the orientation of the target vehicle's main body, and also providing a reliable directional reference for the subsequent construction of the rotating rectangle.
[0058] Next, after determining the principal orientation angle of the target vehicle, a rotated rectangle matching the outline of the target vehicle can be constructed based on the principal orientation angle and the vertex coordinates of the initial rectangular frame outside the vehicle. This process specifically includes the following steps: S303. Obtain the vertex coordinates of the initial rectangle outside the vehicle, and determine the aspect ratio of the initial rectangle outside the vehicle based on the vertex coordinates. The vertex coordinates of the initial rectangle of the vehicle's exterior can be obtained directly from the vehicle information. After obtaining the coordinates of the four vertices, the aspect ratio of the initial rectangle of the vehicle's exterior can be calculated by explicitly calculating the ratio of the length to the width of the initial rectangle of the vehicle's exterior, or by directly comparing the pixel lengths of the longer and shorter sides of the initial rectangle of the vehicle's exterior. This will not be elaborated further here.
[0059] S304. Based on the aspect ratio, estimate the length and width of the minimum bounding rectangle corresponding to the target vehicle; See Figure 6 Once the aspect ratio is determined, the length and width of the minimum bounding rectangle corresponding to the target vehicle can be estimated. This process includes the following steps: S3041. Obtain the length and aspect ratio of the initial rectangular frame outside the vehicle; S3042. Compare the aspect ratio with the preset ratio range to determine the target aspect ratio of the minimum bounding rectangle; Furthermore, the process of comparing the aspect ratio with a preset ratio range to determine the target aspect ratio of the minimum bounding rectangle includes: if the aspect ratio is within the preset ratio range, the aspect ratio of the initial bounding rectangle of the vehicle's outer frame is used as the target aspect ratio of the minimum bounding rectangle; if the aspect ratio is less than the lower boundary value of the preset ratio range, the aspect ratios of the initial bounding rectangles of all auxiliary vehicles in the target vehicle image are obtained, averaged, and the average of the calculated aspect ratios is used as the target aspect ratio of the minimum bounding rectangle; wherein, the auxiliary vehicles are those whose aspect ratios of the initial bounding rectangles of all vehicles in the target vehicle image are within the preset ratio range.
[0060] In this embodiment of the invention, there are two cases regarding the confirmation of the target aspect ratio. Let's assume the aspect ratio of the initial rectangular frame outside the vehicle is... R (The aspect ratio is defined as the length of the initial rectangular frame outside the vehicle divided by the width of the initial rectangular frame outside the vehicle), with a preset ratio range of [missing information]. Two situations need to be explained: Scenario 1: If R In If the aspect ratio of the initial rectangular frame of the vehicle's exterior is considered reliable, then the target aspect ratio is directly set to equal... R That's all.
[0061] Scenario 2: If If the target vehicle is tilted or the detection box is abnormal, it indicates that the target vehicle may be in a severely tilted state. To correct this error, an auxiliary strategy is enabled. This involves statistically analyzing the aspect ratios of all other vehicles in the current target vehicle image whose aspect ratios are within a preset range (defined as auxiliary vehicles in this embodiment), calculating their arithmetic mean, and then setting the target aspect ratio to equal the calculated mean aspect ratio.
[0062] It should be noted that, The numerical range is set based on statistical data. For example, when the aspect ratio of the original bounding rectangle of a vehicle is approximately equal to the aspect ratio of the minimum bounding rectangle, the aspect ratio of the original bounding rectangle is considered to be within the range of 2:1 to 2.6:1 for most vehicles. Therefore, when the aspect ratio is... R When the value is less than 2, the above auxiliary strategy can be enabled.
[0063] It should be noted that if the aspect ratio is found to be less than the lower boundary value of the preset ratio range, but the target vehicle image does not contain any auxiliary vehicles, then an empirical value can be directly used as the target aspect ratio. The selection of this empirical value is determined by technical personnel, and its value is, for example, 2.25:1; no special limitations are imposed here. Furthermore, regarding the preset ratio range... The aforementioned "2:1~2.6:1" setting does not essentially include vehicle types with large length-to-width ratios, such as large buses and large trucks; however, since there are many types of vehicles, if it is applied to the detection of all vehicle types, in practical applications, the upper limit of the preset ratio range can be set to infinity.
[0064] As can be seen, by setting a physically reasonable threshold and utilizing statistical information within the scene, the embodiments of the present invention effectively filter out abnormal aspect ratios caused by extreme viewing angles or detection errors, ensuring the stability of the size estimation basis and improving the adaptability of the algorithm in complex scenes.
[0065] S3043. Using the length of the initial rectangular frame outside the vehicle as the length of the minimum bounding rectangle, calculate the width of the minimum bounding rectangle based on the target aspect ratio and the length of the minimum bounding rectangle.
[0066] Based on practical experience, the long side of the initial rectangle of the vehicle's outer edge is almost equal to or mostly within a reasonable error range of the long side of the minimum bounding rectangle of the target vehicle. For ease of calculation, the length of the initial rectangle of the vehicle's outer edge can be directly used as the length of the minimum bounding rectangle. In actual application scenarios (images taken from above), vehicles will experience perspective distortion (compression), and the initial rectangle of the vehicle's outer edge is generally slightly larger than the minimum bounding rectangle. Therefore, this approximation method can also compensate for the compression of the target vehicle caused by perspective distortion to a certain extent. Then, in the next step of calculation, given that the aspect ratio of the target and the length of the minimum bounding rectangle are known, the width of the minimum bounding rectangle can be calculated using the following formula (2): Formula (2); in, The width of the minimum bounding rectangle; The length of the minimum bounding rectangle; The target aspect ratio.
[0067] Therefore, the length and width of the minimum bounding rectangle are calculated.
[0068] As can be seen, this step utilizes the relationship between the length of the initial bounding rectangle of the vehicle and the minimum bounding rectangle corresponding to the target vehicle from a top-down perspective, simplifying the size estimation problem into an intuitive calculation, achieving extremely low computational complexity, and is very suitable for edge computing scenarios with high real-time requirements.
[0069] S305. Based on the principal direction angle, calculate the direction vector of the long side and the direction vector of the short side of the smallest bounding rectangle. Here, the long-side direction vector points towards the front / rear of the vehicle, while the short-side direction vector is perpendicular to it and points towards the side of the vehicle.
[0070] In calculating the direction vectors of the long and short sides of the minimum bounding rectangle, these vectors can be directly calculated by specifying the principal direction angle. Essentially, a pair of orthogonal unit vectors corresponding to a given angle are output to represent the long side direction vector. Since the long side direction vector is essentially the same as the principal direction angle, it can be directly defined by the trigonometric function of the principal direction angle. The specific calculation formula is: Long side direction vector... It is used to characterize the length direction vector of the vehicle body.
[0071] Next, since the long side direction vector is perpendicular to the short side direction vector, rotating the long side direction vector by 90° will give us the short side direction vector. The specific calculation formula is: Short side direction vector... It is used to characterize the rear side direction vector or can be understood as the width direction vector of the vehicle body.
[0072] S306. Obtain the center point of the initial rectangular frame outside the vehicle. Based on the center point of the rectangle, the length and width of the minimum bounding rectangle, the direction vector of the long side, and the direction vector of the short side, calculate the actual vertex coordinates used to construct the rotating rectangle to obtain the rotating rectangle.
[0073] Finally, constructing a rotating rectangle that matches the target vehicle's outline mainly requires defining the coordinates of the four actual vertices of the rotating rectangle (see details...). Figure 1 Given A1, B1, C1, and D1, the actual vertex coordinates used to construct the rotating rectangle can be calculated based on the previously known center point of the rectangle, the length and width of the minimum bounding rectangle, the direction vector of the long side, and the direction vector of the short side. It should be noted that after obtaining the above data, all the actual vertex coordinates can be directly calculated using the vertex calculation formula based on the center and axis.
[0074] For example, see Figure 8 In this schematic coordinate system used for calculation, the center point of the initial rectangular bounding box outside the vehicle is the center point of the subsequently constructed rotated rectangle, denoted as O, and its coordinates in the predefined image coordinate system are ( H2 , H1 The unit vector along the longer side is The unit vector in the short side direction is The length of the minimum bounding rectangle is L, and the width of the minimum bounding rectangle is W. Based on the length L and width W of the minimum bounding rectangle, calculate the half-length of the minimum bounding rectangle. hL and half width hW ,Right now: L / 2 = hL , W / 2 = hW ; The following example demonstrates how to determine the x-coordinate and y-coordinate of P1. Specifically, the x-coordinate of P1... and ordinate It is calculated using the following formula (3): Formula (3); in, and These are the x and y coordinates of P1, respectively; and These are the x and y coordinates of the vector along the longer side, respectively. and These are the x and y coordinates of the long side direction vector, respectively.
[0075] Specifically, see Figure 8 In calculating the x-coordinate of P1 At that time, through It can be calculated Figure 8 The length of the red edge plus the green edge; then through The length of the green edge can then be calculated, and the sum of the two is the length of the remaining red edge. Finally, using the known... H2 By combining the length of the red side with the calculated length, we can obtain the x-coordinate of P1. .
[0076] In calculating the ordinate of P1 At that time, through It can be calculated Figure 8 The length of the blue edge; then through The length of the yellow side can then be calculated, and the sum of the lengths of the blue side and the yellow side can be multiplied by... H1 By adding the lengths, we can obtain the x-coordinate of P2. .
[0077] Similarly, the x-coordinate of the remaining P2 and ordinate x-coordinate of P2 and ordinate x-coordinate of P2 and ordinate The results are obtained by using the following formulas (4), (5), and (6) respectively: Formula (4); Formula (5); Formula (6); Since the calculation principle is the same as the process described in P1 above, it will not be repeated here. Therefore, the actual vertex coordinates used to construct the rotating rectangle can be calculated using the above formulas (3)-(6), which is equivalent to calculating the actual vertex coordinates used to construct the rotating rectangle. Figure 1 By finding the actual vertex coordinates of A1, B1, C1, and D1, and then connecting A1, B1, C1, and D1 in sequence, a rotating rectangle matching the vehicle body contour can be obtained.
[0078] S400: Based on the rotation rectangle, set the dividing line, obtain the image corner points distributed on both sides of the dividing line, and determine the location of the head and tail of the target vehicle based on the distribution of the image corner points.
[0079] Since the identification of the head and tail of a vehicle can bring great convenience to accident determination or intelligent driving of vehicles in practical applications, after obtaining the rotating rectangle, this embodiment of the invention also proposes to determine the location of the head and tail of the target vehicle, that is, to assign semantic information of "head" and "tail" to the rotating rectangle that has the correct geometric orientation.
[0080] Specifically, in reality, from a top-down or oblique top-down perspective, the front of a vehicle typically includes: the leading edge of the body (the upper edge of the front bumper, the upper edge of the headlights, the outline and styling lines of the hood), the leading edge of the roof (the outline of the windshield and its reflective effects, vehicle inspection labels, etc., the wiper structure, the upper surface outline of the center console, possible trim pieces, sunroof structure), and the rearview mirrors, while the rear structure is relatively simple. This physical characteristic is reflected in the image features, where the density of corner points or keypoints in the area where the vehicle's front is located is usually significantly higher than that in the rear area.
[0081] Based on this, see Figure 7 Step S400, which involves setting a dividing line based on a rotated rectangle, acquiring image corner points distributed on both sides of the dividing line, and determining the locations of the head and rear of the target vehicle based on the distribution of these corner points, specifically includes the following steps: S401. Based on the rotating rectangle, construct a straight line that passes through the center of the rotating rectangle and is perpendicular to the main direction angle as a dividing line; Based on the rotating rectangle obtained in the previous steps, a straight line is constructed that passes through its geometric center and is perpendicular to the main direction angle (i.e., the direction of the long side of the rotating rectangle) as a dividing line (equivalent to the perpendicular bisector of the long side of the rotating rectangle). This dividing line divides the rotating rectangle region into two parts with equal areas.
[0082] S402. Using the dividing line as the boundary, use the corner point algorithm to obtain the image corner points distributed on both sides of the dividing line, count the number of corner points on both sides of the dividing line, and record them as the first corner point number and the second corner point number. S403. If the number of first corner points is greater than the number of second corner points, then the side corresponding to the number of first corner points is determined to be the front of the target vehicle, and the side corresponding to the number of second corner points is determined to be the rear of the target vehicle; otherwise, the side corresponding to the number of second corner points is determined to be the front of the target vehicle, and the side corresponding to the number of first corner points is determined to be the rear of the target vehicle.
[0083] Corner points are points in an image where the grayscale changes drastically in all directions. They are usually the corners of object edges, texture intersections, etc. For vehicles, the front of the car usually produces a dense number of corner points.
[0084] Within the rotated rectangular area, corner detection algorithms (such as the Shi-Tomasi algorithm) are used to extract image corners. Simultaneously, the number of corners falling on either side of the segmentation baseline is counted, denoted as the first corner count and the second corner count, facilitating subsequent comparison of the corner counts on both sides of the segmentation line. During the comparison, taking advantage of the characteristic that the corner density in the vehicle's head area is typically significantly higher than in the tail area, the side with a significantly higher corner count is identified as the target vehicle's head side; the other side is correspondingly identified as the target vehicle's tail side.
[0085] As can be seen, the embodiments of the present invention utilize the vehicle's own structural priors, without relying on complex models or additional labeled data, and solve the problem of automatic vehicle head and tail identification with low computational cost, so that the output results can directly serve advanced application scenarios such as trajectory analysis, behavior event detection and automated traffic accident analysis.
[0086] In a preferred embodiment, in order to standardize the semantic information output format so that downstream systems (such as trajectory trackers and behavior analysis modules) do not need to perform any direction parsing and can directly read the vehicle's direction of travel from the vertex order, the method further includes: Step G1: Take the coordinates of the two vertices of the rotating rectangle located at the head of the target vehicle as the head point of the rotating rectangle of the target vehicle, and take the coordinates of the two vertices of the rotating rectangle located at the tail of the target vehicle as the tail point of the rotating rectangle of the target vehicle. Step G2: Sort and output the head points and tail points of the rotating rectangle in a clockwise direction to construct a rotating rectangle with directional semantics.
[0087] Specifically, based on the clearly defined distribution positions of the target vehicle's front and rear, the previously calculated A1, B1, C1, and D1 will be output in sequence. In this embodiment of the invention, the actual vertex coordinates of the set rotating rectangle should follow the characteristic that the first two vertices represent the front side of the vehicle, the last two vertices represent the rear side of the vehicle, and the four vertices are arranged in a clockwise direction (see [reference]). Figure 2 (Coordinate adjustment in the middle).
[0088] pass Figure 2 As can be seen, if we follow the output method corresponding to the previous vehicle (A1, B1, C1, D1), we cannot directly determine the positions of the head and tail of the target vehicle. However, by setting the G1 and G2 in the above steps, after obtaining the output coordinates in the next step, we can directly determine that the positions of points A1 and B1 are the head of the vehicle, and the positions of points C1 and D1 are the tail of the vehicle. In this way, we can effectively simplify system integration and data interface, support batch processing and modular integration, embed it into the existing target detection system as a post-processing module, improve vehicle semantic understanding, and have strong engineering applicability.
[0089] Based on the above description, this invention proposes an image-based vehicle orientation and head / tail recognition method to address the problem that existing vehicle detection technologies can only output axis-aligned rectangles and cannot characterize the actual orientation and head / tail position of the vehicle. The method provided by this invention, in the form of a back-end processing module, is compatible with the output of existing mature detectors. Given only a standard overhead image and its corresponding vehicle detection box as input, it determines the principal orientation angle by extracting straight lines from the vehicle's edges, and then generates a rotating rectangle aligned with it. Utilizing prior knowledge of the more complex structure and richer corner features of the vehicle's head, it automatically and robustly identifies the front and rear sides of the vehicle by statistically analyzing the distribution density of image corner points on both sides of the perpendicular bisector of the rotating rectangle. Finally, it outputs a rotating rectangle with directional semantics, where the vertices are arranged in the order of head in front and tail in back.
[0090] This invention achieves technological advancements beyond simply detecting presence to understanding orientation and behavior, delivering outputs that combine geometric accuracy with directional semantics. At the application level, this technology provides directly usable key inputs for advanced analytical tasks such as vehicle trajectory tracking, automatic identification of traffic violations (e.g., driving against traffic, illegal U-turns), and traffic accident reconstruction and liability determination. At the engineering level, it does not rely on large-scale orientation annotation data or complex deep learning models; the algorithm is lightweight and efficient, making it particularly suitable for deployment in scenarios with limited computing resources, such as UAV-borne systems and edge computing devices. It can empower existing traffic monitoring systems at a lower cost, demonstrating significant practical value and market potential.
[0091] The above description is merely a preferred embodiment of the present invention and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of the invention is not limited to the specific combination of the above-described technical features, but also includes other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the inventive concept. For example, technical solutions formed by substituting the above-described features with (but not limited to) technical features with similar functions disclosed in this invention.
Claims
1. A method for vehicle orientation and head / tail recognition based on images, characterized in that, include: Acquire an image of the target vehicle and read at least one set of vehicle information corresponding to the target vehicle image; The vehicle information includes at least the vertex coordinates of the initial rectangular bounding box corresponding to the target vehicle. Based on the target vehicle image, edge detection and line detection are performed on the target vehicle to obtain a set of lines that meet preset conditions; the set of lines includes multiple lines corresponding to the length of the target vehicle body; Based on the set of lines, the main direction angle of the target vehicle is determined, and based on the main direction angle and the vertex coordinates of the initial rectangular frame outside the vehicle, a rotating rectangle that matches the outline of the target vehicle is constructed. Based on the rotating rectangle, a dividing line is set, and image corner points distributed on both sides of the dividing line are obtained. Based on the distribution of the image corner points, the locations of the head and tail of the target vehicle are determined. The process of constructing a rotated rectangle that matches the target vehicle's outline based on the principal orientation angle and the vertex coordinates of the initial rectangular frame outside the vehicle includes: Obtain the vertex coordinates of the initial rectangle outside the vehicle, and determine the aspect ratio of the initial rectangle outside the vehicle based on the vertex coordinates; Based on the aspect ratio, the length and width of the minimum bounding rectangle corresponding to the target vehicle are estimated. Based on the principal direction angle, the long side direction vector and the short side direction vector of the minimum bounding rectangle are calculated. Obtain the center point of the initial rectangular frame outside the vehicle. Based on the center point, the length and width of the minimum bounding rectangle, the direction vector of the long side, and the direction vector of the short side, calculate the actual vertex coordinates used to construct the rotating rectangle to obtain the rotating rectangle. The step of setting a dividing line based on the rotated rectangle, acquiring image corner points distributed on both sides of the dividing line, and determining the location of the head and rear of the target vehicle based on the distribution of the image corner points includes: Based on the rotating rectangle, a straight line passing through the center of the rotating rectangle and perpendicular to the main direction angle is constructed as a dividing line; Using the dividing line as the boundary, the corner points distributed on both sides of the dividing line are obtained using a corner point algorithm. The number of corner points on both sides of the dividing line is counted and recorded as the first corner point number and the second corner point number. If the number of the first corner points is greater than the number of the second corner points, then the side corresponding to the number of the first corner points is determined to be the front of the target vehicle, and the side corresponding to the number of the second corner points is determined to be the rear of the target vehicle; otherwise, then the side corresponding to the number of the second corner points is determined to be the front of the target vehicle, and the side corresponding to the number of the first corner points is determined to be the rear of the target vehicle.
2. The image-based vehicle direction and head / tail recognition method according to claim 1, characterized in that, The step of performing edge detection and line detection on the target vehicle image to obtain a set of lines that meet preset conditions includes: The target vehicle image is preprocessed to obtain a preprocessed target vehicle image; The Canny operator is used to perform edge detection on the processed target vehicle image to obtain an image with vehicle edge points. Apply the probabilistic Hough transform to the image containing vehicle edge points to detect the line segments contained therein, and obtain a candidate set of line segments; The line segments in the candidate set of line segments are sorted according to their Manhattan length, and a preset number of line segments are selected in sequence according to the sorting results to form the line set.
3. The image-based vehicle direction and head / tail recognition method according to claim 2, characterized in that, The step of preprocessing the target vehicle image to obtain a preprocessed target vehicle image includes: The target vehicle image is converted into a grayscale image, and a Gaussian filter is applied to the grayscale target vehicle image to obtain the processed target vehicle image.
4. The image-based vehicle direction and head / tail recognition method according to claim 2, characterized in that, Determining the principal heading angle of the target vehicle based on the set of lines includes: The horizontal angles formed by all line segments within the set of lines are counted, and all singular angles within the horizontal angles are removed to obtain the filtered horizontal angle data. The mean of the horizontal angle data is calculated, and the horizontal angle corresponding to the mean is taken as the main direction angle of the target vehicle.
5. The image-based vehicle direction and head / tail recognition method according to claim 1, characterized in that, The process of estimating the length and width of the minimum bounding rectangle corresponding to the target vehicle based on the aspect ratio includes: Obtain the length and aspect ratio of the initial rectangular frame outside the vehicle; The aspect ratio is compared with a preset ratio range to determine the target aspect ratio of the minimum bounding rectangle; The length of the initial rectangular frame outside the vehicle is used as the length of the minimum bounding rectangle. The width of the minimum bounding rectangle is calculated based on the target length-to-width ratio and the length of the minimum bounding rectangle.
6. The image-based vehicle direction and head / tail recognition method according to claim 5, characterized in that, The step of comparing the aspect ratio with a preset ratio range to determine the target aspect ratio of the minimum bounding rectangle includes: If the aspect ratio is within a preset range, the aspect ratio of the initial rectangular frame outside the vehicle is taken as the target aspect ratio of the minimum bounding rectangle. If the aspect ratio is less than the lower boundary value of the preset ratio range, the aspect ratios of the initial bounding rectangles of all auxiliary vehicles in the target vehicle image are averaged and the average aspect ratio is used as the target aspect ratio of the minimum bounding rectangle; wherein, the auxiliary vehicle is a vehicle whose aspect ratio of the initial bounding rectangles of all vehicles in the target vehicle image is within the preset ratio range.
7. The image-based vehicle direction and head / tail recognition method according to claim 1, characterized in that, After determining the locations of the front and rear of the target vehicle, the method further includes: The coordinates of the two actual vertices of the rotating rectangle located at the head of the target vehicle are taken as the head point of the rotating rectangle of the target vehicle, and the coordinates of the two actual vertices of the rotating rectangle located at the tail of the target vehicle are taken as the tail point of the rotating rectangle of the target vehicle. The head and tail points of the rotating rectangle are sorted and output in a clockwise direction to construct a rotating rectangle with directional semantics.