# Visual-Based Localization Using Pictorial Planar Objects in Indoor Environment
## 5 PicPose: A Picture-Based Pose Method
### PicPose Feature Points Matching  
FLANN (Fast Library for Approximate Nearest Neighbors) is applied in our work to obtain the matching points between detected picture and the original picture stored in the library. FLANN can provide fast nearest neighbor searching in high dimensional spaces. However, it is hard to avoid the failed matching clustering in a small area. As a dominant process in the localization model, the accuracy of matching directly affects the localization performance. That is to say, too many false matches are not tolerant by localization calculation. Therefore, a matching filter is required to apply for removing the bad matching results. There are two common situations which may cause matching errors, single point errors and clustered points errors. Single point error means there is only one matching error within a small region. Meanwhile, the clustered points error is that there are a lot of errors clustered in a region. A two-layer matching filter is proposed to handle those two kinds of errors. ```
Input: picture width w, height h, key points array P and corresponding descriptors array d\({}_{p}\) Output: Optimized key points array D\({}^{p}\) and descriptor array D\({}^{d}\) Initialize a 2D array for distributed key points D\({}^{p}\), and a 2D array for descriptors D\({}^{d}\); m = w/4 m = h/4 for i = 0 to 3 do for j = 0 to 3 do for k = 0 to P.size do if \(i*m\leq P_{i}.x<(i+1)*m\) and \(j*n\leq P_{i}.y<(j+1)*n\) \(D_{i*+j}^{p}.add(P_{i})\) \(D_{i*+j}^{d}.add(d_{i\mu})\) \(P.remove(P_{i})\) \(d_{p}.remove(d_{\mu})\) end if end for end for end for \(\alpha=\min\ (\frac{1}{100}\frac{w*h}{P.size})\) for i = 0 to 15 do if \(D_{i}^{p}.size>\alpha^{*}m^{*}n\) for j = 0 to \(D_{i}^{p}.size\) \(H.add(Hamming distances of in \(D_{ij}^{d}\) and nearest 10 descriptor in \(D_{i}^{d}\)) end for H.rank() \(D_{i}^{p}.remove(points with Top(D_{i}^{p}.size - \alpha^{*}m^{*}n)\) nearest Hamming distances in H.) end if end for
```  
**Algorithm 1 Feature Points Density Optimization**  
We use [PERSON]'s test as the first layer that can remove the single point error. [PERSON]'s matching test compares the nearest neighbor's distance to the next nearest neighbor distance to eliminate those unmatched feature points due to image occlusion and background confusion. The feature points with the top 2 closest Euclidean distance of their descriptors are involved in a ratio test. The feature point will be accepted only when the ratio between the Euclidean distance of testing feature point and the top 2 closest feature points is smaller than a critical threshold. A huge number of matching errors can be removed through the nearest ratio test. The recommended threshold is 0.8, but our study shows that the ratio is the best between 0.4 and 0.6. However the first layer is unable to find a set of errors clustered in one small region. We further designed the second layer, global distance test, for detecting those errors which have unreasonable space distribution in the picture. First of all, a distributed region is created by dividing the picture to a 4 \(\times\) 4 grid. In each grid, the dispersion of a matching pair can be represented with the standard deviation of the descriptor's Euclidean distance. The ratio \(\gamma\) between the euclidean distance of a descriptor and the standard deviation of the grid can describe the space distributed deviation in the grid. The feature point pair can be accepted when \(\gamma\) is smaller than a threshold which means the space distribution of this pair does not deviate from the average to much in the region. In general, the threshold of \(\gamma\) can be set between 0.1 and 0.3. Figure 10: Algorithm for Reducing Feature Points. An example of the matching pairs by applying our two-layer filter is shown as Figure 11. We show 3 matching layers in Figure 11. In each layer the picture on the left is the original picture stored in the library and the picture detected from the camera view is on the right.