2.1.3. The Lightweight Contour Extraction Algorithm Based on BAS-DP

A large number of high-precision instance segmentation can be obtained through the contour enhancement network. If all points on the target contour segmented by the instance are retained, the file will be too large, which will lead to slow SLAM operation time in the later stage and make it difficult to achieve the real-time effect. Therefore, a lightweight contour extraction algorithm based on BAS-DP is proposed. The algorithm converts the contour information surrounding the target into the best polygon surrounding the target. The number of coordinate points contained in the polygon is small, which can lighten the segmentation file while ensuring the accuracy of instance segmentation.

**Figure 6.** The recognition structure with contour enhancement using CQE.

Using the best polygon surrounding the target to replace the contour curve surrounding the target is the most direct and commonly used method. Therefore, it is necessary to convert the contour of the target into each turning point on the polygon surrounding the target. So, it is necessary to use a polygon approximation algorithm to convert the contour curve of the target into a polygon surrounding the target and then record the coordinates of key points on the polygon in the segmentation file.

Douglas–Peucker algorithm (DP algorithm) is a classical polygon approximation algorithm that can approximate the closed curve as a polygon and reduce the number of points as much as possible. It has the advantages of translation and rotation invariance. However, it needs to solve other points on the curve that do not belong to key points exhaustively, which requires a lot of calculation time. The Beetle antennae search algorithm (BA algorithm) is another classic polygon approximation algorithm that realizes efficient optimization by simulating longicorn beetle foraging. Beetle Antennae Search algorithm can realize optimization without knowing the specific form of function and gradient information. However, its accuracy is relatively low.

This paper proposes lightweight contour extraction algorithm based on BAS-DP, combining the advantages of the above two algorithms. The calculation steps are shown in Figure 7.

In the BAS-DP algorithm, parameter initialization includes the initial trial step attenuation factor *H*, step *S*, the ratio of step and whisker *C*, the number of iterations *n* and the number of parameters to be optimized *k*. Among them, the distance optimization function *f*(*x*) is shown in Formula (2). According to this formula, the function values *fl* and *fr* corresponding to the left whisker position *xl* and the right whisker position *xr* of the longicorn beetle can be calculated, and the next position *x* of the longicorn beetle can be calculated at the same time. Perform calculating function *f*(*x*) n times in total. The optimal function value corresponding to the last position *x* of the longicorn beetle is obtained as the optimal solution.

**Figure 7.** The calculation steps of BAS-DP lightweight contour extraction algorithm.

$$\begin{cases} & d\_{\rm ir} = rand(k, 1); \, d\_0 = step/c \\ & \mathbf{x\_l} = \mathbf{x} + d\_0 \* dir/2; \, \mathbf{x\_r} = \mathbf{x} - step\* \* d\_{\rm ir}/2 \\ & f\_1 = f(\mathbf{x\_l}); \, f\_\mathbf{r} = f(\mathbf{x\_r}) \\ & \mathbf{x} = \mathbf{x} - st\_{\rm tcp} \* d\_{\rm ir} \* s\_{\rm iqn}(f\_l - f\_\mathbf{r}) \end{cases} \tag{2}$$

The BAS-DP algorithm can reduce the size of the segmented file while maintaining the contour accuracy and improving the real-time performance of the later visual SLAM. Finally, the BAS-DP algorithm is combined with the hybrid dilated convolutional neural network and the CQE algorithm proposed in the previous two sections, forming the CO-HDC. Through this algorithm, a large number of high-quality instance segmentation images can be generated, and the data enhancement network needs only a small amount of data to record better accuracy, especially to solve the segmentation problem of the object contour.
