# Highly Accurate Deep Learning Models for Estimating Traffic Characteristics from Video Data
## 3 Methodology
### Vehicle Speed Calculation  
To account for potential scenarios where the height and orientation of traffic cameras vary across diverse installations, it is necessary to conduct installation-specific calibration to attain precise vehicle position detection before deploying the system. An affine transformation from the image space to the world space is therefore deduced. A projection matrix is created based on road markings to acquire a representation of the position offset of each vehicle relative to the camera, which is then used for speed evaluation [36]. To ensure accurate calibration for each camera installation, a marker indicating the projected surface of a road segment must be provided. This marker should be a quadrilateral shape that encapsulates the outline of the road segment and represents a rectangle on the road surface. A sample marker preset is illustrated in Figure 3.  
The marker deduction approach assumes that the road is approximately straight with parallel lanes, as well as a constant slope, as flat roads with no change in elevation throughout the view frustum of the camera are preferred, as the slope of an elevating road surface is seldom uniform, introducing projection error and decreasing the model's accuracy [36]. Assume a camera model in the world space with positional parameters \(x,y,\) and \(z\), yaw y (i.e., the horizontal angle of the forward axis of the camera with respect to the world Y axis), pitch \(p\), roll \(r\), tilt angle t, and projection parameters focal length\(f\) and camera length l, vehicle world coordinate \(C_{world}\in R4\) and image space coordinate \(C_{screen}\in R3\) (representing position vectors in the vertical homogeneous coordinate form), the transformation function: \(R2\in R3\) maps the given screen coordinate vector \(p\) to the world coordinate given road marker data \(m\) via perspective transformation [37]. The perspective projection process is defined as [36; 37]:  
\[C_{screen}=P\times R\times T\times C_{world} \tag{1}\]  
\(P\) represents the projection matrix, while \(P\) and \(R\) represent the matrices responsible for the position and rotation of the viewport in world space, respectively. This affine  
Figure 3: Road marker label (ABCD are anchor points and W represents the width of the rectangle). transformation can be inverted to obtain the world coordinate from the screen coordinate of the vehicle:  
\[C_{world}=P^{-1}\times R^{-1}\times T^{-1}\times C_{screen} \tag{2}\]  
Excluding conversion of camera properties from road markers, the transformation matrices are defined as:  
\[T= \begin{bmatrix}1&0&0&-x\\ 0&1&0&-y\\ 0&0&1&-z\\ 0&0&0&1\end{bmatrix}  \tag{3}\]  
\[R= \begin{bmatrix}cosy&-siny&0&0\\ siny&-cosy&0&0\\ 0&0&1&0\\ 0&0&0&1\end{bmatrix}\begin{bmatrix}cosp&0&sinp&0\\ 0&1&0&0\\ -sinp&0&cosp&0\\ 0&0&0&1\end{bmatrix}\begin{bmatrix}1&0&0&0\\ 0&cosr&-sinr&0\\ 0&sinr&cosr&0\\ 0&0&0&1\end{bmatrix}  \tag{4}\]  
\[P= \begin{bmatrix}1&0&0&0\\ 0&0&1&0\\ 0&\frac{1}{7}&0&0\end{bmatrix}  \tag{5}\]  
The camera position can be inferred from the rotation and the camera length, namely [36]:  
\[ \begin{array}{c}x=l\times siny\times cosp\\ y=-l\times cosy\times cosp\\ z=-l\times sint\end{array}  \tag{6}\]  
The road marker's geometry is labelled as shown in Figure 3.  
Trivially, the label's on-screen width \(w\), along with other dimensions, can be determined by [36]:  
\[ \begin{array}{c}\alpha(A,B)=X_{B}-X_{A}\\ \beta(A,B)=Y_{B}-Y_{A}\\ \gamma(A,B)=X_{A}\times Y_{A}-X_{B}\times Y_{A}\\ \omega=\beta(A,C)\end{array}