## Materials and Methods
### Directional Bee Traffic  
The main logical steps of the proposed algorithm are given in Figure 1. Let \(F_{t}\) and \(F_{t+1}\) be two consecutive image frames in a video such that \(F_{t}\) is taken at time \(t\) and \(F_{t+1}\) at time \(t+1\). Let \(IA_{1}\) be a \(D\times D\) window, referred to as _interrogation area_ in the PIV literature, selected from \(F_{t}\) and centered at position \((i,j)\). Another \(D^{\prime}\times D^{\prime}\) window, \(IA_{2}\), is selected in \(F_{t+1}\) so that \(D\leq D^{\prime}\). The position of \(IA_{2}\) in \(F_{t+1}\) is the function of the position of \(IA_{1}\) in \(F_{t}\) in that it changes relative to \(IA_{1}\) to find the maximum correlation peak. In other words, for each possible position of \(IA_{1}\) in \(F_{t}\), a corresponding position \(IA_{2}\) is computed in \(F_{t+1}\). For example, \(IA_{2}\) in \(F_{t+1}\) can be centered at the same position \((i,j)\) as \(IA_{1}\) in \(F_{t}\). The 2D matrix correlation is computed between \(IA_{1}\) and \(IA_{2}\) with the correlation formula in Equation (1). \[ \begin{split}& C(r,s)=\sum\limits_{i=0}^{D-1}\sum\limits_{j=0}^{D-1} IA_{1}(i,j)IA_{2}(i+r,j+s),\\ &\text{where }\text{r},\text{s}\in[-\lfloor\frac{D+D^{\prime}-1}{2} \rfloor,\ldots,\lfloor\frac{D+D^{\prime}-1}{2}\rfloor]\end{split}  \tag{1}\]  
In Equation (1), \(IA_{1}(i,j)\) and \(IA_{2}(i+r,j+s)\) are the pixel intensities at location \((i,j)\) in \(F_{t}\) and \((i+r,j+s)\) in \(F_{t+1}\), respectively (see Figure 2). For each possible position \((r,s)\) of \(IA_{1}\) inside \(IA_{2}\), the correlation value \(C(r,s)\) is computed. If the size of \(IA_{1}\) is \(M\times N\) and the size of \(IA_{2}\) is \(P\times Q\), then the size of the \(C\) matrix is \((M+P-1)\times(N+Q-1)\). The \(C\) matrix records the correlation coefficient for each possible alignment of \(IA_{1}\) with \(IA_{2}\). Let \(C(r_{m},s_{m})\) be the maximum value in \(C\). If \((i_{c},j_{c})\) is the center of \(IA_{1}\), then the positions of \((i_{c},j_{c})\) and \((r_{m},s_{m})\) define a displacement vector \(\vec{v}_{i_{c},j_{c},r_{m},s_{m}}\) from location \((i_{c},j_{c})\) in \(F_{t}\) to \((i_{c}+r_{m},j_{c}+s_{m})\) in \(F_{t+1}\). This vector is a representation of how the particles may have moved from \(F_{t}\) to \(F_{t+1}\). All displacement vectors form a vector field that can be used to estimate possible flow patterns. Figure 2 shows the steps of how the cross correlation coefficients are computed. A faster way to calculate correlation coefficients between two image frames is to use the Fast Fourier Transform (FFT) and its inverse, as shown in Equation (2). The reason the equation tends to be computationally faster is that \(IA_{1}\) and \(IA_{2}\) must be of the same size. \[C(r,s)=\Re[FFT^{-1}(FFT^{*}(IA_{1})\cdot FFT(IA_{2}))] \tag{2}\]  
For many real world images, some displacement vectors are invariably noisy and must be eliminated from the vector field. Some vectors can be eliminated as outliers if their signal to noise ratio exceeds a certain threshold. Additional vectors may be computed, if necessary, as the averages of their immediate neighbors as functions of the second and third largest peaks in the correlation plane to achieve subpixel accuracy. Figure 1: Directional DPIV-based bee motion estimation algorithm. Figure 3 gives the directional vectors computed by the proposed algorithm from two consecutive \(640\times 480\) video frames with an interrogation window size of 90 and an overlap of 60%. Figure 3a,b presents two consecutive frames from a 30-s video captured by a deployed BeePi monitor. In Figure 3a, a single moving bee is indicated by a green rectangle. In Figure 3b, the same bee, again indicated by a green rectangle, has moved toward the white landing pad (the white strip in the middle of the image) of the hive. This movement of the bee is reflected in a vector field of eleven vectors shown in Figure 3e. Figure 3c,d presents two consecutive frames from a different 30-s video captured by the same deployed BeePi monitor.