Vehicle Speed Detection Based on Video at Urban Intersection

: In order to obtain the average speed of vehicle at plane intersection on urban traffic, an algorithm of average speed measurement based on the video is proposed in this study. Video is captured against the motion of the vehicle by the camera which is mounted on the cross bar at the intersection. The detection zone is set between the stop line and the pedestrian road. These methods of background difference, shadow removal and region filling of morphology are applied to detection zone. Then, method of vertical projection is employed to the obtained binary image, judging whether the vehicles exist in the detection region by vertical projection diagram and calculating the total frames that the vehicle drive into and depart out the detection region. The instantaneous velocity is obtained by using the frame rate of the camera and the width of the detection region and then to calculate the mean velocity.


INTRODUCTION
Plane intersection (intersection for short) as an organization form of urban traffic plays an important role in urban traffic.With the increase of the traffic flow, the low traffic efficiency of intersection causes low average velocity and even congestion and then leads to severe traffic congestion in city as a whole.Many crossing facilities are re-designed such as urban rail or flyover-crossing to solve the problem of low traffic efficiency in many cities.However, the city construction has historical inheritance so that not all intersections are suitable to develop flyover-crossing traffic.Plane intersections still are the majority in city intersections.Therefore, the mean velocity of intersections is the key to intelligent traffic system.
There are many methods of measuring speed, such as induction loop detector, radar detector and videobased solution: • Induction loop detector (Ki, 2011), which has high accuracy but would damage the road when the induction coil is buried.So it is easy to be crushed and difficult to be repair • Radar detector (Wang et al., 2010), which has the capacity to detect the speed of several lanes simultaneously with high precision, but the cost is too expensive • Video-based detection, which not only contains large amount of information but also, is of low cost.This method has become the main research subject of intelligent transportation system (ITS).Literature (Huang et al., 2005), points out that the displacement image is obtained by license plate location.This method is of low precision and relies on the accuracy of the license plate location.
Because vehicles move slowly and the distance of them is small at intersection, the license plate is sheltered easily and located difficulty and then the vehicle speed detection is easy to be missed and mistaken.In literature (Cheng et al., 2005;Zhang and Zhang, 2010), 2 virtual detection lines on the video image of the detection region are used to replace the buried coil underground.Vehicle speed can be calculated according to the real distance between 2 virtual lines and the time it takes for the vehicle to pass through 2 virtual detection lines.The velocity error decreases as the length of detection zone increases.However, the increase of detection zone's length affects the accuracy of distance measurement because of the restrictions of image resolution.At the same time, the algorithm will be invalid when 2 or more vehicles appear inside the 2 virtual lines.
In addition, the existing vehicle velocity measurement method based on computer vision is only applied to the speed measurement of highway and express way, the speed of which is faster and the vehicle spacing is larger.The vehicles of urban intersections are guided by cross-light and move slowly (the maximum speed is generally not more than 60 km/h), so the distance between them is smaller.Because the existing vehicle velocity measurement method is not suitable to be applied in urban intersections, the method based on single detection zone is proposed in this study.This study mainly covers the following parts: introduction, the principle of vehicle velocity measurement, camera calibration and setting the detection zone, vehicle detection and time determination, speed determination.

THE PRINCIPLE OF VEHICLE VELOCITY MEASUREMENT
In this study, the proposed approach is similar to the traditional single induction loop detector (Yu et al., 2006).The method calculates the vehicle velocity by the width of the detection zone and the time it takes for target vehicles to drive into and depart from the detection region.
Camera is installed on the beam of crossroads appropriately, facing the direction of the traffic.The detection zone is set between the stop line and the crosswalk (or part of the crosswalk if necessary, because the pavement where vehicles pass by are prohibited from passing by pedestrians during green light), as shown in Fig. 1.
According to the condition on site, set the width of the detection zone to 2 meters and make the detection zone cover the lane.The vehicles must pass the detection zone because they cannot change lanes optionally.It's inaccurate to calculate speed by the time it takes for the vehicle to pass through the detection zone and the width of the detection zone, because the length of vehicle also affects the time of passing through the detection zone.However, the time for any vehicles to enter and leave the detection zone can be measured respectively, which is irrelevant to the body length.Therefore, the vehicle speed can be obtained from formula (1): where, S is the width of the detection zone.t = ∆t 1 -∆t 2 , in which ∆t 1 is the time it takes for the front of vehicle to enter the detection zone until it covers the detection zone completely, just referred to the time it take for the vehicle to enter the detection zone and ∆t 2 denotes the time it takes for the rear of vehicle to cover the detection zone completely until leave it, referred to the time it takes for the vehicle to leave the detection zone, the diagram of ∆t 1 and ∆t 2 is shown in Fig. 2 and 3.
In Fig. 2 and 3, j and k denote the frames take by the vehicle enter and leave the detection zone respectively.∆t 1 and ∆t 2 can be obtained according to frame rate (the collection frequency of images) f, in which ∆t 1 = j/f, ∆t 2 = k/f.This method adapts to low velocity measurement at the urban intersection where the speed is usually less than 40 km/h according to traffic safety and driving experience.The maximum value of the speed should be less than 60 km/h.

Camera calibration and detection zone setting:
Camera calibration (Damien and Kunihiro, 2009;Taufiqur and Nicholas, 2012) is necessary, because the information obtained by the video is only the pixel distance of the vehicle moving rather than the real world distance.In this study, a simple method that is proposed by Ren et al. (2007) is used for camera calibration, as shown in Fig. 4. The actual distance according to each row pixels of image is not equal, which is of nonlinear relation to each row pixels.So each row of pixels must be mapped to the actual distance.Assumed that the number of line scanned by camera is N (the camera resolution of 720 × 576, N is 576) and W 1 , W 2 , W 3 ... W N is the actual distances that corresponding to each row of pixels.
H is camera height above the ground, while L is the vertical distance along the surface direction between the bottom of the image and camera, H and L can be measured directly.So the angle between the 1 st scanning lines and the vertical direction is, then: The angle between 2 adjacent scanning lines is α.Therefore, the angle between the second scanning lines and vertical direction line is θ+α, between the third scanning lines and vertical direction line is θ+2α and between the nth scanning line and the vertical direction line is θ+ (n-1) α.We can get the real distance corresponding to the pixel on each line by formula (2): The camera is usually installed on a roadside support and video is shot in the looking-down perspective.In the captured images, the closer the vehicle is to the bottom of the image, the greater is the image of the vehicle, the greater is the spacing between vehicles and vehicle.The vehicle behind is vulnerable to be blocked by the vehicle in front of it because of the slow traffic and the small vehicle spacing.In order to eliminate the effect of vehicles occlusion, the detection zone will be set between a stop line and pavement.According to the difference between the height of the camera and the horizontal distance to the detection zone, setting an angle that makes the detection zone images at the bottom of the image.
The detection zone crosses the detection lane and the width of the detection zone is the safe interval between vehicles (usually 2 m) when they run at low speed.Suppose the pixels of two edge lines of the width of the detection zone are set on row n and row m+n, respectively.The actual distance of the width of the detection zone can be obtained by formula (3): (3) In the experimental test, H = 8.1m, L = 12m, n = 33, M = 56, it is easy to get S = 1.996 m.

Vehicle detection:
In order to achieve the vehicle speed, the moving vehicles need to be extracted from the image.So, the following step is necessary.

Background difference:
The background difference method is the most commonly used method for vehicle detection at present.The basic idea is: acquiring a background image firstly and doing subtraction between the current frame image and the background image.Then, extract the moving object with the threshold segmentation method (Du-Ming and Shia-Chih, 2009).The method can be described by the formula (4): Among them, I t (x, y) denotes the current image, B t (x, y) denotes the background image, D t (x, y) denotes the binary images and T denotes the threshold value.The vehicle is extracted using the background difference method and it is as shown in Fig. 5.

Shadow remove:
Because of the role of sunlight, the vehicle forms the shadow in the video image.Along with the change of the relative positions between the camera, vehicle and the sun, the shadow has different degrees of influence on the vehicle speed detection.When the direction of shadow and the direction of vehicle are same or opposite, the shadow is easy to be mistaken for the vehicle because of shadow has low Region filling: Due to light reflection, vehicle's windows and body are too close to the road in gray, which inevitably causes the binary image fault in horizontal and vertical direction.Because vertical faults have great influence on vehicle speed detection, the morphologic processing is implemented by the vertical dilation operator for binary image in the study to eliminate vertical fault.Dilation operator is shown in Fig. 6.Although there is the image fault in the horizontal, it is easy to make the adjacent vehicles adhesive when dilating in horizontal.Large number of experiments found that transverse faults appear small, have little effect on the speed detection.The effect of erosion operation is to eliminate the boundary points.The image boundary along the periphery will reduce one pixel when eroded by the erosion operation in Fig. 7.The vertical expansion operator above fills the empty image and at the same time makes the image edge to expand, so the erosion operation is implemented to eliminate the increased boundary points.with the increasing area of the vehicle that covers the detection zone.The amplitude will reach to its maximum when the vehicle completely enters the detection zone and it may last for frames according to different speed and different length of vehicle.When the vehicle is away from the detection zone, the area will gradually reduce and the amplitude of rectangular wave will continue to decline until it reduces to zero.
In the experiment, capture 3 frames when the vehicle passes through the detection zone, as shown in Assume that the maximum of rectangular wave amplitude f y (x) of each frame image is M f .Then, M f will change according to the time during the vehicle passing through the detection zone, as shown in Fig. 10.In Fig. 10, when the vehicle is entering the detection zone, the maximum Mf gradually rises from 0 to the attitude value of detection zone and this process takes ∆t1.When Mf reaches the attitude of detection zone, the vehicle completely covers the detection zone and the time is not sure for the speed and the length of the vehicle is uncertain.When the vehicle is leaving the detection zone, Mf gradually reduces from the attitude value of detection zone to 0. And the time that the vehicle spends on the process is ∆t2.So the instantaneous velocity when vehicles passing through the detection zone can be calculated by formula (1).

Speed determination:
In order to detect the speed of the vehicle, it is 1 st to detect whether the car exists in the image of detection zone.The width of the vehicle is the main feature of the vehicle and its performance in vertical projection curve is the width of the rectangular wave.To judge the width of the rectangular wave is greater than threshold TW is to detect if there are the vehicles exist in the detection zone and the value of TW is based on the width of a regular vehicle in the image.If TW is too large or too small, it will cause error or omission.In practice, TW is obtained after the video image is determined.The width of the rectangular wave is obtained by counting the continuous non-zero value of the vertical projection function f y (x).When the rectangular wave width is bigger than TW, it indicates there is a car in the detection zone, otherwise, there is none.
When vehicles exist in the detection zone, the time t can be obtained using the above-mentioned detection method and the distance which vehicle moves during the t is 2S， so the velocity can be calculated by In Fig. 11, the variable Frm is used to count the number of frames while vehicles entering and leaving the detection zone and is 0 in initial state.Lennum is the sum of columns when f y (x) is bigger than S. TF is the minimum value of Lennum when vehicle completely covers the detection zone in travel direction.When the Lennum is bigger than TF, the detection zone will be completely covered.
The vertical projection diagram of binary image is obtained after the image pre-processing.When the width of rectangular wave is bigger than the threshold TW, there is a car in the detection zone.Judging whether the maximum value of waveform amplitude Mf is less than the width of the detection zone S, if so, the vehicle is in the process of entering or leaving.Then, Frm plus 1 jump to the next frame.When the M f is not less than the width of the detection zone, it means that at least 1 pixel covers the detection zone.
In order to determine whether the vehicle enters the detection zone completely, judge whether Lennum is bigger than the threshold TF.If Lennum is less than TF, the vehicle is entering or leaving the detection zone and add 1 to Frm.If Lennum is bigger than the threshold TF, the vehicle has entered the detection zone completely.Then, Frm doesn't add 1 and jump to the next frame.
If the width of rectangular wave is less than or equals to the threshold TW, the vehicle is not detected in the frame.Then, judge whether form is bigger than 0. If so, vehicle will has been early and leaved the detection zone now.Now, Frm is the total value of frames that the leaving car enters and exits the detection zone.Then, t = Frm/f (f is 25 in this study), so the velocity can be calculated by formula (1).If Frm is 0, it means there is no vehicle in the detection zone.

EXPERIMENTAL RESULTS AND CONCLUSION
In order to verify the feasibility and validity of the algorithm, this study chooses an intersection with flyover junction.The camera is placed on the bridge and the detection zone is set according to Fig. 1.In practice, H = 8.1 m, L = 12 m and S = 1.996 m.The sampling rate of camera (f) is 25 frames per sec.The video sequences are processed in VC2008 and OpenCV2.0 environment on a computer with 2.0GHZ CPU and 2GB RAM.
In tests, the driver drives the same car to pass through the detection zone many times and records the speed value in speedometer every time when the vehicle is passing through the detection zone.Driving speed is 20 km/h, 20 to 40 km/h and above 40km/h respectively in 3 groups and test is made ten times for each group.The results are shown in Table 1.
As shown in Table 1, the velocity is not more than 20 km/h in group 1，between 20km/h and 40km/h in group 2 and above 40 km/h in group 3.The maximum error is 12.5, 16. and 28.4%, respectively in the 3 groups.In Table 2, the average speed error is 5.0, 6.2 and 9.9%, respectively.Although some single errors are large, the average speed error is below 10%.So this method for average vehicle speed measurement at intersection is able to meet the requirements of the traffic parameters measured.
In addition, the error is small when the vehicle speed is less than 20 km/h and the error increases gradually when the vehicle speed gradually increases from 20 km/h to 60 km/h because the vehicle takes short time and Frm is little when it passes by the detection zone at high speed.In order to reduce measurement errors and theoretical errors and improve the measurement accuracy, it can be achieved by increasing the camera frame rate.
This proposed approach can detect the average speed effectively and satisfy the demand of traffic parameters.Because of the small detection zone, this proposed approach has low requirement for calculation capability, the advantages of high real time and strong robustness.44.9 44.9 51.3 59.9 44.9 59.9 59.9 59.9 71.9 71.9 Error (%) 4.4 -0.2 6.9 17.5 -5.3 10.9 10.9 8.9 28.4 21.9

Fig. 1 :
Fig. 1: Schematic diagram of the speed detection at intersection

Fig. 2 :
Fig. 2: Schematic diagram of vehicle entering the detection zone

Fig. 9 .
Where, (a) ~ (c) provides images of the vehicle while entering the detection zone, fully entering the detection zone and leave the detection zone, respectively.(d) ~ (f) and (g) ~ (k) are binary images and vertical projection curves of the binary images according to (a) ~ (c).

Table 1 :
The result of this experiment

Table 2 :
Analysis of experimental results