\subsection{Video Data Processing}

\subsubsection{Trajectories: Positions in Space and Time}

Road user trajectories are extracted from video data using a feature-based tracking algorithm described in \cite{saunier06feature-based}. Trajectories are a series of points in Cartesian space representing the centre position of a moving object (road user) at time $t$ on a planar surface. Points are evenly spaced in time with a consistent $\Delta t$ equivalent to the inverse of the frame rate of the video (typically 15 to 30 frames per second), i.e. a measurement is done for each frame. The object (road user) itself is represented by a group of characteristic features spread over the object and moving in unison. A sample of tracked road user trajectories is presented in image space in Figure~\ref{fig:conflict-video}. The computer vision software is covered in greater detail in section \ref{software}.

Three potential sources of error exist: parallax, pixel resolution, and tracking:

\begin{itemize}
\item \textbf{Parallax error} is mitigated by maximizing the subtending angle between the camera and the height of tracked objects. In practical terms this requires a high angle of view, ideally a bird's eye view, and tracking objects with a small height-to-base ratio. Passenger cars are more forgiving in this respect than heavy vehicles or pedestrians. 
\item \textbf{Pixel resolution} determines measurement precision. Objects further away from the camera experience lower tracking precision than objects near the camera. Error due to pixel resolution is mitigated by placing the camera as close to the study area as possible and using high-resolution cameras, though increases in resolution offer diminishing returns in tracking accuracy. 
\item Finally, \textbf{tracking errors} may occur with scene visibility issues or due to limits to current computer vision techniques. These erroneous observations have to be rejected or reviewed manually. Attempts have been made in recent literature and for this work to measure and optimize tracking accuracy \cite{ettehadieh15systematic} using the Measure Of Tracking Accuracy (MOTA) methodology \cite{Bernardin_2008}. MOTA is a measure of accuracy that combines multiple sources of tracking error simultaneously, including false positive and false negative detection (Measure of Tracking Precision, MOTP, may be used for the spatial accuracy of measurements). The tracking optimization is replicated for this study using a genetic algorithm that searches heuristically for optimal tracking parameters based on MOTA as a measure of fitness from manually annotated video data. See section \ref{tracking_calibration} for more details and results of this process.
\end{itemize}

Depending on the steps taken to minimize tracking errors, feature-based tracking functions best over study areas of up to 50-100~m in length with high-to-medium speed, low-to-medium density traffic flows.

\subsubsection{Derived Data: Velocity \& Acceleration}

Velocity and acceleration vectors are derived by simple differentiation of position and subsequently velocity over time, after undergoing smoothing with a moving average window over several frames. The heading of the velocity vector may be used to determine the orientation of the vehicle.

%It should be noted however that each successive derivation increases pixel precession error for that measure. A velocity measure requires twice as many pixels as a position measurement. Similarly, an acceleration measurement requires three times as many pixels as a position measurement. This type of error can be compensated for with  moving average smoothing over a short window (e.g. 5 frames). At this time, acceleration measurements are still too noisy to be useful for instantaneous observations. Higher camera resolutions should solve this problem in future applications.

\subsubsection{Size of Data}
\label{method-size_of_data}

Feature tracking provides a microscopic level of detail. Individual observations measured at a single site over the course of a normal day typically register in the tens of millions. The sample size (number) of individual tracking measurements (positions, velocities, etc.) per hour $n$ can be estimated with the equation

\begin{equation} \label{eqn:data-size} n = fQd \end{equation}

where $f$ is the number of frames per second of the video, $Q$ is the average hourly flow-rate, and $d$ is the average dwell-time of each vehicle in the scene (excluding full stops). Dwell-time is affected by the size of the analysis area in the scene and the average speed. As such, the size of the analysis area needs to be carefully selected.

%Furthermore, over-representation of objects travelling below the average speed needs to be accounted for in all calculations. One option is to sample data per object with, for example, a simple mean, or alternatively to re-sample observations by position instead of time. For a series of equally spaced points in a grid, hex map, or along a spline, the re-sampled value $m'_j$ at the point $p_j$ is the average 

%\begin{equation} \label{eqn:resampling} m'_j = \frac{\sum_{i=1}^{n}{m_i} }{n} \end{equation}

%where $m_i$ is the measure of a series of observations $i=1..n$ satisfying the constraint 

%\begin{equation} \label{eqn:resampling-constraint-map} [(p'_{xi}-p_{xj})^2+(p'_{yi}-p_{yj})^2 < (p_{xj+1}-p_{xj})^2+(p_{yj+1}-p_{yj})^2] \end{equation}

%for a grid or hex map and the constraint 

%\begin{equation} \label{eqn:resampling-constraint-spline} [(p'_{si}-p_{sj}) < (p_{sj+1}-p_{sj})] \end{equation}

%for a spline where $s$ is the curvilinear distance along the spline (see section \ref{alignments} for more details on the curvilinear coordinate system employed). This choice of re-sampling will vary from one context to the next.