# Vessel Velocity Estimation and Docking Analysis: A Computer Vision Approach
## 4 Methodology
### Vessel Velocity Estimation Strategy  
The strategy for measuring vessel velocity comprises two stages: processing and measurement. In the processing stage, image purity is enhanced to identify ship features accurately. The Suzuki and Abe algorithm [6] is applied to detect image borders. In contrast, a water feature detection algorithm inspired by [16] was utilized to identify water areas without compromising ship element edges. To facilitate the detection of these features, the following sequence of image processing steps was applied to the images:  
* Conversion to grayscale. The original RGB image was converted to a single color channel, varying its intensity between 0 (black) and 255 (white). Intermediate values represent shades of gray. * Binarization. With the image in grayscale, a threshold intensity value, or thresh, was established to determine whether that pixel would be considered black or white, depending on its intensity. In the case described here, it was established that all pixels with intensity below 150 would be considered black and those above, consequently, white. After these steps, the water detection algorithm separated the ship's edge from the water. Once the ship's edge could be isolated from the water movement, identifying the approach velocity became a relatively simple task. Based on the concept that average velocity is defined as the ratio between the variation in space and the variation in time, speed estimation utilized two different points. When the vessel executes a translation movement associated with a rotation movement, as often happens during docking processes, the vessel does not always approach parallel to the dock. Therefore, it was relevant to measure the velocity at two distinct points: on the left side of the image and the right side of it. Thus, two detection zones were created on the left side, one further away and one closer to the dock, aligned vertically and 5 m apart. The same was done on the right side. Each detection zone monitored the change in pixels so that the time of that event was recorded from a certain number of altered pixels. Therefore, when the first detection zone (farther from the dock) perceives the vessel's presence, the time starts to be counted. The counting is finished when the second detection zone (closer to the dock) is activated; thus, the average velocity is calculated. The conversion of pixel velocity to real-world velocity was achieved through a simple image-based coordinate mapping technique known as homography. During the data collection process, the port authorities provided real-world coordinate information by utilizing reference points in the upper and bottom detection zones on the left and right sides. These reference points were then mapped onto the image plane. By establishing a proportional relationship between the image coordinates and the measurements provided by the port authorities, the algorithm could convert the image coordinates into real-world coordinates and estimate the velocity. Since the portion of the vessel considered for calculating the speed moves in a planar environment, such as the sea, perspective distortion has a negligible effect on the calculation, thus enhancing the accuracy of the estimation. The applied homography transformation follows the following equation  
\[ \begin{bmatrix}x^{\prime}\\ y^{\prime}\\ 1\end{bmatrix} = \begin{bmatrix}h_{11}&h_{12}&h_{13}\\ h_{21}&h_{22}&h_{23}\\ h_{31}&h_{32}&h_{33}\end{bmatrix}\begin{bmatrix}x\\ y\\ 1\end{bmatrix}  \tag{2}\]  
where \(x^{\prime}\) and \(y^{\prime}\) represent the real-world coordinates, and \(x\) and \(y\) correspond to the image coordinates. The \(h_{ij}\) parameters are components of the projection matrix \(H\), which iscalculated using the Singular Value Decomposition (SVD) technique, taking into account the coordinates provided by the port authorities. The approximation angle is calculated using the same projection matrix. The centroid of the contour within the detection zones is considered.