# Pose Measurement Method Based on Machine Vision and Novel Directional Target
## 3 Methods
### Algorithms Related to Target Image Processing
#### 3.2.2 Ellipse Fitting Based on the RANSAC Algorithm  
In the final image-matching stage, model parameters must be estimated for the sample set obtained from coarse matching. However, due to image noise, etc., coarse matching based simply on the magnitude of the Euclidean spatial distances to find possible matches to the current point from the mapped set of points does not directly determine that these matches conform to the desired mapping model. In the ellipse fitting problem, this is manifested in the elimination of discrete or noisy points from a sample set in the ellipse fitting so that the elliptic equation obtained is more in line with reality compared to the elliptic model directly fitted with all the sample points, but it also further eliminates the error brought by the noise for the influence of the coordinate centre of the feature points to make the model parameter estimation to maintain a better robustness. Therefore, to better remove the mismatched points in the sample set, the RANSAC algorithm is introduced into the process of the least squares fitting ellipse through which the points with higher dispersion of the ellipse edges are removed to improve the accuracy of the ellipse centre further.  
The RANSAC algorithm can divide all points into out-of-bounds and in-bounds points. The in-local points are the points whose distance to the model is less than a set threshold, and the out-local points are the points whose distance to the model is greater than the threshold, i.e., noise. Taking fitting an ellipse as an example, the number of iterations is set to 100, and the algorithm process is shown in Algorithm 1.  
```
1:Set of data points \(\mathbf{P}\), number of iterations \(\mathbf{T}\), fitting threshold threshold
2:Best model parameters (a, b, c, d, e, f)
3:Best model parameters \(\leftarrow\) empty
4:Best model support count \(\leftarrow\) 0
5:for\(\mathbf{t}\gets 1\) to \(\mathbf{T}\)do
6:Randomly select the minimum required set of data points \(\mathbf{P}^{\prime}\) as the candidate set
7:Fit an ellipse model using \(\mathbf{P}^{\prime}\), obtaining parameters (a\({}^{\prime}\),b\({}^{\prime}\),c\({}^{\prime}\),d\({}^{\prime}\),e\({}^{\prime}\),f)
8:Current model support count \(\leftarrow\) 0
9:for each data point \(\mathbf{p}\) in \(\mathbf{P}\)do
10: Calculate the distance from \(\mathbf{p}\) to the ellipse
11:if distance is less than threshold then
12: Increment the current model support count
13:if current model support count \(>\) best model support count then
14: Update best model parameters and support count
15:endif
16:endif
17:endfor
18:Return Best model parameters (a, b, c, d, e, f)
```  
Figure 4: Visual camera external reference. (**a**) Camera-centred, (**b**) target-centred.  
Finally, by using the fitting results, the key parameters of the elliptic equation can be obtained, and the centre coordinates of the ellipse can be calculated. Consider the outer circle of the circular ring as an ellipse, and there are a total of 441 feature circles on the target. By repeating the above steps, all 441 centre points can be obtained.