Machine vision-based highway traffic flow detection system
2026-04-06 03:49:33··#1
Introduction With the increasing population, the pressure on transportation is growing, making intelligent transportation systems a hot research topic in recent years. Traffic flow detection is a fundamental part of intelligent transportation and plays a crucial role in the system. Currently, there are various methods for detecting traffic flow, such as electromagnetic induction and ultrasonic detection of traffic information. However, in reality, the speed and type of moving vehicles are constantly changing, resulting in unstable reflected signals and large measurement errors. Compared with the above methods, video-based traffic flow detection methods have many advantages: extracting reliable information from video images to complete road traffic monitoring improves the automation level of roads and vehicles; installing video cameras in traffic monitoring and control systems is more economical and less destructive than installing other sensors; many cameras are already installed in actual road traffic systems for road traffic monitoring and control, achieving two goals at once. Existing traditional video detection methods are based on industrial control computers, with mature algorithms and related products. However, they also have disadvantages: firstly, because general-purpose CPUs do not have dedicated hardware multipliers, it is difficult to achieve real-time image processing. Secondly, using a general-purpose industrial control computer running a Windows system is costly and requires constant monitoring for machine crashes, virus infections, and operating system patch upgrades. Based on these two points, this paper proposes an embedded image recognition solution based on the TMS320DM642 (hereinafter referred to as DM642), solving these problems. The Principle and Composition of a Traffic Flow Detection SystemWorking Principle of a Traffic Flow Detection System The traffic flow detection system consists of several parts: video acquisition, digital video signal processing of traffic flow, traffic flow detection algorithms under different environments, and output of traffic flow detection results. The core chip of the digital image acquisition part is the TVP5150, which can convert analog video signals into digital video signals. The DM642 runs image algorithms to perform digital image processing on the acquired images. The digital video detection algorithm for traffic flow mainly uses the improved frame difference method for motion detection during the day and the vehicle headlight detection method at night. The acquired highway image is divided into four parts according to lanes, each part corresponding to one lane. A virtual coil (a rectangular detection area in the image, collectively referred to as a virtual coil) is set up in each lane. When a vehicle crosses the virtual coil, the pixel value within the virtual coil changes. Based on this change, the I/O port is controlled to generate corresponding pulses for each lane. After processing, the pulses are sent to the highway traffic signal controller to control the traffic lights, thereby achieving the goal of intelligent traffic. Simultaneously, traffic flow information can be transmitted to the monitoring center via the network. The hardware of the traffic flow detection system, the DM642, is a digital signal processing chip designed by Texas Instruments specifically for multi-channel video input/output. Its powerful computing capabilities, built on a second-generation high-performance very long instruction word (VLSI) architecture, allow for the parallel execution of eight instructions, making this chip highly suitable for digital image processing. Considering the requirements of practical operation and system stability, the DM642's main frequency is set to 600MHz. Based on the actual application environment and the needs of the embedded system, in addition to expanding the necessary memory and video acquisition/playback sections, the system mainly expands the multi-channel digital I/O, asynchronous serial port, and network interface functions to facilitate communication with external systems. The specific hardware is shown in Figure 1. The specifications are as follows: External SDRAM with a capacity of 4M×64 bits; External Flash with a capacity of 4M×8 bits; 2 PAL/NTSC standard analog video inputs (CVBS or S-terminal), 1 PAL/NTSC standard analog video output; 8 digital I/O ports expanded via CPLD for outputting traffic flow information on the lanes; 2 UART interfaces, configurable according to RS232/RS422/RS485 standards; Real-time clock (RTC) + watchdog circuit; 10M/100M base-TX standard Ethernet interface. [align=center] Figure 1 Hardware Physical Diagram[/align] The system composition is shown in Figure 2. In the figure, the TMS320DM642 expands the external memory section through a 64-bit wide EMIF (External Memory Interface) bus, including 32Mbytes of Synchronous DRAM, used to store user code and image data during actual operation. A 4Mbyte Flash memory is used to store the bootloader and user applications. During startup, the code and data in the Flash are loaded into main memory (SDRAM). User configuration parameters for the virtual coil can also be stored in the Flash. The SDRAM data width is 64 bits, and the Flash data width is 8 bits, corresponding to the CE0 and CE1 spaces of the TMS320DM642, respectively. Similarly, the Universal Asynchronous Receiver (UART) and the Complex Programmable Logic Device (CPLD) are also connected to the DM642 via the EMIF bus. The UART is used to expand the serial port; in this system, it can be used to expand the RS232 interface. The CPLD is used to implement the glue logic between the Flash and UART and to expand general-purpose digital I/O. For ease of software implementation, these two parts are also connected to the CE1 space of the DM642, with their internal registers serving as part of the CE1 storage space. [align=center] [/align] Video Acquisition and Output Section To collect traffic flow information at the intersection, this system is designed with two analog video inputs. The system converts the analog video signal captured by the camera into a digital video stream using a TVP5150 according to ITU-R BT.656, and sends the embedded synchronization signal to the VP1 and VP2 ports of the DM642. The horizontal and vertical synchronization signals of the image are embedded in the EAV and SAV time base signals in the video data stream; the video port only needs the video sampling clock and sampling enable signal. The DM642 can achieve three-frame continuous acquisition of digital video images via FIFO. While one frame is being processed, the other two buffers can still achieve cyclic acquisition of images, thus resolving the contradiction between constant-speed video acquisition and variable-speed image processing. This system expands to include one video output for local playback; this function can be discontinued after system debugging is complete. The video output is implemented using the Phillips (now NXP) SAA7121 chip. The SAA7121 converts the digital video signal from the DM642's VP0 port into a PAL (50Hz) or NTSC (60Hz) analog signal for external video port output. Software ComponentsTraffic Flow Statistics Algorithm Due to the significant variations in road surface light intensity between day and night, the algorithm's adaptability is greatly enhanced. To obtain traffic flow information throughout the day, the algorithm processes daytime and nighttime traffic separately. The program automatically switches between the two algorithms based on the varying light conditions, ensuring a smooth operating environment for the entire algorithm. [align=center]Figure 3: Nighttime Algorithm Flowchart[/align] * Selection of Virtual Coils The selection of virtual coils affects the accuracy and speed of the detection algorithm and is influenced by the camera's installation height and tilt angle, as well as the camera's depth of field. Generally, virtual coils are placed near the bottom of the image where vehicle spacing is larger, facilitating detection. Larger virtual coils generally result in higher detection accuracy, but also longer algorithm execution time. Since the system needs to adapt to various intersections and road surfaces, the selection of virtual coils is left to the user. We developed PC software using VC6.0, allowing users to set the size and position of virtual coils for each lane via serial port. * **Time Interval Between Adjacent Detection Frames:** Since the entire system needs to communicate with the traffic signal controller, the total processing time for images on each road must not exceed 0.25 seconds. Here, a frame interval of 0.125 seconds is chosen. * **Traffic Flow Detection Algorithm:** The improved frame difference method is already well-established on PCs during the day. As shown in Formula 1: i=1,2,3,......80, j="1",2,3,......10 In Formula 1, E stores the average value of the detection window after frame difference, R is the grayscale value of the detection window in the current frame, R' is the grayscale value of the detection window in the previous frame, and m and n are the length and width of the virtual coil, which will not be elaborated further here. * **At Night:** Road visibility is relatively low, and the algorithm mainly focuses on vehicle headlight recognition. At night, vehicle headlights are very bright, so as long as the headlights are detected correctly, vehicle measurement can be performed. The interference in the algorithm comes from the reflection of light emitted by vehicle headlights from the road surface. After simulation experiments using Matlab, it was found that after binarization and denoising, the bright spots of the headlights are basically the shape of the headlights, while the road surface reflection area diverges forward. Therefore, headlights and road surface reflection areas can be identified by detecting the shape features of the bright spots on the window. The nighttime algorithm is shown in Figure 2, the nighttime algorithm flowchart. The threshold for binarizing the virtual coil was selected using Otsu's method. Compared with the empirical method, Otsu's method obtains the threshold by calculating the variance, which has stronger environmental adaptability, but this also increases the time and space complexity of the algorithm. Image denoising uses a 3×3 median filter, and we improved it with a fast algorithm, applying it only to the virtual coil. The original grayscale image of the road surface is shown in Figure 4, and Figure 5 shows its binarized image. The rectangular area in the figure is the virtual coil, and there are two white areas within the coil. Using pixels as the unit, the maximum aspect ratio of the white area is used to determine whether it is a headlight. The length of the white area corresponding to the headlight is generally less than or equal to the width, as shown in Figure 6. The length of the white area corresponding to the road surface reflection is greater than the width, as shown in Figure 9. The white area within the virtual coil is the road surface reflection. [align=center]Figure 4 Nighttime road surface grayscale image[/align] [align=center]Figure 5 Road surface binarized image[/align] [align=center]Figure 6 Virtual coil[/align] System software framework based on DSP/BIOS The system software development environment is CCS, using the DSP/BIOS kernel provided by TI and the RF5 software reference framework advocated by TI. Input, processing, and output threads are configured through DSP/BIOS, and synchronization between these threads is achieved through semaphores. Using the DSP/BIOS kernel, configuring DSP/BIOS is convenient and easy to modify, offering many advantages over traditional methods. Using the RF5 (Reference Framework 5) DSP software architecture significantly shortens development time while maximizing code portability and robustness. The software architecture, from bottom to top, consists of CSL (Chip Support Library), DSP/BIOS and Driver layer, signal processing library layer, and algorithm standard layer. These three layers constitute RF5, with the top layer being the user application layer. Users can easily modify and maintain the code, requiring only changes to the upper layers. The input driver uses the FVID class driver provided by TI, as shown in Figure 10. This driver configures the DM642's IIC module to the video acquisition port and the A/D conversion chip TVP5150 through structure configuration parameters, enabling the TVP5150 to output a PAL digital video stream and write the acquired image to a designated memory area through the video port's FIFO. After image acquisition is complete, a message is sent to the processing module via semaphore. The message structure stores the starting address of the memory space where the image data is located. The input module then waits for a reply from the output module to continue processing the next frame of the image. The processing module is responsible for executing the traffic flow statistics algorithm. It extracts the image data address from the message structure sent by the input module for image algorithm processing. The calculation result is output through the I/O port extended by the CPLD, transmitting the traffic flow monitoring information to the traffic signal controller. Code Optimization The program is mainly written in C language. Some core code has been optimized using assembly language to meet real-time requirements. The quality of C language program optimization directly affects program efficiency. The program extensively uses space-for-time tradeoffs to improve code execution efficiency. There are many methods for code optimization, the main ones being: compiler optimization, selecting different compilation optimization options during compilation, such as the -pm-oe option; optimizing C language code, adding commonly used indicative information such as #Pragma MUST_ITERATE; writing linear assembly programs to improve program execution speed; and writing assembly programs to implement software pipelining. Pipelining can be achieved using various techniques, such as dependency graphs and iteration interval timing tables. These are described in detail in TI's technical documentation and will not be repeated here. [align=center] Figure 7 Video Acquisition Driver Structure[/align] Experimental Results and Analysis To verify the reliability of the traffic flow detection system, the algorithm was ported into the detection system, and actual detection experiments were conducted using cameras mounted on tripods on multiple highway overpasses. Due to the number of pedestrians on the overpasses, the overpasses swayed slightly, affecting the stability of the cameras. Additionally, vehicle straddling caused some errors in the detection results, but the detection effect was still good. A set of tests is shown in Table 1, showing the traffic flow detection results. Under natural conditions, the acquired image size was 720×576. The daytime measurements were taken at 3:27 PM and the evening measurements at 6:50 PM, under clear weather conditions. The test location was two lanes on Xueyuan Road in Haidian District, Beijing. A 1/3-inch CCD was used. The lens focal length was 3.5–8 mm, and the maximum aperture ratio was 1:1.4. [align=center]Table 1 Traffic Flow Detection Results[/align] Table 1 shows that the daytime video detection results were slightly better. At night, the shape and brightness of vehicle lights varied significantly, resulting in some error, but the system's recognition accuracy remained above 80%. The experiment demonstrates that this method has high detection accuracy, low implementation cost, and reliable system operation. References: 1. TI, TMS320DM642 Video/Imaging Fixed-point Digital Signal Processor (Literature Number: SPRS200F) [Z]. Dallas: TI, 2004. 2. Anon, TMS320DM642 Evaluation Module Technical Reference SPECTRUM DIGITAL [Z]. [SL]:INC.2003. 3. Li Fanghui, TMS320C6000 Series DSPs Principles and Applications (Second Edition) [M], Beijing: Electronic Industry Press, 2003. 4. TI. TMS320C6000 DSP External Memory Interface Reference Guide (Literature Number: SPRU266B) [Z]. Dallas:TI, 2004. 5. TI. TMS320C64x Image/Video Processing Library Programmer's Reference (Literature Number: SPRU023B) [Z]. Dallas:TI, 2003. 6. Chen Bingqi, Practical Image Processing in Visual C++, Beijing: Tsinghua University Press, 2004. 7. TI.TMS320C6000 DSP/BIOS Application Programming Interface (API) Reference Guide (Literature Number: SPRU403F) [Z]. Dallas:TI, 2004.