# Vehicle Detection with Self-Training for Adaptative Video Processing Embedded Platform
## 3 Methods
### Vehicle Tracking  
In this work, the SORT approach is applied for vehicle tracking [28]. This method follows the tracking-by-detection framework. Firstly, the object detector returns bounding box proposals for a given frame. In the next step, new detections are associated with existing ones (called tracks) by usingthe Hungarian algorithm [40]. The vehicle motion is estimated using the Kalman filter to improve the tracker accuracy further [41]. This framework provides great efficiency with very good accuracy in an online setting.  
The goal of the vehicle association step is to match the new bounding box detections returned by the vehicle detector with the existing tracks. Firstly the IOU between all new detections and all existing tracks is computed. This forms a cost matrix, and the problem is to find an association where the cost is minimal. Cost is defined as a sum of all unassigned values in the cost matrix. There are many methods for solving this problem, e.g., sub-optimal, but a fast greedy algorithm that first assigns the biggest values to the cost matrix. However, the optimal solution can be found using the Hungarian algorithm. Additionally, a minimum \(IOU_{min}\) constraint is added to remove possible false assignments with a small overlap. All of the detections that were not matched form new tracks.  
Next, the vehicle's motion needs to be modelled. Given the history of the vehicle's positions, its location in a subsequent frame can be approximated. Additionally, because the observation model (vehicle detector) is not perfect (detections may be inaccurate or missing), a tracking method is needed that accounts for this uncertainty in the model. For this purpose, the Kalman filter is applied. Each vehicle is modelled as a vector [28]:  
\[x=[u,v,s,r,\dot{u},\dot{v},s]^{T} \tag{3}\]  
where \(u\) and \(v\) are horizontal and vertical pixel positions of vehicle bounding box centroid, \(s\) stands for scale (area) and \(r\) for the ratio of the bounding box. \(u\), \(v\), \(s\), \(r\) are the measurements, while \(\dot{u}\), \(\dot{v}\), and \(\dot{s}\) are estimated from observations. To track a moving vehicle, two basic procedures are applied:  
1. Prediction. Predict the vehicle's position in the next frame.
2. Update. Given a new observation (bounding box detection) update the current state.  
A new detection that was not matched to any of the existing tracks creates a new identity with a unique identifier initialised with zero velocity and geometry of the bounding box. Because this is a first detection of the vehicle, and its velocity is not known, large values of the velocity component in covariance matrix \(P\) are assigned, reflecting uncertainty regarding the speed. Tracks are removed if they are not detected for \(T_{lost}\) frames. This solution allows for handling short-term occlusions, and it resolves situations where the detector fails to detect an existing vehicle for a few frames. However, the valuue of \(T_{lost}\) should be kept relatively small to prevent uncontrolled growth in the number of tracks.  
Finally, it is possible to add a probationary period, during which the vehicle is regarding as not being active, i.e., a track is considered to be active when it has successfully been tracked for \(T_{min}\) consecutive frames. This helps to prevent the tracking of some false positively detected objects. In our experiments, the values of the covariance matrices were initialised with the same values as in the original SORT paper, and the following values were used--\(IOU_{min}\) = 0.5, \(T_{min}\) = 2, and \(T_{lost}\) = 2.