A traffic light detection method and system based on dynamic pixel region
By using a traffic light detection method based on dynamic pixel regions, the pixel positions of the traffic light frame are obtained and local processing is performed, which solves the problems of large computational load, low accuracy and insufficient real-time performance in the existing technology, and realizes efficient and real-time traffic light detection.
Patent Information
- Application Number
- CN202611264840.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-19
- Publication Date
- 2026-11-27
AI Technical Summary
Existing traffic signal detection solutions involve large computational loads and low detection accuracy, failing to meet real-time requirements. Furthermore, their reliance on roadside equipment results in communication delays and coverage blind spots.
A traffic light detection method based on dynamic pixel regions is adopted. By obtaining the pixel position of the traffic light frame, the pixel region containing the traffic light frame is extracted, and state detection is performed in the region. Combining visual perception and deep learning algorithms, the extracted region is dynamically adjusted to optimize computing resources.
It significantly reduces computing power consumption, improves detection accuracy and robustness, is highly adaptable, has good real-time performance, can quickly lock onto targets, adapts to stationary or moving traffic lights, and reduces computing load to improve system performance.
Smart Images

Figure CN123182181A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of intelligent vehicle perception technology. Specifically, this invention relates to a traffic light detection method and system based on dynamic pixel regions. Background Technology
[0002] Existing traffic signal detection solutions mainly have the following two technical approaches and their shortcomings:
[0003] Full-image feature extraction method: This method uses a high-resolution camera to acquire image data and directly feeds the entire high-resolution image into the perception algorithm. This results in a very large data processing volume for the perception algorithm. This not only increases computational power consumption and occupies a significant amount of memory resources on the computing platform, but also leads to a decrease in inference speed, failing to meet real-time requirements.
[0004] Image scaling preprocessing: Before inputting the image into the perception algorithm, the high-resolution image is scaled. Downsampling during image scaling leads to a decrease in image resolution. Traffic lights are inherently small, occupying a small percentage of pixels in the image. After scaling, the texture details and other information of the traffic lights are significantly distorted, making it difficult to extract true and comprehensive feature information and reducing the perception algorithm's ability.
[0005] In addition, some systems rely on V2X technology to obtain traffic light status, but this depends on the construction of roadside equipment and has communication delays and coverage blind spots, and cannot independently solve the real-time perception needs of the vehicle. Summary of the Invention
[0006] This invention aims to overcome the shortcomings of existing technologies and proposes a traffic light detection method and system based on dynamic pixel regions to achieve the following objectives: solving the technical problems of high computational consumption, low detection accuracy, and low efficiency in processing high-resolution images in existing traffic light detection technologies. By introducing the concept of dynamic pixel regions, fine processing is performed only on local regions containing the target in the image, thereby significantly reducing computational complexity while improving detection accuracy.
[0007] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0008] This invention provides a traffic light detection method based on dynamic pixel regions, the method comprising:
[0009] Step S1: Obtain the pixel position of the traffic light frame in the image;
[0010] Step S2: Based on the pixel position of the traffic light frame, extract the pixel region containing the traffic light frame from the image;
[0011] Step S3: Detect the traffic light status based on the extracted pixel region.
[0012] Furthermore, methods for obtaining the pixel position of the traffic light frame in an image include: obtaining the pixel position of the traffic light frame in an image captured at the current location based on the current location of the vehicle; and obtaining the pixel position of the traffic light frame in an image based on visual perception.
[0013] Furthermore, methods for obtaining the pixel positions of traffic light frames in an image based on visual perception include: obtaining the pixel positions of traffic light frames based on pixel-by-pixel search and feature matching.
[0014] Furthermore, the method for obtaining the pixel position of the traffic light frame in an image based on visual perception includes: inputting the image into a preset perception algorithm, and obtaining the pixel position of the traffic light frame based on the perception algorithm.
[0015] Furthermore, the perception algorithm includes the YOLO-Nano target detection network.
[0016] Furthermore, when obtaining the pixel position of the traffic light frame in the image based on visual perception, for images with a resolution greater than a preset resolution, the original image is divided into multiple small image blocks. The pixel position of the traffic light frame in each image block is obtained independently based on visual perception. Finally, the position acquisition results of each block are summarized and merged to obtain the pixel position of the traffic light frame in the original image.
[0017] Furthermore, the method of obtaining the pixel position of the traffic light frame in the image based on visual perception is enabled only when the distance between the vehicle's location and the target traffic light is less than a preset distance threshold.
[0018] Furthermore, based on the vehicle's current location, the pixel position of the traffic light frame in the image captured at the current location is obtained, including: matching the pixel position of the traffic light frame in the image captured at the current location from the historical database according to the vehicle's current location.
[0019] Furthermore, based on the vehicle's current location, the pixel position of the traffic light frame in the image captured at the current location is obtained, including: based on the vehicle's current location and driving information, obtaining the three-dimensional position information of the traffic light frame from the map information and projecting it onto the image coordinate system to obtain the pixel position of the traffic light frame in the image captured at the current location.
[0020] Furthermore, step S2 includes:
[0021] Step S21: During the first image cutout, a preset image cutout method is used to cut out the image based on the pixel position of the traffic light frame;
[0022] Step S22: The position selection method for each subsequent cutout is to update the pixel position of the traffic light frame based on the preset target tracking algorithm, and then use the preset cutout method to cut out the image based on the updated pixel position of the traffic light frame.
[0023] Furthermore, the preset image cutout method includes: maintaining the pixel position of the traffic light frame in the center of the cutout area, as expressed by the following formula:
[0024] ;
[0025] ;
[0026] The pixel position of the traffic light frame is... , The coordinates of the top left corner Width and height; cutout area is , The coordinates of the top left corner For width and height.
[0027] Furthermore, the preset method for selecting the cutout location includes: using an adaptive expansion algorithm to determine the size of the cutout area, expressed by the following formula:
[0028] ;
[0029] ;
[0030] in, and For safety reasons, background context is reserved; , Indicates the width and height of the traffic light frame; , This indicates the width and height of the cutout area.
[0031] Furthermore, in step S3, the traffic light status detection method includes: obtaining traffic light status information based on a pixel-by-pixel search and feature matching method.
[0032] Furthermore, in step S3, the traffic light status detection method includes: obtaining traffic light status information based on a preset deep learning algorithm.
[0033] Furthermore, the deep learning algorithm includes ResNet50.
[0034] This invention provides a traffic light detection system based on dynamic pixel regions. Using the aforementioned traffic light detection method based on dynamic pixel regions, the system includes:
[0035] The traffic light frame pixel position acquisition module is used to acquire the pixel position of the traffic light frame.
[0036] The image cutout module is used to cut out the pixel region containing the traffic light frame from the image based on the pixel position of the traffic light frame;
[0037] The status detection module is used to detect the status of traffic lights based on the extracted pixel regions.
[0038] The present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the above-described traffic light detection method based on dynamic pixel regions.
[0039] This invention provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the aforementioned traffic light detection method based on dynamic pixel regions.
[0040] The technical effects of this invention are as follows:
[0041] The beneficial effects of this invention are mainly reflected in the following three aspects:
[0042] (1) Significantly reduce computational power consumption: The computational complexity of deep learning models is directly proportional to the amount of pixel data in the input image. By inferring from a small dynamic region containing only traffic lights, the amount of pixel data in the input model is reduced to a very small part of the original image (e.g., in a two-million-pixel resolution image, the pixel width and height of traffic lights are usually within 60 to 180 pixels, and the pixel ratio of the traffic light frame is usually within 2%), thereby significantly reducing the computational power consumption of the vehicle's GPU or CPU.
[0043] (2) Improved detection accuracy and robustness: Because it retains high-resolution information of the target area, it can completely preserve the texture details, luminous intensity and other information of the traffic signal indicator. Compared with shrinking the whole image before detection, this invention avoids the loss of features of the traffic signal indicator due to compression, thereby improving the perception capability in long-distance, low-brightness and high-noise environments.
[0044] (3) Strong adaptability and good real-time performance: By dynamically adjusting the matting area, the system can quickly lock onto the target, whether it is a stationary traffic light or a moving vehicle; the low computational load enables the system to run at a higher frame rate, providing more real-time perception information for decision-making and control. Attached Figure Description
[0045] Figure 1 A flowchart of a traffic light detection method based on dynamic pixel regions provided in an embodiment of the present invention;
[0046] Figure 2 This is a diagram illustrating the architecture of a traffic light detection system based on dynamic pixel regions, provided as an embodiment of the present invention. Detailed Implementation
[0047] The specific embodiments of the present invention will be further described in detail below with reference to the accompanying drawings. This is to help those skilled in the art to have a more complete, accurate, and in-depth understanding of the inventive concept and technical solutions of the present invention, and to facilitate its implementation. It should be noted that the terms "first," "second," etc., used in this application are only for the convenience of describing the technical solutions and to distinguish components; the corresponding component configurations may be the same or different, and are not intended to limit the scope of this application. To make the technical solutions of the present invention clearer, the present invention will be explained and illustrated through the following embodiments.
[0048] This invention provides a traffic light detection method based on dynamic pixel regions. By dynamically determining the pixel position of the traffic light frame and extracting the pixel region containing the traffic light frame based on the position, the traffic light status is detected based on the extracted pixel region. This achieves dynamic updating of the detection area and optimized allocation of computing resources, effectively solving the technical problems of large global processing computation, insufficient robustness, and inflexible resource scheduling in the prior art.
[0049] like Figure 1 As shown, the present invention provides a traffic light detection method based on dynamic pixel regions, the specific method flow of which includes:
[0050] Step S1: Obtain the pixel position of the traffic light frame in the image;
[0051] Step S2: Based on the pixel position of the traffic light frame, extract the pixel region containing the traffic light frame from the image;
[0052] Step S3: Detect the traffic light status based on the extracted pixel region.
[0053] The design principle of this invention is as follows: instead of performing global processing on the entire image, the pixel positions of the traffic light frames are first obtained. Then, the pixel regions containing the traffic light frames are dynamically extracted based on these positions. Finally, traffic light status detection is performed only within these pixel regions. This "localize first, focus then recognize" processing flow concentrates computational resources on the region of interest, significantly reducing the computational load, while ensuring the continuity and accuracy of detection through a dynamic update mechanism.
[0054] This invention also provides various methods for obtaining the pixel positions of traffic light frames, including prior information acquisition based on vehicle position and real-time detection acquisition based on visual perception, enabling reliable pixel position information to be obtained in different scenarios. Regarding visual perception, this invention supports pixel-by-pixel search and feature matching methods and deep learning object detection methods, and proposes a block processing strategy for high-resolution images and a distance threshold triggering mechanism for long-distance scenes, achieving intelligent scheduling of computing resources.
[0055] Regarding pixel region extraction, this invention proposes a dynamic update mechanism based on a target tracking algorithm, enabling the extraction position to be updated in real time as the traffic light moves within the image. Simultaneously, this invention innovatively proposes an adaptive expansion algorithm that dynamically determines the size of the extraction region based on the actual size of the traffic light frame, while reserving background context information. This ensures complete inclusion of the traffic light while avoiding excessive background interference.
[0056] In traffic light status detection, this invention supports both traditional methods based on pixel-by-pixel search and feature matching, and modern methods based on deep learning. Users can flexibly choose according to the actual scenario and computing resources. Deep learning methods perform inference on the extracted pixel regions, with smaller input image sizes and less background interference, resulting in better recognition accuracy and inference speed than whole-image inference methods.
[0057] Specifically, referring to step S1, the pixel position of the traffic light frame is obtained in the image. In an autonomous driving system, the onboard camera continuously acquires images of the road ahead. These images contain rich road environment information, among which traffic lights are one of the key targets that autonomous vehicles must accurately perceive. The core task of step S1 is to determine the pixel position of the traffic light frame in the current frame image, that is, to determine the bounding box information of the traffic light in the image coordinate system.
[0058] Step S1 of this embodiment provides two main types of methods for obtaining the pixel position of traffic light frames in images: obtaining the pixel position of traffic light frames in images captured at the current location based on the current location of the vehicle; and obtaining the pixel position of traffic light frames in images based on visual perception.
[0059] These two methods can be used independently or in combination to improve the reliability and accuracy of location acquisition. When results from both methods are available, strategies such as weighted fusion, confidence filtering, or cross-validation can be employed to determine the final pixel location. For example, if the difference between the pixel location obtained based on vehicle location and the pixel location obtained based on visual perception is less than a preset threshold, they are considered to be consistent, and the average value is taken as the final location. If the difference is greater than the preset threshold, the result with higher confidence is prioritized, or an anomaly handling mechanism is activated for further verification. The vehicle location-based method can still provide reliable location estimates under adverse visual conditions (such as heavy fog, heavy rain, or direct sunlight), serving as a supplement and backup to visual perception. The visual perception-based method can correct map projection errors in real time and adapt to changes in the road environment (such as the addition of traffic lights or adjustments to traffic light positions). The following sections provide a detailed explanation of the two methods.
[0060] This method, which determines the pixel position of the traffic light frame in an image captured at the current vehicle location, utilizes the vehicle's location information and prior knowledge (such as map data and historical data) to identify the pixel position of the traffic light frame. It is a non-visual perception method. Its advantage lies in its independence from the image quality of the current frame, providing reliable position estimation even under poor visual conditions. Specifically, it includes the following two implementation methods:
[0061] (1) Based on the current location of the vehicle, match the pixel position of the traffic light frame in the image collected at the current location from the historical database.
[0062] The core idea of this approach is to pre-establish a historical database that records the pixel positions of traffic light frames in images captured from different vehicle locations. The process of building this historical database is as follows: During daily vehicle operation, the vehicle's position (obtained through sensors such as GPS, IMU, and wheel speedometers) and the corresponding pixel positions of traffic light frames in the images are continuously recorded (detected through visual perception algorithms). This data is then cleaned, deduplicated, and clustered to form the historical database. Each record in the database includes: vehicle location (latitude and longitude or local coordinates), direction of travel, traffic light ID, traffic light frame pixel position, recording timestamp, and confidence level.
[0063] In actual operation, when a vehicle approaches a certain location, the system queries the historical database for historical records of that location and nearby locations. Query criteria include: the vehicle's current location (within a certain radius, such as 50 meters), current direction of travel (within a certain angle, such as ±30°), and current time. The query results may contain multiple records. The system weights and sorts these records based on factors such as confidence level, timestamp, and distance, selecting the best record as the estimated pixel position of the traffic light frame in the current frame.
[0064] The technical advantages of method (1) are as follows: First, it does not require running complex visual perception algorithms in real time, resulting in extremely low computational load and extremely fast response speed; Second, it can still provide reliable location estimation when visual conditions are poor (such as no streetlights at night, heavy fog, heavy rain, etc.), serving as an effective supplement to visual perception; Third, as the vehicle's mileage increases, the historical database continues to accumulate, and the accuracy and coverage of location estimation continue to improve; Fourth, through multi-vehicle data sharing (such as uploading and downloading historical data through the vehicle network), the database content can be further enriched, and the system's generalization ability can be improved.
[0065] (2) Based on the vehicle’s current location and driving information, obtain the three-dimensional position information of the traffic light frame from the map information and project it onto the image coordinate system to obtain the pixel position of the traffic light frame in the image collected at the current location.
[0066] The core idea of this method is to utilize the 3D location information of traffic lights stored in high-precision maps, combined with the vehicle's current position and camera parameters, to project the 3D world coordinates onto a 2D image coordinate system through coordinate transformation, thereby obtaining the pixel position of the traffic light frame. The specific steps are as follows:
[0067] First, the 3D world coordinates of the target traffic light are obtained from a high-precision map. High-precision maps typically contain 3D models of road infrastructure, including the traffic light's location (latitude, longitude, and elevation), frame size, light head arrangement, and orientation. Map data is collected and produced using specialized surveying vehicles, achieving centimeter-level accuracy.
[0068] Secondly, the vehicle's current position and attitude are acquired. The vehicle position is obtained through the fusion of sensors such as GPS / RTK, IMU, and wheel speedometer, including three-dimensional coordinates (x, y, z) and attitude angles (roll, pitch, yaw). The vehicle attitude describes the transformation relationship between the vehicle coordinate system and the world coordinate system.
[0069] Next, coordinate transformation is performed. Coordinate transformation includes three steps: transformation from the world coordinate system to the vehicle coordinate system, transformation from the vehicle coordinate system to the camera coordinate system, and transformation from the camera coordinate system to the image coordinate system. The transformation from the world coordinate system to the vehicle coordinate system is determined by the vehicle's position and attitude; the transformation from the vehicle coordinate system to the camera coordinate system is determined by the camera's mounting position (extrinsic parameter); and the transformation from the camera coordinate system to the image coordinate system is determined by the camera's intrinsic parameters (focal length, principal point, distortion coefficients, etc.). Combining these three transformations, the projection matrix P from the world coordinate system to the image coordinate system is obtained.
[0070] Finally, the 3D corner coordinates of the traffic light are projected onto the image plane using the projection matrix P to obtain the pixel coordinates. Based on the projected corner coordinates, the pixel positions of the traffic light frame are then calculated.
[0071] The technical advantages of method (2) are as follows: First, by utilizing the prior information of high-precision maps, the accuracy of location acquisition is high (the error is usually within a few pixels) and is not affected by image quality; Second, the calculation speed is fast, and the coordinate transformation is a simple matrix multiplication, with a computational load far less than that of visual perception algorithms; Third, it can acquire the three-dimensional information of traffic lights (such as distance and height), providing rich context for subsequent driving decisions; Fourth, the type of traffic lights (such as disc lights, arrow lights, countdown lights, etc.) can be known in advance through map data, which helps in the targeted processing of subsequent state detection.
[0072] This method obtains the pixel positions of traffic light frames in images based on visual perception. It directly analyzes the current frame image and detects the position of the traffic lights using a visual perception algorithm. Its advantage lies in its independence from map data and vehicle positioning accuracy, allowing it to adapt to changes in the road environment. Specifically, it includes two implementation methods: obtaining the pixel positions of traffic light frames based on pixel-by-pixel search and feature matching; and inputting the image into a preset perception algorithm, using the algorithm to infer the pixel positions of the traffic light frames.
[0073] Obtaining the pixel positions of traffic light frames based on pixel-by-pixel lookup and feature matching is a traditional computer vision method, suitable for those with limited computing resources or as a supplement to deep learning methods. The specific steps are as follows:
[0074] First, the image is preprocessed, including noise reduction (such as Gaussian filtering), color space conversion (such as RGB to HSV), contrast enhancement, and other operations, to improve the robustness of subsequent processing.
[0075] Secondly, color segmentation is performed. In the HSV color space, the image is thresholded based on the Hue value ranges of red, yellow, and green to obtain candidate region masks for the three colors.
[0076] Then, morphological processing is performed on the candidate region mask (such as opening operations to remove noise and closing operations to fill holes), and connected components are extracted. Each connected component corresponds to a color candidate region.
[0077] Next, shape feature matching is performed. Standard traffic lights have specific shape characteristics: the light frame is usually circular or rectangular, and the light heads are arranged in three vertically aligned circular areas (red, yellow, and green from top to bottom), with a border around the light frame. Based on this prior knowledge, shape analysis is performed on each connected component: the area, perimeter, circularity, aspect ratio, centroid position, and other features of the region are calculated; it is determined whether the region conforms to the shape characteristics of the traffic light heads (e.g., circularity close to 1, area within a certain range); and it is determined whether multiple candidate regions are vertically aligned and the spacing conforms to the standard traffic light head spacing.
[0078] Finally, the pixel positions of the traffic light frames are determined by combining candidate regions that meet the shape feature matching criteria. The combination method is as follows: take the smallest bounding rectangle of all matching light heads, and expand it appropriately to include the frame border.
[0079] The advantages of using a pixel-by-pixel search and feature matching method to obtain the pixel position of traffic light frames are as follows: First, it eliminates the need to train a deep learning model, resulting in low computational complexity and enabling real-time operation on embedded devices. Second, it demonstrates good detection performance for traffic lights of specific colors and shapes, with transparent recognition logic that facilitates debugging. Third, by combining color and shape features, it achieves a low false detection rate. Fourth, it is suitable for detecting standard traffic lights, and non-standard traffic lights can be adapted by adjusting shape feature parameters.
[0080] The image is input into a preset perception algorithm, and the pixel positions of the traffic light frames are obtained based on the perception algorithm. This method belongs to deep learning object detection and is suitable for scenarios with high detection accuracy requirements. In this embodiment, the perception algorithm uses the YOLO-Nano object detection network. YOLO-Nano is a lightweight version of the YOLO series of object detection algorithms, designed specifically for edge devices and embedded platforms. While maintaining high detection accuracy, it significantly reduces the number of model parameters and computational cost. The YOLO-Nano network structure is based on the simplified and optimized architecture of YOLOv4 or YOLOv5. Its main features include: using a lighter backbone network; reducing the number of layers and channels in the feature pyramid network; using a more efficient detection head design; and introducing knowledge distillation technology, using a large teacher model to guide the training of a small student model, enabling the small model to achieve performance close to that of the large model.
[0081] In practice, the current frame image is input into the YOLO-Nano network, which outputs detection boxes for all targets in the image through a single forward propagation. Each detection box contains at least five pieces of information: center coordinates, width, height, confidence score, and class probability. The network output undergoes non-maximum suppression post-processing to remove overlapping detection boxes and retain the detection results with the highest confidence scores. Finally, the pixel positions and detection confidence scores of the traffic light boxes are obtained.
[0082] The technical advantages of using a pre-defined perception algorithm to infer the pixel positions of traffic light frames are as follows: First, high detection accuracy; the YOLO-Nano network can accurately detect traffic lights of various sizes and postures. Second, fast inference speed; meeting real-time requirements. Third, a lightweight network with small model size and low parameter count, facilitating deployment on in-vehicle devices. Fourth, end-to-end detection; no manual design of color and shape features is required; the model automatically learns the optimal feature representation, demonstrating strong adaptability. Fifth, through knowledge distillation, the YOLO-Nano network achieves a balance between accuracy and efficiency, with small models performing close to large models.
[0083] In existing technologies, deep learning object detection models typically have fixed input size limitations (e.g., YOLO series models are usually 416×416, 608×608, 640×640, etc.). When the original image resolution (e.g., 1920×1080, 3840×2160) is much larger than the model input size, a global scaling approach is usually used to scale the image to the model input size. However, this global scaling approach has a serious problem: for small targets at a distance in a high-resolution image (e.g., distant traffic lights), the scaled target size may be only a few pixels, or even smaller than a single grid cell, causing the model to fail to detect the target. This is the main reason for the missed detection of distant traffic lights in existing technologies. To address this, this embodiment further proposes an image block processing strategy. For images with an original image resolution greater than a preset resolution, the original image is divided into multiple small image blocks. Each image block independently obtains the pixel position of the traffic light frame based on visual perception. Finally, the position acquisition results of each block are summarized and fused to obtain the pixel position of the traffic light frame in the original image. The specific steps are as follows:
[0084] First, determine if the original image resolution is greater than a preset resolution threshold (e.g., 1920×1080). If so, initiate block processing; otherwise, process the entire image directly.
[0085] Secondly, the original image is segmented into multiple small image blocks. Segmentation strategies can include uniform grid segmentation or overlapping region segmentation. Uniform grid segmentation divides the image into M×N blocks (e.g., 2×2, 3×3, etc.), with each block being 1 / M×1 / N of the original image size. Overlapping region segmentation, based on uniform segmentation, sets overlapping regions (overlap ratio, for example, 20%) between adjacent blocks to avoid truncation when the target is located at the block boundary.
[0086] Then, the pixel positions of traffic light detection boxes are independently obtained for each image patch based on visual perception. For example, each image patch is scaled to the model input size and fed into the YOLO-Nano network for inference to obtain the traffic light detection boxes within that patch. The coordinates of the detection boxes are local coordinates relative to the image patch and need to be converted to global coordinates relative to the original image.
[0087] Finally, the positions of each block are summarized and merged to obtain the results. The summarization process includes: collecting the detection results of all image blocks; removing duplicate detections in overlapping areas; and applying non-maximum suppression to the deduplicated detection results to obtain the pixel positions of the traffic light frames in the final original image.
[0088] The technical advantages of the image segmentation strategy are as follows: First, it effectively solves the problem of missed detection of small targets at a distance in high-resolution images. Second, segmentation results in each image block containing less background information, making it easier for the model to focus on the target within the block, thus improving detection accuracy. Third, inference for each image block can be performed in parallel (e.g., on a multi-core CPU or multi-GPU), fully utilizing the hardware's parallel computing capabilities, with overall inference time comparable to or even faster than whole-image inference. Fourth, the segmentation strategy is flexible and adjustable, dynamically adjusting the number of blocks and overlap ratio according to image resolution and target size to adapt to different scenario requirements.
[0089] In existing technologies, visual perception algorithms typically run in every frame, regardless of the vehicle's distance from the traffic light. When the vehicle is far from the traffic light (e.g., more than 200 meters), the traffic light appears very small in the image (possibly only a few pixels), making accurate detection difficult for the visual perception algorithm. Furthermore, the traffic light status has little impact on the current driving decision (the vehicle doesn't need to immediately make a stop or proceed decision), resulting in wasted computational resources for visual detection. In autonomous driving systems, computational resources are limited, requiring the simultaneous handling of multiple tasks such as lane detection, obstacle detection, and pedestrian detection. Inappropriate resource allocation will negatively impact overall system performance. Therefore, this embodiment introduces a distance threshold triggering mechanism, which only activates the method of obtaining the pixel position of the traffic light frame in the image based on visual perception when the distance between the vehicle's location and the target traffic light is less than a preset distance threshold.
[0090] The technical benefits of this distance threshold triggering mechanism are as follows: First, it enables intelligent scheduling of computing resources, saving computational overhead on visual perception algorithms at long distances and allocating resources to other more urgent perception tasks, thus improving overall system performance. Second, it avoids invalid detection of small targets at long distances, reducing noise caused by false positives and false negatives, and improving the reliability of detection results. Third, combined with vehicle location-based methods, it can still provide approximate location information of traffic lights at long distances, ensuring system continuity. Fourth, the distance threshold can be dynamically adjusted according to the scenario; for example, a larger threshold can be set on highways, while a smaller threshold can be set on urban roads, adapting to the needs of different driving scenarios.
[0091] Referring to step S2, based on the pixel position of the traffic light frame, the pixel region containing the traffic light frame is extracted from the image. After obtaining the pixel position of the traffic light frame, the task of step S2 is to extract the pixel region containing the traffic light frame from the original image based on this position information, as input for subsequent traffic light status detection. In this embodiment, step S2 adopts a dynamic pixel region extraction strategy, which not only includes the traffic light frame itself, but also reserves an appropriate background context area, and dynamically updates the extraction position through a target tracking algorithm, effectively solving the above problems. Specifically, step S2 includes the following sub-steps:
[0092] Step S21: During the first image cutout, a preset image cutout method is used to cut out the image based on the pixel position of the traffic light frame.
[0093] After initially obtaining the pixel position of the traffic light frame (e.g., the first frame after system startup, or the first frame detected again after tracking was lost), initial image matting is required based on that position. In this embodiment, the preset image matting method includes two core elements: determining the matting position and determining the size of the matting area.
[0094] Regarding the determination of the cutout position, this embodiment proposes to keep the pixel position of the traffic light frame in the middle of the cutout area, which is expressed by the following formula:
[0095] ; ;
[0096] The pixel position of the traffic light frame is... , The coordinates of the top left corner Width and height; cutout area is , The coordinates of the top left corner Here, the width and height are given. The physical meaning of this formula is: by calculating the offset between the center point of the traffic light frame and the center point of the cutout region, the traffic light frame is precisely placed at the center of the cutout region. The advantages of this are: First, when the traffic light frame shifts slightly in the image (due to vehicle movement or detection errors), as long as the offset does not exceed the reserved boundary width, the traffic light remains completely within the cutout region, avoiding truncation issues; Second, the centrally symmetrical placement ensures that the reserved background context around the traffic light is evenly distributed in all directions, which is beneficial for subsequent recognition models to fully utilize contextual information for judgment; Third, the unified placement rule ensures that the input images across different frames have a consistent spatial structure, which is beneficial for deep learning models to extract stable features.
[0097] Regarding the determination of the size of the cutout region, this embodiment uses an adaptive expansion algorithm to determine the size of the cutout region, which is expressed by the following formula:
[0098] ;
[0099] ;
[0100] in, and For safety reasons, background context is reserved; , Indicates the width and height of the traffic light frame; , This represents the width and height of the cutout area. The core idea of this adaptive expansion algorithm is that the width and height of the cutout area are jointly determined by the size of the traffic light frame and a safety factor. (Safety factor) and It is usually set to a value greater than 1 (e.g., =1.2, =1.5), indicating that 50% expansion space is reserved in both the width and height directions of the traffic light frame. When , When the area is small (such as a distant traffic light), even after multiplying by a safety factor, the cutout area is still small, and the computational load is controllable; when , When the image is large (such as a traffic light at close range), the max function ensures that the cutout area is at least the same size as the traffic light frame to avoid truncation.
[0101] The technical advantages of the adaptive scaling algorithm provided in this embodiment are as follows: First, it dynamically adjusts the matting area according to the actual size of the traffic light, avoiding the problems caused by a fixed-size matting area, so that the system can obtain the optimal input area under various distance conditions; Second, by reserving background context through a safety factor, it provides rich environmental information for subsequent recognition, which helps to distinguish traffic lights from similar targets and improves recognition accuracy; Third, the adaptive matting area size makes the use of computing resources more reasonable and avoids unnecessary computational waste.
[0102] Step S22: The position selection method for each subsequent cutout is to update the pixel position of the traffic light frame based on the preset target tracking algorithm, and then use the preset cutout method to cut out the image based on the updated pixel position of the traffic light frame.
[0103] After the initial image matting, subsequent frames do not re-perform global detection to obtain the traffic light frame position. Instead, the pixel position of the traffic light frame is dynamically updated based on a preset target tracking algorithm. In existing technologies, a common approach is to re-run the target detection algorithm for each frame. While this method can ensure detection accuracy, it involves a huge amount of computation, and the detection results between frames may exhibit jitter (differences in the position and size of the detection box for the same target in adjacent frames), leading to instability in the input image content.
[0104] In this embodiment, target tracking algorithms (such as KCF, MOSSE, CSRT, SiamFC, etc.) are used to track the traffic light frames. The core idea of the target tracking algorithm is: after the initial position of the target is given in the first frame, the position of the target in the current frame is predicted in subsequent frames based on the target's motion characteristics (such as color histogram, HOG features, deep learning features, etc.) and inter-frame motion models (such as Kalman filtering, particle filtering, etc.). Compared with re-detection in each frame, the target tracking algorithm significantly reduces the computational load and the tracking results have better continuity between frames, avoiding the detection jitter problem.
[0105] The technical effects of step S22 are as follows: First, by replacing re-detection every frame with a target tracking algorithm, the computational load is significantly reduced, meeting the stringent real-time requirements of autonomous driving systems. Second, the inter-frame continuity of the tracking results ensures the stability of the matted region, and the smooth changes in the input image content between frames are conducive to the output of stable recognition results by the state recognition model, avoiding the problem of inter-frame flickering. Third, when the target is briefly occluded or disturbed by sudden changes in illumination, the tracking algorithm can use the motion model to maintain tracking, improving the robustness of the system. Fourth, the tracking algorithm only performs local searches near the predicted position, avoiding the computational waste caused by global scanning and achieving optimized allocation of computing resources.
[0106] It should be noted that target tracking algorithms suffer from a drift problem, meaning that after prolonged tracking, the tracking bounding box may gradually deviate from the actual target position. To address this issue, this embodiment employs a detection-tracking fusion strategy: every preset number of frames (e.g., every 10 frames), the visual perception algorithm is re-run to obtain the pixel positions of the traffic light boxes, and the detection results are used to correct the tracker's state, preventing drift accumulation.
[0107] Referring to step S3, the traffic light status is detected based on the extracted pixel region. After extracting the pixel region containing the traffic light frame in step S2, the task of step S3 is to detect the current status of the traffic light (e.g., red, green, yellow, flashing, etc.) within that pixel region. In existing technologies, traffic light status detection is usually performed on the entire image or a large region of interest. This approach has the following problems: First, the input image size is large, resulting in long inference time for the deep learning model, making it difficult to meet real-time requirements; second, the image contains a large amount of irrelevant background information, making the model susceptible to background interference and causing misidentification (e.g., identifying a red billboard as a red light); third, when there are multiple traffic lights in the image, the model may confuse the states of different traffic lights, leading to output errors.
[0108] In this embodiment, step S3 performs state detection based on the pixel region extracted in step S2. This pixel region has the following advantages: First, the region size is small, the inference time of the deep learning model is short, and the real-time performance is high; Second, the content of the region is carefully selected, centered on the traffic light and containing an appropriate amount of background context, which avoids interference from irrelevant backgrounds and retains contextual information that helps in the judgment; Third, each pixel region corresponds to an independent traffic light, avoiding the problem of multi-target confusion.
[0109] In this embodiment, the traffic light status detection method includes two implementation methods, which users can flexibly choose according to the actual application scenario and computing resources: obtaining traffic light status information based on pixel-by-pixel search and feature matching; and obtaining traffic light status information based on a preset deep learning algorithm.
[0110] Obtaining traffic light status information based on pixel-by-pixel search and feature matching is a traditional image processing method, suitable for scenarios with limited computing resources or requiring rapid prototype verification. Specific steps include:
[0111] First, the extracted pixel region undergoes color space conversion, transforming the RGB image to the HSV color space. The HSV color space separates color information from luminance information, making color judgment more robust to changes in lighting conditions. In the HSV space, red, yellow, and green each correspond to different Hue value ranges.
[0112] Secondly, pixels belonging to the red, yellow, and green color ranges are searched pixel by pixel in the HSV image, and the number of pixels of each color is counted. To avoid noise interference, morphological processing (such as opening and closing operations) is performed on the search results to remove isolated noise points and fill small holes.
[0113] Then, the traffic light status is determined based on feature matching. Features include color distribution features (the proportion of each color pixel), spatial distribution features (the position and shape of the lit area), and temporal features (the pattern of state change between the current frame and the previous frame). For example, if the number of red pixels exceeds a preset threshold and the red pixels are concentrated in the upper area of the traffic light (corresponding to the red light position), the current state is determined to be red; if the number of green pixels exceeds a preset threshold and is concentrated in the lower area, the current state is determined to be green.
[0114] Finally, the analysis is validated using prior knowledge of the traffic light's structure. Standard traffic lights typically have a fixed arrangement of the lights (e.g., red, yellow, green from top to bottom), and only one light is lit at a time (except when flashing). Using this prior knowledge, the initial judgment can be verified and corrected, improving the accuracy of the identification.
[0115] The advantages of using a pixel-by-pixel search and feature matching method to obtain traffic light status information are as follows: First, it has low computational complexity, requiring no deep learning model training and can run in real time on embedded devices; second, it has low hardware requirements and is suitable for scenarios with limited computing resources; third, the recognition logic is transparent, facilitating debugging and optimization; and fourth, by combining color space and morphological processing, it has a certain degree of robustness to changes in illumination.
[0116] Obtaining traffic light status information based on a pre-defined deep learning algorithm is a modern deep learning method suitable for scenarios requiring high recognition accuracy. In this embodiment, the deep learning algorithm uses ResNet50 as the backbone network. ResNet50 solves the gradient vanishing problem in deep networks by introducing residual connections, allowing the network to be trained to deeper layers, thereby extracting richer and more abstract image features.
[0117] Specifically, the pixel region extracted in step S2 is input into the ResNet50 network.
[0118] First, feature extraction is performed through convolutional and pooling layers to obtain a high-dimensional feature map;
[0119] Then, the feature map is converted into a feature vector through a global average pooling layer;
[0120] Secondly, the classification results and their confidence scores for each state (red, green, yellow, blinking red, blinking green, etc.) are output through fully connected layers and the Softmax activation function;
[0121] Finally, the classification results are filtered by confidence to remove low-confidence predictions. If the recognition results are consistent across multiple consecutive frames, the signal light status is confirmed as valid and uploaded to the vehicle control layer. Due to the significant reduction in input image size (e.g., from 1920x1080 to 100x100 or 200x200), the ResNet50 network can operate easily and accurately classify light colors based on high-precision raw pixel values.
[0122] The advantages of using a pre-defined deep learning algorithm to obtain traffic light status information are as follows: First, high recognition accuracy. ResNet50, pre-trained on large datasets such as ImageNet, has powerful feature extraction capabilities and can learn the complex visual features of traffic lights, thus improving recognition accuracy. Second, strong robustness. The deep learning model has good adaptability to complex scenarios such as changes in lighting, weather, and partial occlusion. Third, end-to-end recognition. No manual design of color and shape features is required; the model automatically learns the optimal feature representation. Fourth, good scalability. By increasing training data or adjusting the network structure, it can be easily extended to new types of traffic lights (such as arrow lights, countdown lights, etc.).
[0123] It should be noted that, in practice, the deep learning algorithm used is not limited to ResNet50; other network structures can also be employed. ResNet50 was chosen because it achieves a good balance between accuracy and computational cost, making it suitable for deployment on in-vehicle computing platforms. If computational resources are more abundant, deeper networks can be selected to further improve accuracy; if computational resources are limited, lightweight networks can be chosen to improve inference speed.
[0124] This embodiment also provides a traffic light detection system based on dynamic pixel regions, using the aforementioned traffic light detection method based on dynamic pixel regions, such as... Figure 2 As shown, the system includes:
[0125] The traffic light frame pixel position acquisition module is used to acquire the pixel position of the traffic light frame.
[0126] The image cutout module is used to cut out the pixel region containing the traffic light frame from the image based on the pixel position of the traffic light frame;
[0127] The status detection module is used to detect the status of traffic lights based on the extracted pixel regions.
[0128] This embodiment also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the above-described traffic light detection method based on dynamic pixel regions.
[0129] This embodiment also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the above-described traffic light detection method based on dynamic pixel regions.
[0130] The present invention has been described above by way of example with reference to the accompanying drawings. Obviously, the specific implementation of the present invention is not limited to the above-described manner. Any non-substantial improvements made using the inventive concept and technical solution; or the direct application of the inventive concept and technical solution to other situations without modification, are all within the protection scope of the present invention.
Claims
1. A traffic light detection method based on dynamic pixel regions, characterized in that: The method includes: Step S1: Obtain the pixel position of the traffic light frame in the image; Step S2: Based on the pixel position of the traffic light frame, extract the pixel region containing the traffic light frame from the image; Step S3: Detect the traffic light status based on the extracted pixel region.
2. The traffic light detection method based on dynamic pixel regions according to claim 1, characterized in that: Methods for obtaining the pixel position of traffic light frames in an image include: obtaining the pixel position of the traffic light frame in an image captured at the current location of the vehicle; and obtaining the pixel position of the traffic light frame in an image based on visual perception.
3. The traffic light detection method based on dynamic pixel regions according to claim 2, characterized in that: Methods for obtaining the pixel position of traffic light frames in an image based on visual perception include: obtaining the pixel position of traffic light frames based on pixel-by-pixel search and feature matching.
4. The traffic light detection method based on dynamic pixel regions according to claim 2, characterized in that: A method for obtaining the pixel position of a traffic light frame in an image based on visual perception includes: inputting the image into a preset perception algorithm, and obtaining the pixel position of the traffic light frame based on the perception algorithm.
5. The traffic light detection method based on dynamic pixel regions according to claim 4, characterized in that: The perception algorithm includes the YOLO-Nano target detection network.
6. A traffic light detection method based on dynamic pixel regions according to any one of claims 2-5, characterized in that: When obtaining the pixel position of the traffic light frame in an image based on visual perception, for images with a resolution greater than a preset resolution, the original image is divided into multiple small image blocks. The pixel position of the traffic light frame in each image block is obtained independently based on visual perception. Finally, the position acquisition results of each block are summarized and merged to obtain the pixel position of the traffic light frame in the original image.
7. A traffic light detection method based on dynamic pixel regions according to any one of claims 2-5, characterized in that: The method of obtaining the pixel position of the traffic light frame in the image based on visual perception is enabled only when the distance between the vehicle's location and the target traffic light is less than a preset distance threshold.
8. The traffic light detection method based on dynamic pixel regions according to claim 2, characterized in that: Obtaining the pixel position of the traffic light frame in the image captured at the current location based on the vehicle's current location includes: matching the pixel position of the traffic light frame in the image captured at the current location from the historical database according to the vehicle's current location.
9. The traffic light detection method based on dynamic pixel regions according to claim 2, characterized in that: Obtaining the pixel position of the traffic light frame in the image captured at the current location based on the vehicle's current location includes: obtaining the three-dimensional position information of the traffic light frame from the map information based on the vehicle's current location and driving information, and projecting it onto the image coordinate system to obtain the pixel position of the traffic light frame in the image captured at the current location.
10. The traffic light detection method based on dynamic pixel regions according to claim 1, characterized in that: Step S2 includes: Step S21: During the first image cutout, a preset image cutout method is used to cut out the image based on the pixel position of the traffic light frame; Step S22: The position selection method for each subsequent cutout is to update the pixel position of the traffic light frame based on the preset target tracking algorithm, and then use the preset cutout method to cut out the image based on the updated pixel position of the traffic light frame.
11. The traffic light detection method based on dynamic pixel regions according to claim 10, characterized in that: The preset image cutout method includes: maintaining the pixel position of the traffic light frame in the center of the cutout area, as expressed by the following formula: ; ; The pixel position of the traffic light frame is... , The coordinates of the top left corner Width and height; cutout area is , The coordinates of the top left corner For width and height.
12. The traffic light detection method based on dynamic pixel regions according to claim 10, characterized in that: The preset method for selecting the cutout location includes: using an adaptive expansion algorithm to determine the size of the cutout area, expressed by the following formula: ; ; in, and For safety reasons, background context is reserved; , Indicates the width and height of the traffic light frame; , This indicates the width and height of the cutout area.
13. The traffic light detection method based on dynamic pixel regions according to claim 1, characterized in that: In step S3, the traffic light status detection method includes: obtaining traffic light status information based on pixel-by-pixel search and feature matching.
14. The traffic light detection method based on dynamic pixel regions according to claim 1, characterized in that: In step S3, the traffic light status detection method includes: obtaining traffic light status information based on a preset deep learning algorithm.
15. The traffic light detection method based on dynamic pixel regions according to claim 14, characterized in that: The deep learning algorithm includes ResNet50.
16. A traffic light detection system based on dynamic pixel regions, using the traffic light detection method based on dynamic pixel regions according to any one of claims 1-15, characterized in that: The system includes: The traffic light frame pixel position acquisition module is used to acquire the pixel position of the traffic light frame. The image cutout module is used to cut out the pixel region containing the traffic light frame from the image based on the pixel position of the traffic light frame; The status detection module is used to detect the status of traffic lights based on the extracted pixel regions.
17. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the traffic light detection method based on dynamic pixel regions as described in any one of claims 1-15.
18. A computer-readable storage medium storing a computer program thereon, characterized in that, The computer program, when executed by the processor, performs a traffic light detection method based on dynamic pixel regions as described in any one of claims 1-15.
