# Improved Visual SLAM Algorithm Based on Dynamic Scenes
## 3 Method
### Dynamic Object Detection Based on Object Detection and Depth Maps  
The YOLOv5 network architecture is divided into four main parts: input, backbone, neck, and head, as illustrated in Figure 3. YOLOv5 released four versions of its object detection network--YOLOv5s, YOLOv5m, YOLOv5l, and YOLOv5x--whose model structures are largely similar, with differences primarily in the depth_multiple and width_multiple parameters. Table 1 below compares the speed and accuracy of these four YOLOv5 versions tested on the COCO dataset [24]. Figure 3: YOLOv5’s network architecture diagram. Figure 2: GCNv2 feature extraction network structure with channel numbers listed below each convolutional layer. It can be observed from Table 2 that the YOLOv5s model had the fastest detection speed and the fewest parameters, but it also had the lowest detection accuracy, making it suitable for applications that require high real-time performance but do not demand high detection accuracy. On the other hand, the YOLOv5x model had the slowest detection speed and the largest number of parameters, but it offered the highest detection accuracy, making it suitable for applications that require high detection precision but do not prioritize real-time performance. In indoor scenes, where dynamic objects move slowly and real-time performance is not critical, but the environment is complex with many small items requiring high detection accuracy, the YOLOv5x model, which offers the highest detection precision, was chosen as the dynamic object detection algorithm in this study. The YOLOv5x network, which initially identifies potential dynamic objects through semantic labels and represents them with rectangular bounding boxes, may encounter an issue when the detection box is large and the dynamic object occupies only a small portion of it. This can result in excessive removal of static points from the background, leading to an insufficient number of static feature points for accurate position estimation and ultimately affecting the system's localization accuracy. To address this problem, we adopted a method that combines object detection with depth information to further determine the spatial extent of dynamic objects in the image, similar to obtaining a mask through semantic segmentation, while also maximizing the retention of static feature points. The process for generating the dynamic object mask was as follows. First, create a mask image of the same size and type as the grayscale image, initializing its pixel values to all zeros, which means the mask's initial state is entirely \"off\", with all pixels excluded from the processing range by default. Next, employ two nested loops to iterate through each pixel of the image, setting the depth value of points less than 0.1 m to 15 m, thereby ignoring these noise points and preventing their misapplication in subsequent processing. Then, check whether the current point is located within any bounding box marked as \"person\" by YOLOv5x (with a 5-pixel extension to the bounding box), and calculate the normalized distance between the depth of the point and the average depth of all \"person\" objects within the bounding box. If the square of the distance is greater than 2, indicating a significant difference between the current point's depth and the surrounding depths and suggesting that the point may be static, the pixel value remains unchanged. Finally, a window is created to obtain a mask identical to the one from semantic segmentation, allowing for more accurate removal of dynamic feature points. As illustrated in Figure 4, integrating object detection results with depth information from the RGB-D camera yielded outcomes comparable to those of semantic segmentation. While semantic segmentation neural networks are complex and impose a significant computational burden, potentially impacting processing time and real-time performance, our approach overcame these challenges while preserving system accuracy.