# A Real-Time Map Restoration Algorithm Based on ORB-SLAM3
## 2 Materials and Methods
### Loop Closure Detection Acceleration Based on Grayscale Histogram
According to the container characteristics of the mean-SD structure, the keyframe group similar to the mean and standard deviation of the current keyframe \(KF_{i}\) is taken out, and then all keyframes with common words with \(KF_{i}\) are taken out from the keyframe group through the bag-of-words model and inverted index. This process can help us roughly and quickly exclude some impossible options, saving time for the SLAM system. The obtained keyframe group is further eliminated according to the common view relationship. If the number of common view keyframes in \(KF_{i}\) is \(m\), the \(m\) frames connected to \(KF_{i}\) will be directly eliminated, which is not used to calculate similar scores. Moreover, if the result of insufficient similarity between this keyframe and \(KF_{i}\) is obtained by judging the similarity score; a one-way mark that is not used for detection will be added to this keyframe to illustrate that there is no similarity between this keyframe and \(KF_{i}\). According to this mark, when traversing the common words of other \(KF_{i}\) and its similar keyframes, those with this mark will skip directly. This also saves a lot of computer resources, with less computational cost to save subsequent invalid duplicate calculations. Then, a set of keyframes \(K_{M}\) with a high similarity score is obtained by the bag-of-words matching and calculating the similarity score. According to the characteristics of bag-of-words matching, \(K_{M}\) has high similarity with \(KF_{i}\) in multiple parts, but in many textured similar environments, the overall similarity between \(K_{M}\) and \(KF_{i}\) is still not guaranteed. Thus, before \(K_{M}\) is calculated by Sim3, we calculate the correlation between the grayscale histogram of \(K_{M}\) and \(KF_{i}\) to compare the overall grayscale distribution. Suppose the grayscale histogram of \(H_{1}\) and \(H_{2}\), and the correlation between \(H_{1}\) and \(H_{2}\) is \(d(H_{1},H_{2})\), then  
\[d(H_{1},H_{2})=\frac{\sum_{I}(H_{1}(I)-\bar{H_{1}})(H_{2}(I)-\bar{H_{2}})}{ \sqrt{\sum_{I}(H_{1}(I)-\bar{H_{1}})^{2}\sum_{I}(H_{2}(I)-\bar{H_{2}})^{2}}}, \tag{11}\]  
Figure 3: Examples of normalization of grayscale histogram. (**a**) A room image in Euroc dataset. (**b**) The grayscale histogram of the image. (**c**) Normalized grayscale histogram. where,  
\[\bar{H}_{k}=\frac{1}{N}\sum_{j}H_{k}(j) \tag{12}\]  
If \(d(H_{1},H_{2})\) is closer to 1, it is considered that the correlation between \(H_{1}\) and \(H_{2}\) is higher. Although the high correlation between two grayscale images cannot be obtained from the high correlation between grayscale histograms, it can be concluded that there is no similarity between two grayscale images if the correlation between grayscale histograms is insufficient. Combined with the previous bag-of-words model screening, if \(d(H_{1},H_{2})\) is greater than a certain threshold (0.8 in this paper), it can be determined that the similarity between the two frames is high enough. On the contrary, if \(d(H_{1},H_{2})\) is less than the threshold, skip the current keyframe and judge the next keyframe. In the subsequent test, the situation that the candidate frame is abandoned due to poor frame quality will not occur. If the candidate keyframes \(K_{M}^{\prime}\) that meets all the above conditions is obtained, a local window \(W_{m}\) is defined. The window contains \(K_{M}^{\prime}\) and several keyframes with the highest degree of common view. The set of all mappings in \(W_{m}\) is \(X_{m}\). Mappoints of \(X_{m}\) and \(KF_{i}\) are matched by a bag-of-words. Then, the Sim3 solver is constructed, and the initial relative pose \(T_{am}\) of \(W_{m}\) and \(KF_{i}\) is solved by RANSAC. Through \(T_{am}\), the mapping in the window and the mappoints in \(KF_{i}\) are projected bidirectionally similar to Figure 2, so as to obtain more matching points. According to Equation (1), a more accurate relative pose is obtained by nonlinear optimization by minimizing the reprojection error.