## 5 Discussion
### Keyframe-Based LiDAR Optimization in a Multithreaded Framework
When the number of keyframes is less than 20 frames, the optimization time is above 75 ms. Therefore, from the real-time perspective of the algorithm operation, the number of keyframes per map segment should be set to at least 20 frames. After a comprehensive study of real-time operation and accuracy, we set the number of keyframes per map segment to 40 frames. Table 10 shows the time spent by LiDAR data optimization thread for every 40 keyframes; each operation in the table was performed once in every 40 keyframes. It is clear that the average time spent on each keyframe is very small. As seen from Table 11, the time spent by every keyframe in optimization operation is only \(\sim\)40.20 ms. It must be noted that the tracking thread took about 550 ms to create a new keyframe, as shown in Table 9. These results clearly demonstrate the effective real-time performance of the proposed method. \begin{table}
\begin{tabular}{c c c c c} \hline \hline  & **Operation** & **Medium (ms)** & **Mean (ms)** & **Std. Dev. (ms)** \\ \hline \multirow{4}{*}{Multithreaded segment-based optimization for every 40 keyframes} & Correction keyframe selection & 0.143 & 0.208 & 0.02 \\  & RGB-D points creation & 100.05 & 100.05 & 80.5 \\ \cline{1-1}  & LiDAR points acquisition & 121.90 & 121.90 & 98.8 \\ \cline{1-1}  & ICP operation & 961.03 & 935.76 & 82.69 \\ \cline{1-1}  & Local propagation & 99.43 & 94.19 & 49.10 \\ \cline{1-1}  & Segment-based optimization & 335.55 & 274.09 & 88.76 \\ \cline{1-1}  & Pose transfer and Map fusion & 79.20 & 81.86 & 50.04 \\ \hline \hline \end{tabular}
\end{table} 
Table 10: Average computation time of each operation for every map segment (40 keyframes) in LiDAR data optimization thread. Figure 21: (a) Correlation between the overall optimization time of the map segment and the number of keyframes per map segment and (b) correlation between the average optimization time of each keyframe and the number of keyframes per map segment. In terms of consistency, the map segmentation optimization had a 25% overlap with the previous segment of the map, whereas the keyframe poses at both ends of the map remained fixed as true value constraints. Using the double window optimization strategy, the front window uses the map point-pose constraint to construct an accurate map. The back window adopts the map point-position constraint and the pose-pose constraint to ensure front and rear map segment consistency. In terms of practicability, from the above experiments and analyses of real-time operation, accuracy, and consistency, it has been demonstrated that the proposed algorithm can accurately map and locate most indoor scenes in real-time, which is beneficial in large indoor scenes such as airports and shopping malls. With advancements in sensor technology, cost-effective and portable depth cameras will become popular. In addition to positioning and mapping of the surrounding environment in real-time, users carrying depth cameras can avail more services and experiences, such as augmented reality online games, path planning, and intelligent interaction with the environment, based on precise map and camera pose. Although the high-precision LiDAR data for large indoor scene are difficult to obtain, the data once obtained can be used permanently after subsequent processing; in addition, all users in the environment can share this data for high-precision positioning and mapping. Even in case the scene changes for any reason, the LiDAR data of the scene can be automatically updated using the high-precision model produced by the proposed algorithm, eliminating the need for rescanning.