# Application of a Real-Time Visualization Method of AUVs in Underwater Visual Localization
## 2 Methodology
### Closed Loop Detection and Closed-Loop Optimization Algorithm Based on Point-Line Features  
Closed loop detection is mainly used to judge whether the AUV is in the area that has been visited before on the basis of the current observation data [9]. If it is in such an area, a complete graph structure is constructed and redundant constraints are added. The main purpose of the closed loop test is to eliminate the cumulative error caused by inter-frame registration and the basic idea is to compare the current frame with all the key frames in the system. If they are similar, a closed loop is generated. The methods for judging similarity are presented below. In contrast to the previous closed loop algorithm, or feature dictionary, the characteristic dictionary tree used in this paper is generated by the off-line training of point-line features. The basic training method consists of three steps, as follows. * For the collected environmental image data, the features of point and line segments are extracted, including the corresponding 256 bits ORB and LBD [14] feature description vectors. The two characteristic description vectors can be used to establish the later feature dictionary (see Figure 3). Figure 2: The re-projection error of the line segments. * A simple K-means clustering method is used to obtain each leaf node at the bottom of the tree structure. Then the nodes of each layer are obtained in turn. Thus the training process of the feature tree can be completed. * When the new data is collected, the point-line features are extracted first, and the corresponding number of words in the dictionary are obtained using these features. Thus each picture can be described by the vectors, which are composed of the number of words in the characteristic dictionary tree. The vectors are called bags of words vectors (BOWV). For each word vector in each image, it is important to calculate the distance between two vectors as it is necessary to be able to determine the similarity between the two images. The shorter the distance, the more similar the two images are. A shorter distance also indicates that the AUV may reach the previous positions. The specific approach is as follows. For the two vectors and definitions, the evaluation scores based on the L1 norm \(\mathrm{s}(v_{1},v_{2})\) can be defined as follows:  
\[\mathrm{s}(v_{1},v_{2})=1-\frac{1}{2}\bigg{|}\frac{v_{1}}{|v_{1}|}-\frac{v_{2 }}{|v_{2}|}\bigg{|} \tag{4}\]  
where \(v_{1}\) is the eigenvector of the current frame, and \(v_{2}\) is the eigenvector of the dictionary and the previous frame. The higher the evaluation score, the greater the similarity between the two images and the greater the possibility of a closed loop. When the above score exceeds the set value, the algorithm enters the closed-loop optimization state. After estimating all consecutive loop closures in the trajectory, both sides of the loop closure are fused and the error distributed along the loop is corrected. Usually, the pose graph optimization (PGO) method is required in this process. The main purpose of pose graph optimization is to optimize the previous pose of a robot using the redundant constraints. The redundant constraints are obtained by closed-loop detection. When the robot walks to a position where it has walked before, the pose matrix changes due to the accumulation of errors. At this time, the redundant constraint is to reduce the error of the pose matrix. The process can be explained as follows: \(u=\left( \begin{array}{cccc}&u_{1}&u_{2}&\cdots&u_{t}\\ \end{array} \right)\), which represents the state quantity of the pose matrix of the robot at \(t\) moment. Where \(u_{i}=\prod\limits_{k=0}^{i}\xi_{(k-1,k)}\) and \(\xi_{(k-1,k)}\) is the pose transition matrix between frames \(k-1\) and \(\mathrm{k}\), \(\xi_{ij}\) and \(\Omega_{ij}\) are the observed transformation matrix and information matrix (representing the weight of noise) from the state of \(i\) time to the state of \(j\) time. \(\xi_{ij}\) is a real transformation matrix. The error function is shown in Equation (5).