# DFD-SLAM: Visual SLAM with Deep Features in Dynamic Environment
## 3 Materials and Methods
### Frame Rotation Estimation and Feature Point Matching
The gradient of the objective function is computed as shown in Equation (6), where \(\frac{\partial f}{\partial x}\) and \(\frac{\partial f}{\partial y}\) are given by Equations (7) and (8):  
\[\
abla f(x,y)=\left(\frac{\partial f}{\partial x},\frac{\partial f}{\partial y }\right) \tag{6}\]  
\[\frac{\partial f}{\partial x}=\sum_{i=1}^{n}2\left(\frac{a_{i}x+b_{i}y+c_{i}}{ \sqrt{a_{i}^{2}+b_{i}^{2}}}\right)\frac{a_{i}}{\sqrt{a_{i}^{2}+b_{i}^{2}}} \tag{7}\]  
\[\frac{\partial f}{\partial y}=\sum_{i=1}^{n}2\left(\frac{a_{i}x+b_{i}y+c_{i}}{ \sqrt{a_{i}^{2}+b_{i}^{2}}}\right)\frac{b_{i}}{\sqrt{a_{i}^{2}+b_{i}^{2}}} \tag{8}\]  
Each update of \(OP\) occurs in a specified direction, allowing \(f(x,y)\) to converge quickly. The updated \(f(x,y)\) is represented by Equation (9):  
\[f(x_{k}+a_{k}p_{k,x},y_{k}+a_{k}p_{k,y}) \tag{9}\]  
Here, \(p_{k,x}\) and \(p_{k,y}\) are the iteration directions, determined by Equation (10):  
\[p_{k}=-B_{k}^{-1}\
abla f(x_{k},y_{k}) \tag{10}\]  
The _Hessian_ matrix \(B_{k}^{-1}\) reflects local curvature information of the objective function near the latest iteration point, providing a more accurate descent direction. The formula for \(B_{k}^{-1}\) is given by Equation (11):\[B_{k}^{-1}=(I-\rho_{k-1}s_{k-1}y_{k-1}^{T})B_{k-1}^{-1}(I-\rho_{k-1}y_{k-1}s_{k-1}^ {T})+\rho_{k-1}s_{k-1}s_{k-1}^{T} \tag{11}\]  
Here, \(s_{k}\) represents the change vector, \(y_{k}\) represents the gradient change vector, and \(\rho_{k}\) is used to adjust the update magnitude, ensuring positivity. The specific formulas are as follows:  
\[s_{k}=(x_{k+1}-x_{k},y_{k+1}-y_{k}) \tag{12}\]  
Figure 2:0  
Figure 2:1  
After iterative optimization, \(f(x_{k},y_{k})\) obtains the optimal \(OP\) point as the frame rotation center. Lines 6 to 12 consider that if the motion between the two frames is relatively close to a frame rotation, the distances from \(OP\) to the ends of all optical flow vectors should be similar. As shown in Figure 3, there will be a certain difference \(dist\) between the distance from \(P_{3}\) to \(OP\) and the distance from \(P_{4}\) to \(OP\). If \(dist\) is too large, this vector will be filtered out. This process is expressed in Equation (15), where \(OP\) is the frame rotation center, and \(P1\) and \(P2\) are the two endpoints of the optical flow vector. Figure 2:2  
Therefore, lines 13 to 17 utilize this principle to filter some optical flow vectors. If too many vectors are discarded, it means that the motion between the two frames does not clearly involve a frame rotation. The remaining vectors' angles from both ends to the frame rotation center are then used to estimate the rotational movement between the current and previous frames. This is shown in Equation (16), where \(P1_{i}\) and \(P2_{i}\) represent the two endpoints of each optical flow vector:  
Figure 2:3  
The threshold angle is set at 20 degrees because performance typically starts to degrade once estimated angles exceed \(15^{\circ}\) in testing. If the angle is bigger than the threshold angle, the system assumes that HFNet-generated descriptors should not be used due to potential frame rotation. Instead, it recalculates ORB descriptors for feature points between the current and previous frames, employing the same method as ORB-SLAM3 for subsequent matching. Conversely, if the angle is smaller, the descriptors from HFNet are used for  
Figure 2:4 Filter out optical flow vectors that do not meet the requirements. the current frame, and the descriptors from the previous frame are retrieved from storage. In this case, BOW is still employed to accelerate matching, but the distance calculation shifts from Hamming distance to Euclidean norm, as shown in Equation (17), where \(des1\) and \(des2\) represent the descriptors being matched:  
Figure 2:5  
After this step, certain scenarios where frame rotation loss occurred due to the use of HFNet descriptors will be switched to ORB descriptors.