# Measurement of Large-Sized-Pipe Diameter Based on Stereo Vision
## 2 Materials and Methods
### Parameter Estimation  
Through 3D reconstruction of feature points and point-cloud registration, 3D point clouds of the measured pipe cross section are obtained. However, it is also necessary to fit a three-dimensional circle to obtain the geometric center and diameter of the measured cross section and other dimensional information.  
The least-squares method is a method for parameter estimation of regression models from the perspective of error fitting. It finds the best function matching of data by minimizing the squared sum of errors. Hence, we use the least-squares method for spacial circle fitting. We do not explain here the mathematical solution model of spacial circle fitting with least squares. Instead, we focus on how to establish an overdetermined equation based on plane fitting with the knowledge that the perpendicular bisector of the segment connecting any two points of a planar circle always passes the center of the circle.  
Figure 8: Schematic diagram of point-cloud registration.  
For the three-dimensional point set \(X[[x_{1},y_{1},z_{1}],[x_{2},y_{2},z_{2}]\dots\dots\)\([x_{n},y_{n},z_{n}]]\), the overdetermined equation can be established with least squares, and its planar normal vector \(N\) is obtained:  
\[\left\{\begin{array}{ccc}N=\left(M^{T}M\right)^{-1}M^{T}L_{1}\\ M=\left[\begin{array}{ccc}x_{1}&\dots&x_{n}\\ y_{1}&\dots&y_{n}\\ z_{1}&\dots&z_{n}\\ L_{1}=[1,1\dots 1]^{T}\end{array}\right]\\ L_{1}=[1,1\dots 1]^{T}\end{array}\right., \tag{8}\]  
Since the perpendicular bisector of the segment connecting any two points of a planar circle always passes the center of the circle, the overdetermined equation is constructed again, and the coordinates \(C[x_{0},y_{0},z_{0}]\) of the center of the circle are obtained:  
\[\left\{\begin{array}{ccc}C=\left(\left[\begin{array}{cc}B^{T}B\\ A\end{array}\right]^{T}\left[\begin{array}{cc}B^{T}B\\ A\end{array}\right]\right)^{-1}\left[\begin{array}{cc}B^{T}B\\ A\end{array}\right]^{T}\left[\begin{array}{cc}B^{T}L_{2}\\ 1\end{array}\right]\\ B=\left[\begin{array}{ccc}\Lambda x_{12}&\dots&\Lambda x_{(n-1)n}\\ \Lambda y_{12}&\dots&\Lambda y_{(n-1)n}\\ \Lambda z_{12}&\dots&\Lambda z_{(n-1)n}\end{array}\right]^{T}\\ L_{2}=\left[\begin{array}{c}l_{1}\\ \dots\\ l_{n-1}\end{array}\right]\end{array}, \tag{9}\]  
where \(\Lambda x_{(n-1)n}=x_{n}-x_{n-1}\) and \(l_{i}=\frac{x_{1+1}^{2}+y_{1+1}^{2}+z_{1+1}^{2}-x_{1}^{2}-y_{1}^{2}-z_{1}^{2}} {2}\).  
Finally, twice the average distance from all points to the center of the circle is used as the diameter \(d\) of the fitted circle:  
\[d=\frac{2}{N}{\sum_{i=1}^{N}\sqrt{\left(x_{i}-x_{0}\right)^{2}+\left(y_{i}-y_{ 0}\right)^{2}+\left(z_{i}-z_{0}\right)^{2}}}, \tag{10}\]  
It is noted that the measurement method proposed in this paper uses only the upper profile of the pipe to evaluate the diameter. In precision coordinate measurement, the differences in the arc length of the sampling points and the ovality of the measured pipe lead to different deviations when evaluating the diameter by the least-squares method. Simulations and analysis are therefore carried out to investigate their relationships and to verify the rationality of the system design.  
In simulations, the major axis of the ellipse is set to 300 mm and the ovality is set to vary from 0.0% to 1.5% with a step of 0.1%. The range of central angle corresponding to arc that envelopes the sampling points is set from 1\({}^{\circ}\) to 360\({}^{\circ}\) with a step of 1\({}^{\circ}\), and each degree of central angle contains three the sampling points. Using the proposed method to calculate the diameter of simulated pipe, the error distribution of the pipe diameter is shown in Figure 9.  
If the permitted error of the pipe diameter is within 1 mm, it is seen from the simulations that the maximum required central angle is 168\({}^{\circ}\), considering the ovality varies from 0.0% to 1.5%. That is to say, to ensure the measurement accuracy of the diameter, the central angle enveloping the sampling points must be larger than 168\({}^{\circ}\).