## 2 Materials and Methods
### The Overview of the Applied Optical Flow Methods  
The first of the considered approaches was the use of global entropy of the image and its local values determined for individual frames of the video sequence. According to the adopted assumption, for higher water-flow velocities, individual frames of the video  
Figure 3: Sample video frames acquired for various measured water flow velocities in the presence of fish: (**a**) 2.35 dm\({}^{3}\)/s; (**b**) 2.99 dm\({}^{3}\)/s; (**c**) 3.62 dm\({}^{3}\)/s; and (**d**) 4.01 dm\({}^{3}\)/s. Figure 2: Sample video frames acquired for various measured water-flow velocities: (**a**) 1.86 dm\({}^{3}\)/s; (**b**) 2.80 dm\({}^{3}\)/s; (**c**) 3.96 dm\({}^{3}\)/s; and (**d**) 5.03 dm\({}^{3}\)/s. sequence should be characterized by greater variability, and, thus, higher values of image entropy. However, the observed changes in entropy for individual frames of the video sequence did not allow to obtain satisfactory results, mainly due to the lack of use of inter-frame information. Therefore, subsequent studies focused on estimating the motion vectors between adjacent frames of the video sequence. For this purpose, it is possible to use several methods from the optical flow family [26]. To estimate the value of optical flows for individual frames of recorded video sequences, three different methods were used:  
* Horn-Schunck (HS) method;
* Farneback (F) method;
* Lucas-Kanade (LK) method. Determining the optical flow between two frames of a video sequence requires solving an equation with constraints:  
\[I_{x}u=I_{y}v+I_{t} \tag{1}\]  
where \(I_{x}\), \(I_{y}\) and \(I_{t}\) are spatial and temporal (spatiotemporal) derivatives of image brightness, and \(u\) and \(v\) are the values of the horizontal and vertical optical flow (horizontal and vertical components of the vector), respectively. The Horn-Schunck (HS) method is based on the assumption that the optical flow in the image is smooth over the entire surface of the image; hence, the velocity vector field \([u\ v]^{T}\) determined by this method should minimize the value of the equation:  
\[E=\iint\bigl{(}I_{x}u+I_{y}v+I_{t}\bigr{)}^{2}dx\,dy+\alpha\cdot\iint\biggl{[} \left(\frac{\partial u}{\partial x}\right)^{2}+\left(\frac{\partial u}{ \partial y}\right)^{2}+\left(\frac{\partial v}{\partial x}\right)^{2}+\left( \frac{\partial v}{\partial y}\right)^{2}\biggr{]}dx\,dy \tag{2}\]  
where the global coefficient \(\alpha\) enables the selection of smoothness on the image surface, whereas the individual partial derivatives are determined in relation to the image pixel coordinates. Minimizing this expression in the HS method leads to the following relationships:  
\[u_{x,y}^{k+1}=\bar{u}_{x,y}^{k}-\frac{I_{x}\cdot\left(I_{x}\bar{u}_{x,y}^{k}+ I_{y}v_{x,y}^{k}+I_{t}\right)}{\alpha^{2}+I_{x}^{2}+I_{y}^{2}}\;, \tag{3}\]  
and  
\[v_{x,y}^{k+1}=\bar{v}_{x,y}^{k}-\frac{I_{y}\cdot\left(I_{x}\bar{u}_{x,y}^{k}+ I_{y}\bar{v}_{x,y}^{k}+I_{t}\right)}{\alpha^{2}+I_{x}^{2}+I_{y}^{2}}\;. \tag{4}\]  
The vector \(\left[u_{x,y}^{k}\ v_{x,y}^{k}\right]\) is an estimate of the flow velocity for a given image pixel with coordinates \((x,y)\), whereas \(\left[\bar{u}_{x,y}^{k}\ \bar{v}_{x,y}^{k}\right]\) contains its average values from the defined neighbourhood. To determine the values of \(u\) and \(v\) flows, in the first step the gradient images \(I_{x}\) and \(I_{y}\) should be determined using the well-known Sobel convolution filter for a standard \(3\times 3\) pixels mask. The \(I_{t}\) value calculated as the difference between images is determined using the \([-1\ 1]\) mask, whereas the average velocity for each pixel (excluding it) is determined using a convolution with a mask typical for 4-connected neighborhood (two horizontal and two vertical neighbouring pixels). The determination of the values of flows \(u\) and \(v\) in subsequent steps is iterative. The default value of the parameter \(\alpha\) is \(1\).