## 2 Port Vessel Detection System
### Tracking Path Analysis  
The tracking problem can essentially be defined as the problem of estimating the path or trajectory of a target in an image when the target is moving [25]. In order to observe the trajectory of a target vessel on a sea surface more intuitively, its path needs to be analyzed. Based on the premise that the direction and speed of each pixel in the video image will not change suddenly, the path that the moving target is forming is considered coherent. The path coherence function reflects information such as the direction and velocity of the moving target. It can be used to represent a measure of consistency between the trajectory of a moving target and the constraint of motion; thus, the generated trajectory of a moving target is represented as a series of points in a two-dimensional projection plane, as follows:  
\[T_{i}=\left(X_{i}^{1},\ X_{i}^{2},LX_{i}^{n}\right) \tag{1}\]  
where \(X_{i}^{k}\) represents two independently moving target trajectories in an image sequence \(k\), as shown in Figure 2.  
Let \(x_{i}^{k}\) represent the projected coordinates of the sequence point \(X_{i}^{k}\) on an image. According to the correlation between the coordinates, the trajectory of the moving target can be represented in the form of a vector, as follows:  
\[T_{i}=\left(X_{i}^{1},\ X_{i}^{2},L,X_{i}^{n}\right) \tag{2}\]  
The deviation in the path represents the difference between the target and the coherent path, which can be used to measure the consistency of the path of the moving target. Let \(d_{i}^{k}\) denote the path deviation of point \(i\) in image \(k\), as follows:  
\[d_{i}^{k}=\Phi\Big{(}\overline{x_{i}^{k-1}x_{i}^{k}},\overline{x_{i}^{k}x_{i} ^{k+1}}\Big{)} \tag{3}\]  
where \(\Phi\) is the path coherence function and \(\overline{x_{i}^{k-1}x_{i}^{k}}\) represents the motion vector from point \(x_{i}^{k-1}\) to point \(x_{i}^{k}\). The path deviation \(D_{i}\) of target \(i\) over the whole motion can be expressed as follows:  
\[D_{i}=\sum_{k-2}^{n-i}d_{i}^{k} \tag{4}\]  
For \(m\) independently moving targets, the overall path deviation \(D\) can be defined as follows:  
\[D=\sum_{k-2}^{n-i}D_{i} \tag{5}\]  
When path analysis is required for multiple targets at the same time, this can be solved by minimizing the overall path deviation \(D\). Assuming that the video frame rate is high enough, the velocity and direction of motion of the target can be considered to change smoothly between image sequences. Therefore, \(\Phi\) can be expressed as follows:  
\[\Phi\Big{(}P_{i}^{k-1},\ P_{i}^{k},P_{i}^{k+1}\Big{)}=w_{1}(1-cos\theta)+w_{2 }\Bigg{(}1-2\frac{\sqrt{S_{k}S_{k+1}}}{s_{k}+s_{k+1}}\Bigg{)} \tag{6}\]  
Figure 2: Trajectories of two independently moving targets. where \(cos\theta=\frac{\left|\frac{k_{1}^{k-1}x_{1}^{k}}{k_{1}^{k-1}}\right|\left|\frac{k _{1}^{k}x_{1}^{k+1}}{k_{1}^{k-1}}\right|}\) and \(\frac{\sqrt{k_{k}+k_{1}}}{k_{1}+k_{1}}=\frac{\sqrt{\left|\frac{k_{1}^{k-1}x_{1} ^{k}}{k_{1}^{k}}\right|\left|\frac{k_{1}^{k}x_{1}^{k+1}}{k_{1}^{k-1}}\right|}}{ \left|\frac{k_{1}^{k}-1}{k_{1}^{k}}\right|\left|\frac{k_{1}^{k}x_{1}^{k+1}}{k _{1}^{k}}\right|}\). The angle \(\theta\) and the distances \(S_{k}\) and \(S_{k+1}\) are shown in Figure 3. The weight coefficients \(w_{1}\) and \(w_{2}\) represent the importance of direction coherence and velocity coherence in path analysis, respectively. When multiple independently moving targets are tracked at the same time, occlusion occurs between them, and the targets in some image frames may partially or completely disappear, which leads to errors in the target trajectory. Minimization of the total trajectory deviation (Equation (5)) using a given path coherence function assumes that the same number of targets is detected in each image in an image sequence and that the detected target points always represent the same targets [26]. However, once a moving target is occluded in an image, these assumptions cannot be satisfied.