# Measurement of Large-Sized-Pipe Diameter Based on Stereo Vision
## 2 Materials and Methods
### Point-Cloud Registration  
Each set of binocular cameras eventually provides a group of point clouds about a certain arc of the measured cross section, but, at this point, each group of point clouds has its own coordinate system and the different groups need to be registered for standardization in a single coordinate system. The flow chart of point-cloud registration is shown in Figure 7, which is divided into two parts: correspondence matching and transformation estimation. In practical-application scenarios, the approximate relationship between the two cameras in each set is known: the right half of the feature points acquired by the left camera and the left half of the feature points acquired by the right camera are corresponding points. Therefore, in the correspondence-matching process, based on fitting of the circle center of each group of point clouds, the angle formed by two adjacent points and the center of the fitted circle is calculated. The two sets of angles are then moved toward each other continuously to enable calculation of angle correlation. The matching result with the highest degree of correlation is taken as the final matching result of corresponding points. SVD is a widely used method for solving rigid-body transformations. It not only uses principal component analysis (PCA) to construct distance errors between point clouds but also solves rotation matrices and translation vectors with the least-squares method. However, due to factors such as ambient light and feature-point-extraction accuracy, there is noise in the reconstructed 3D point clouds. That is to say, the 3D points are not strictly on a plane. In the point-cloud registration of the section circle, the ideal transformation results of the two groups of point clouds is in the same plane and form an arc. However, since the traditional SVD only considers the Euclidean distance between corresponding points, it is easy to fall into a local minimum, resulting in an angular difference between the two groups of point clouds after conversion, which affects the measurement accuracy. Therefore, in this paper, the result of rigid-body transformation obtained by SVD is used as the initial value and the difference between the plane normal vectors of the two groups of point clouds is used as the constraint condition to construct a Newton-Gaussian solving algorithm. The schematic diagram of the algorithm is shown in Figure 8.  
Figure 7: Flow chart of point-cloud registration. Points \(p_{a}\) and \(p_{b}\) are corresponding points of point clouds \(A\) and \(B\), respectively, and \(n_{a}\) and \(n_{b}\) are the normal vectors of the entire point clouds \(A\) and \(B\). The matching vector is expanded to \(P=[p^{T}\ n^{T}]^{T}\). On the basis of the error function \(e_{i}(T)\), an objective function \(T^{*}\) is constructed:  
\[\left\{ \begin{array}{c}e_{i}(T)=P_{i}^{B}-T\otimes P_{i}^{A}\\ T^{*}=\sum e_{i}(T)^{T}\Omega e_{i}(T)\end{array} \right., \tag{6}\]  
where \(T\otimes P=\left[ \begin{array}{c}Rp+t\\ Rn\end{array} \right]\) and \(\Omega=\left[ \begin{array}{cc}I&0\\ 0&\lambda I\end{array} \right]\), which is the information matrix. The weight of the normal-vector constraint is determined by changing \(\lambda\). With the Gauss-Newton iteration method, the objective function is minimized through local parameterization using incremental perturbations and the optimal \(T\) is solved through iterations. The incremental equation is expressed as  
\[(H+I)\Delta T=b, \tag{7}\]  
where \(H=\sum J_{i}^{T}\Omega J_{i}\) is the approximate Hessian matrix and \(J_{i}\) is the Jacobian matrix of error with respect to disturbance; \(\Delta T=\left[\Delta t_{x},\Delta t_{y},\Delta t_{z},\Delta t_{x},\Delta t_{y},\Delta t_{z}\right]^{T}\), including the translation vector \(\Delta t\) and the imaginary part \(\Delta q\) of the four-element rotation unit; and \(b=\sum J_{i}^{T}\Omega e_{i}(T)\). The transformation-solving steps are described as follows: SVD is used to obtain the initial transformation \(T_{0}\).