## 2 Proposed VO System
### Solution Implementation
#### 2.3.2 Sub-Pixel Precision  
Optical flow allows for the development of a fast VO algorithm capable of being performed in real time. However, due to the nature of the algorithm and how the tracking is done, the system is prone to deviations and drift. To address this issue and increase precision, a subsequent direct method is used to improve the overall method and obtain sub-pixel accuracy, as illustrated in Figure 3. This method, also called template matching, involves a comparison of a fixed template of size \(T_{w}xT_{h}\) centered at \(O\) in the new image of the sequence \(I_{k+1}\) with an equivalent template in the previous frame, \(I_{k}\). This template is moved iteratively across a search area to find the maximum correspondence between both templates, which is represented as the area of size \(T_{w}xT_{h}\) surrounding \(O^{\prime}\). Therefore, using this representation, the true movement between both frames can then be described as the vector \(O\tilde{O}^{\prime}\). This method performs well as part of VO systems in environments with low texture [1; 12; 13]. However, due to its high computational cost, it is only used within a small search area, based on the assumption that the point \(O^{\prime}\) in the frame \(k\) will be situated near the point \(O^{\prime\prime}\), which is calculated after moving \(O\) by the translation vector \(t_{k,k+1}\) obtained previously. This structure allows for a rapid and robust execution that enables the calculation of a translation vector, \(t_{TM}\), between the points \(O^{\prime}\) and \(O^{\prime\prime}\), which will finally facilitate the computation of the true movement across frames as follows:  
\[t_{k,k+1}=\hat{t}_{k,k+1}+t_{TM} \tag{9}\]  
Figure 3: Schematic diagram of template matching. Figure 2: Filtering process: matched features before filtering (**left**) and filtered features (**right**). where \(\hat{t}_{k,k+1}\) represents the estimated movement obtained after the filtering process. The size of the template, \(T_{w}xT_{h}\), is maximized for the frame to avoid losing information by using small templates. These dimensions are determined using the following expressions:  
\[ \begin{split} T_{w}&=I_{w}-S_{w}\\ T_{h}&=I_{h}-S_{h}\end{split}  \tag{10}\]  
where \(S_{w}\) and \(S_{h}\) represent the width and the height of the defined search area, respectively. In this work, a small search area of size \(5\times 5\) pixels was chosen, assuming that the movement estimation from the previous process was close to the true solution. This significantly reduced the computational cost of this step. The comparison between templates was done by calculating the normalized cross-correlation coefficient, which obtains great results, reduces false matches, and achieves great performance against changes in external illumination [12]. This coefficient is defined as follows:  
\[R(x,y)=\frac{\sum_{i,j}(T^{\prime}(i,j)\cdot I^{\prime}(x+i,y+j))}{\sqrt{\sum_{ i,j}T^{\prime}(i,j)^{2}\cdot\sum_{i,j}I^{\prime}(x+i,y+j)^{2}}} \tag{11}\]  
where \(R(x,y)\) represents the similarity between the fixed template of the image \(k+1\) and the moving template of the image \(k\) centered at pixels \((x,y)\). \((i,j)\) represent the coordinates of the pixels in the moving template, which fulfill \(0\leq i\leq T_{w}-1\) and \(0\leq j\leq T_{h}-1\). Finally, \(T^{\prime}(i,j)\) and \(I^{\prime}(x+i,y+j)\) are obtained as follows:  
\[ \begin{split} T^{\prime}(i,j)&=T(i,j)-\frac{\sum_{ x,y}T(x,y)}{T_{w}\cdot T_{h}}\\ I^{\prime}(x+i,y+j)&=I(x+i,y+j)-\frac{\sum_{x,y}I( x+i,y+j)}{T_{w}\cdot T_{h}}\end{split}  \tag{12}\]  
where \(T(i,j)\) represents the \((i,j)\) pixel value at fixed template T, and \(I^{\prime}(x+i,y+j)\) represents the \((i,j)\) pixel value of the moving template at \((x,y)\). The algorithm will repeat this process for all pixels of the defined search area around \(O^{\prime}\), resulting in the one illustrated in Figure 4, whose maximum will be \(O^{\prime\prime}\).