# Semantic Visual SLAM Algorithm Based on Improved DeepLabV3+ Model and LK Optical Flow
## 2 Relevant Theories
### Octree Map Construction  
Although point cloud maps can realize 3D reconstruction of the environment, there are still some limitations: Firstly, point cloud maps cannot reconstruct the occluded area and cannot judge the occupancy of the map in the environment, which cannot provide more information for the robot navigation and path planning; secondly, the amount of data in point cloud maps is very large, and at the same time, the map scale is also large, so the point cloud information occupies a large amount of memory space. Therefore, it is not possible to build point cloud maps for a long time or large-scale scenes. However, octree maps can represent objects or maps in 3D space with the advantage of fast find, insert, and delete operations on large-scale data. Therefore, the point cloud map exported from the SLAM system in this study is converted into an octree map. Octree is a commonly used data structure for space partitioning. The basic idea of octree is to divide the space into a series of cubes, and then recursively divide each cube again into eight smaller cubes until some termination condition is satisfied, as shown in Figure 3. In a map application, the map can be divided into a series of cubes, each of which is called a \"node.\" Nodes can have three states: empty, leaf, or intermediate. Empty nodes indicate that there are no map data in the region, leaf nodes indicate that there are map data in the region, and intermediate nodes indicate that the region is further divided into eight sub-nodes. By recursive division, the regions of the map can be represented as an octree. When querying the map data, each child node can be searched recursively starting from the root node until a leaf node containing the query point is found. In the octree, the node stores the chance of the square being occupied, using \"0\" and \"1\" to indicate the state, where \"0\" means that the node is free, which means it can be passed, and \"1\" means that the node is occupied, which means it cannot be passed. The initial map obtained will be noisy, leading to some nodes being affected by noise and unable to observe the state. The state of the nodes can be described by probability logarithmic (log-odds) methods. Supposing \(p\in[0,1]\) represents the probability that a voxel block is occupied in the map, the probability logarithmic value of \(p\) is \(l\in R\), and the value \(l\) can be computed by using Equation (11):  
\[l=\log it(p)=\log\biggl{(}\frac{p}{1-p}\biggr{)} \tag{11}\]The inverse transformation results can be obtained with Equation (12):  
\[p=\log it^{-1}(l)=\frac{\exp(l)}{\exp(l)+1} \tag{12}\]  
On an octree map, when a node is observed to be occupied, its corresponding \(l\) value increases, and vice versa it decreases. Thus, \(l\) can be used to represent the magnitude of the probability that the node is occupied. Supposing a node is \(n\) and \(Z_{t}\) is the observation data of node \(n\) at time \(t\), then the probability logarithmic value at time t + 1 is as shown in Equation (13):  
\[L(n|Z_{1:t+1})=L(n|Z_{1:t-1})+L(n|Z_{t}) \tag{13}\]  
Semantic Visual SLAM System: Incorporating DeepLabV3+ Models, LK Optical Flow, and Background Repair Techniques  
The semantic segmentation thread is added using ORB-SLAM2 as the base framework, which contains a semantic segmentation module, an optical flow module, and a background restoration module. The semantic segmentation module is used to obtain the prior semantic information in the environment and eliminate the prior dynamic feature points. The optical flow module is used to detect the non-prior dynamic feature points whose motion speed exceeds a certain threshold, and after the processing of the two modules the dynamic targets can be eliminated. The background restoration module is used to provide more accurate information in the case of re-localization. A semantic dense map-building thread is added. The semantic dense mapping thread is used to 3D reconstruct the map in the dynamic environment.