A Model of Diameter Measurement Based on the Machine Vision

: If the shaft diameter can be measured in-situ during the ﬁnishing process, the closed-loop control of the shaft diameter processing process can be realized and the machining accuracy can be improved. Present work studies the measurement of shaft diameter with the structured light system composed of a laser linear light source and a camera. The shaft is a kind of part with rotationally symmetric structure. When the linear structured light irradiates the surface of the shaft, a light stripe will be formed, and the light stripe is a part of the ellipse. Therefore, the in-situ measurement of the shaft diameter can be realized by the light stripe and the rotational symmetry of the shaft. The measurement model of shaft diameter is established by the ellipse formed by the intersection of the light plane and the measured shaft surface. Firstly, in the camera coordinate system, normal vector of the light plane and the coordinates of the ellipse center are obtained by the calibration; then, the equation of oblique elliptic cone is established by taking the ellipse as the bottom and the optical center of the camera as the top. Next, the measurement model of shaft diameter is obtained by the established oblique elliptic cone equation and theoretical image plane equation. Finally, the accuracy of the measurement model of shaft diameter is tested by the checkerboard calibration plate and a lathe. The test results show that the measurement model of shaft diameter is correct, and when the shaft diameter is 36.162mm, the speed is 1250r/min, the maximum average measurement error is 0.019mm. The measurement accuracy meets the engineering requirement.


Introduction
Machine visual detection can realize noncontact and online detection [1][2][3], so application of the machine vision has been widely studied [4][5][6]. With the attention of industry being paid to the development of digital manufacturing and metrological support manufacturing, machine vision has also been widely used in industrial measurement [7][8][9][10]. Shen [11] proposed a method to detect the surface defects of bearing by machine vision. The measurement system was mainly composed of area scanning camera, lens, LED illuminator and hood, and the imaging of defects can be improved by controlling the image acquisition environment. This method can detect the deformation, rust, scratch and other defects on the bearing cover, and has high precision and efficiency. Moru et al. [12] developed an accurate gear measurement system based on machine vision. The system was mainly composed of software, sensor, camera and robot. Its calibration accuracy can reach 0.06 pixels, and the measurement algorithm was improved. Finally, the system realized the effective vision measurement of the gear. Wu et al. [13] proposed a vision measurement method based on three-line structured light to measure the diameter of the ball. After calibrating the internal parameters of the camera, the neural network algorithm was used to correct the camera distortion. Then, the three-line structured light system was calibrated, and the sub-pixel coordinates of the center of the light stripe were extracted to calculate the diameter of the ball. The measurement results meet the requirements of the measurement system. Bao et al. [14] realized the automatic reading measurement of the multi pointer instrument based on machine vision. During the measurement, the scales on the instrument root mean square error of measurement results was less than 0.5 mm. Zhang et al. [26] proposed a binocular stereo vision measurement method for the shape of large parts. A priori constraint was established to detect the boundary of the part, and the image edge compensation method was used to realize the initial edge extraction, and then the critical point of the edge laser stripe was extracted, so the contour of the part can be measured by the principle of binocular vision. The highest measurement accuracy was 0.33 mm.
There are two shortcomings in the above work: one is that the method with good measurement accuracy is only suitable for measuring small diameter; the other is that the model of measuring diameter is not unified, that is, the model is established for specific needs. In this paper, a shaft diameter measurement method is proposed using line structured light vision by establishing a unified model of diameter measurement. The block-diagram of the shaft diameter measurement method is shown in Figure 1. Compared with the existing vision measurement methods of the shaft diameter, this method can realize the in-situ and on-line measurement of shaft diameter only by a single image, so it features low cost and high efficiency. In addition, the established measurement model has good universality and accuracy, it is suitable for the measurements whose shape is ellipse (or circle) on the laser plane, and if the accuracy of the detected points on the ellipse can be guaranteed, the accuracy of the measurement results using the measurement model can be very high. The imaging principle of an ordinary camera is a pinhole model, and the pinhole model can be used to describe the actual three-dimensional imaging process of the camera, which can establish the relationship between the measured threedimensional coordinate points in space and two-dimensional coordinate points on image. Therefore, the pinhole model is suitable for three-dimensional measurement based on the two-dimensional image. However, the pinhole model has perspective projection distortion [27][28][29][30][31]. To solve the influence of the projection distortion on the measurement, an oblique elliptic cone representing the actual imaging process is derived, and then a universal vision measurement model for the shaft diameter is established. Finally, the validity and accuracy of the measurement model are verified by the experiment, and the measurement results meet the requirements.
of the wheel set can be calculated. The root mean square error of measurement results was less than 0.5 mm. Zhang et al. [26] proposed a binocular stereo vision measurement method for the shape of large parts. A priori constraint was established to detect the boundary of the part, and the image edge compensation method was used to realize the initial edge extraction, and then the critical point of the edge laser stripe was extracted, so the contour of the part can be measured by the principle of binocular vision. The highest measurement accuracy was 0.33 mm.
There are two shortcomings in the above work: one is that the method with good measurement accuracy is only suitable for measuring small diameter; the other is that the model of measuring diameter is not unified, that is, the model is established for specific needs. In this paper, a shaft diameter measurement method is proposed using line structured light vision by establishing a unified model of diameter measurement. The block-diagram of the shaft diameter measurement method is shown in Figure 1. Compared with the existing vision measurement methods of the shaft diameter, this method can realize the in-situ and on-line measurement of shaft diameter only by a single image, so it features low cost and high efficiency. In addition, the established measurement model has good universality and accuracy, it is suitable for the measurements whose shape is ellipse (or circle) on the laser plane, and if the accuracy of the detected points on the ellipse can be guaranteed, the accuracy of the measurement results using the measurement model can be very high. The imaging principle of an ordinary camera is a pinhole model, and the pinhole model can be used to describe the actual three-dimensional imaging process of the camera, which can establish the relationship between the measured three-dimensional coordinate points in space and two-dimensional coordinate points on image. Therefore, the pinhole model is suitable for three-dimensional measurement based on the two-dimensional image. However, the pinhole model has perspective projection distortion [27][28][29][30][31]. To solve the influence of the projection distortion on the measurement, an oblique elliptic cone representing the actual imaging process is derived, and then a universal vision measurement model for the shaft diameter is established. Finally, the validity and accuracy of the measurement model are verified by the experiment, and the measurement results meet the requirements. The structure of this paper is as follows. Section 2 establishes the model of shaft diameter measurement. Section 3 tests the model and analysis. Section 4 is the conclusion of the full text.

Establishment of the Model of Shaft Diameter Measurement
Because the ordinary industrial camera is used for the imaging, the model of diameter measurement is established by the principle of pinhole imaging. To establish the measurement model, the influence of the projection distortion on the measurement needs to be solved first. When the object surface is not parallel to the image plane, the projection The structure of this paper is as follows. Section 2 establishes the model of shaft diameter measurement. Section 3 tests the model and analysis. Section 4 is the conclusion of the full text.

Establishment of the Model of Shaft Diameter Measurement
Because the ordinary industrial camera is used for the imaging, the model of diameter measurement is established by the principle of pinhole imaging. To establish the measurement model, the influence of the projection distortion on the measurement needs to be solved first. When the object surface is not parallel to the image plane, the projection distortion causes dimension of the object surface corresponding to the pixels at different positions on the image to be different. Figure 2. To describe the ellipse formed by intersection of the light plane and the measured shaft surface, a world coordinate system is established. The origin of the world coordinate system is at optical center of the camera, the X−Y coordinate plane of the world coordinate system is parallel to the light plane, the X axis is parallel to long axis of the ellipse, the Y axis parallel to the minor axis, and the Z axis is perpendicular to the light plane. In this world coordinate system, the ellipse formed by the intersection of light plane and shaft surface can be expressed as:

System of shaft diameter measurement from the line structured light vision is shown in
where (t x , t y , t z ) are center coordinates of the ellipse, r is radius of the measured shaft, and θ is the angle between rotation axis of the measured shaft and the light plane.
distortion causes dimension of the object surface corresponding to the pixels at different positions on the image to be different. System of shaft diameter measurement from the line structured light vision is shown in Figure 2. To describe the ellipse formed by intersection of the light plane and the measured shaft surface, a world coordinate system is established. The origin of the world coordinate system is at optical center of the camera, the X -Y coordinate plane of the world coordinate system is parallel to the light plane, the X axis is parallel to long axis of the ellipse, the Y axis parallel to the minor axis, and the Z axis is perpendicular to the light plane. In this world coordinate system, the ellipse formed by the intersection of light plane and shaft surface can be expressed as: where ( , , ) x y z t t t are center coordinates of the ellipse, r is radius of the measured shaft, and θ is the angle between rotation axis of the measured shaft and the light plane. Oblique elliptic cone with ellipse of Equation (1) as the base and the camera optical center as the top can be expressed as: When the object surface is not parallel to the image plane, distance from each point on the object surface to the image plane is different. If the attitude of the object surface relative to the image plane is mastered in the imaging space (i.e., the camera coordinate system), we can know the influence of projection distortion on shaft diameter measurement. From mathematics, in the camera coordinate system, the position of the light plane relative to the image plane is determined by the coordinates  Oblique elliptic cone with ellipse of Equation (1) as the base and the camera optical center as the top can be expressed as: When the object surface is not parallel to the image plane, distance from each point on the object surface to the image plane is different. If the attitude of the object surface relative to the image plane is mastered in the imaging space (i.e., the camera coordinate system), we can know the influence of projection distortion on shaft diameter measurement. From mathematics, in the camera coordinate system, the position of the light plane relative to the image plane is determined by the coordinates (t x0 , t y0 , t z0 ) of the ellipse center and the normal vector (A, B, C) of the light plane. Therefore, the normal vector (A, B, C) of the light plane is used to determine the transformation relationship Q between the world coordinates Symmetry 2021, 13, 187 5 of 15 and the camera coordinates (see Appendix A). The world coordinates of Equation (2) are transformed into the camera coordinates by Q and written into matrix form: After the transformation matrix Q is multiplied by the coefficient matrix, the above formula is expressed as: The specific expressions of each parameter in the matrix are shown in Appendix B. Equation (4) represents an oblique elliptic cone with the ellipse formed by the intersection of the optical plane and the shaft surface as the base and the optical center of the camera as the top. Therefore, according to the principle of pinhole imaging, simultaneous Equation (4) and equation z = 1 can obtain the expression of the intersection line between the light plane and the shaft surface on the theoretical image plane: The coefficient of Equation (5) is only related to the measured shaft diameter (see Appendix B), that is, Equation (5) has only one unknown quantity. The measured shaft diameter can be obtained by fitting Equation (5) on the theoretical image. Therefore, Equation (5) is the model of shaft diameter measurement.

Test and Analysis of the Shaft Diameter Measurement Model
In order to verify the correctness and accuracy of the measurement model, a special test experiment is established. The structure of the test system is shown in Figure 3. The accuracy of the measurement model is related to the accuracy of the detected measurement points and the camera calibration. The calibration accuracy of the camera's intrinsic parameters, lens distortion parameters and external parameters can meet the requirements of vision measurement of shaft diameter [32]. Therefore, after calibrating the camera's internal parameters and distortion parameters, the influence of the accuracy of the measurement points on the accuracy of the measurement model is tested. The models and main parameters of the equipment used for the test are shown in Table 1. Since the error of detecting the square corner points of the calibration plate image is very small [33,34], the accuracy of the measurement model is tested by the corner points of the calibration plate to reduce the influence of measurement point error on the test. When testing, the surface of the calibration plate simulates the light plane. After calibrating the intrinsic parameters of the camera, the normal vector (A, B, C) and external parameter Z 0 of the calibration plate can be obtained by the detected corner coordinates. 4 corner points on the same circle are selected near the camera main point (to reduce the lens distortion) on the calibration plate, as shown in Figure 4. The symmetrical point of the 4 points is the center of the circle. The 4 points on the same circle on the calibration plate are located in the same ellipse on the image of the calibration plate. Therefore, the pixel coordinates of the ellipse center and four measuring points can be obtained by detecting the image, and the results are shown in Table 2. Then, in Table 2, Z 0 is the Z coordinate (the world coordinate) of the calibration plate.     According to the principle of least squares [35][36][37][38][39], the geometric fitting of the measurement model of Equation (5) is carried out by the data in Table 2, as shown in Equation (6).        According to the principle of least squares [35][36][37][38][39], the geometric fitting of the measurement model of Equation (5) is carried out by the data in Table 2, as shown in Equation (6).  According to the principle of least squares [35][36][37][38][39], the geometric fitting of the measurement model of Equation (5) is carried out by the data in Table 2, as shown in Equation (6).
where (x i , y i ) are the coordinates of the detected corner points; (x i , y i ) are the coordinates of the points which are both on the ellipse and perpendicular to the point (x i , y i ). The diameter of the circle, where the four points on the calibration plate is located, is obtained by optimizing Equation (6) using least squares geometric fitting [40][41][42]. In the experiment, two different known diameters determined by the grid size between the four corner points are selected as exact values for measurement, and the measurement experiment is repeated for 10 times to ensure the effectiveness. In order to verify the stability of the measurement method, change the position of the camera arbitrarily to test again. The position of the original camera is named position 1, and the changed camera position is named position 2. The diameter obtained by the optimizing is compared with the diameter determined by the grid size between the four corner points, as shown in Tables 3 and 4. The data in Tables 3 and 4 show that: the measurement model is correct, which can solve the influence of the projection distortion on the measurement and if the accuracy of the detected points is good, the measurement model has high measurement accuracy. On a CA6140 lathe, the measurement accuracy of Equation (5) is tested by measuring the shafts with different diameters, as shown in Figure 5. The measured shafts were installed between the three-jaw chuck and the top of the lathe. The camera is the same as the front test. The laser line source is LH650-80-3. The equation of the connection line between the three-jaw chuck and the top and the optical plane equation are calibrated by Liu and co-workers' method [21], the connection line equation calibration system structure is shown in Figure 6a, the optical plane equation calibration system structure is shown in Figure 6b. The normal vector of the optical plane in the camera coordinate system is obtained by the optical plane equation calibrated. Because the intersection line between the optical plane and the surface of the measured shaft is an ellipse, the coordinate of the ellipse center can be obtained by the optical plane equation and the equation of the connection line between the three-jaw chuck and the top. The coordinate transformation relationship Q is determined by the normal vector of the optical plane and the equation of the connection line between the three-jaw chuck and the top (see Table A1 and Equation (A13) in Appendix C).
As shown in Figure 7, (a) and (b) are the images of the light stripe on the shaft surface when the shaft does not rotate and it rotates, respectively. The midpoints of the light stripe images in Figure 7a are detected by the Steger method [43][44][45]. Moreover, the pixel coordinates of the detected midpoints are converted into theoretical image coordinates. The measurement accuracy of Equation (5) is tested by the theoretical image coordinates when the measured shaft does not rotate. Similarly, when the measured shaft rotates, the measurement accuracy of Equation (5) is tested by detecting the midpoint of the light stripe image in Figure 7b. The fit result of an ellipse on the theoretical image plane is shown in Figure 8. In addition, to ensure the validity of the experiment and the rigor of the research, each test is repeated 10 times, the final measurement results of three different shaft diameters are shown in Table 5. In Table 5, the roughness of the shaft is the average of three measurement values obtained by the roughness measuring instrument (TR200), and the known values of the shaft diameters are obtained by the micrometer measurement. The accuracy of the micrometer is 0.001 mm, and the average value of three measurement  Table 5 are the average values of repeated measurements.
shown in Figure 6b. The normal vector of the optical plane in the camera co system is obtained by the optical plane equation calibrated. Because the intersec between the optical plane and the surface of the measured shaft is an ellipse, dinate of the ellipse center can be obtained by the optical plane equation and the of the connection line between the three-jaw chuck and the top. The coordina formation relationship Q is determined by the normal vector of the optical p the equation of the connection line between the three-jaw chuck and the top (see and Equation (A13) in Appendix C).  As shown in Figure 7, (a) and (b) are the images of the light stripe on the shaft surface when the shaft does not rotate and it rotates, respectively. The midpoints of the light stripe images in Figure 7a are detected by the Steger method [43][44][45]. Moreover, the pixel coordinates of the detected midpoints are converted into theoretical image coordinates. The measurement accuracy of Equation (5) is tested by the theoretical image coordinates when the measured shaft does not rotate. Similarly, when the measured shaft rotates, the measurement accuracy of Equation (5) is tested by detecting the midpoint of the light stripe image in Figure 7b. The fit result of an ellipse on the theoretical image plane is shown in Figure 8. In addition, to ensure the validity of the experiment and the rigor of the research, each test is repeated 10 times, the final measurement results of three different shaft diameters are shown in Table 5. In Table 5, the roughness of the shaft is the average of three measurement values obtained by the roughness measuring instrument (TR200), and the known values of the shaft diameters are obtained by the micrometer measurement. The accuracy of the micrometer is 0.001 mm, and the average value of three measurement results of the micrometer is taken as the known value. The measured values in Table 5 are the average values of repeated measurements. As shown in Figure 7, (a) and (b) are the images of the light stripe on the shaft surface when the shaft does not rotate and it rotates, respectively. The midpoints of the light stripe images in Figure 7a are detected by the Steger method [43][44][45]. Moreover, the pixel coordinates of the detected midpoints are converted into theoretical image coordinates. The measurement accuracy of Equation (5) is tested by the theoretical image coordinates when the measured shaft does not rotate. Similarly, when the measured shaft rotates, the measurement accuracy of Equation (5) is tested by detecting the midpoint of the light stripe image in Figure 7b. The fit result of an ellipse on the theoretical image plane is shown in Figure 8. In addition, to ensure the validity of the experiment and the rigor of the research, each test is repeated 10 times, the final measurement results of three different shaft diameters are shown in Table 5. In Table 5, the roughness of the shaft is the average of three measurement values obtained by the roughness measuring instrument (TR200), and the known values of the shaft diameters are obtained by the micrometer measurement. The accuracy of the micrometer is 0.001 mm, and the average value of three measurement results of the micrometer is taken as the known value. The measured values in Table 5 are the average values of repeated measurements.    The data in Table 5 show that the measurement model Equation (5) is correct, and the measurement results meet the requirement, so in-situ and on-line measurement of shaft diameter can be realized by this method. However, compared with Tables 3 and 4, the measurement error increases, this is because the precision of the calibration plate is 1 μm, the error of detecting the midpoints of the light strip image is larger than the error of detecting the square corner points of the calibration plate image. In addition, when the surface roughness of the shaft is large, there is less specular reflection and more diffuse reflection [46]. When the rotation speed of the shaft becomes higher, this situation will be aggravated, which cause the image quality of the light stripe on the rotating shaft surface is worse than that on the stationary shaft surface, so that the measurement error of rotating shaft is larger than that of static shaft.

Conclusions
This paper studies the measurement of shaft diameter with the structured light system composed of a laser linear light source and a camera, which can realize the in-situ and on-line measurement of shaft diameter. Based on the ellipse formed by the intersection of the light plane and the surface of the measured shaft, the measurement model of shaft diameter is established on the theoretical image plane. The measured shaft diameter can be obtained by optimizing the measurement model with the detected points on the ellipse. The measurement model requires axis of the measured shaft to be unchanged in the position of the machine tool, and general processing machine tools meet this re-  The data in Table 5 show that the measurement model Equation (5) is correct, and the measurement results meet the requirement, so in-situ and on-line measurement of shaft diameter can be realized by this method. However, compared with Tables 3 and 4, the measurement error increases, this is because the precision of the calibration plate is 1 µm, the error of detecting the midpoints of the light strip image is larger than the error of detecting the square corner points of the calibration plate image. In addition, when the surface roughness of the shaft is large, there is less specular reflection and more diffuse reflection [46]. When the rotation speed of the shaft becomes higher, this situation will be aggravated, which cause the image quality of the light stripe on the rotating shaft surface is worse than that on the stationary shaft surface, so that the measurement error of rotating shaft is larger than that of static shaft.

Conclusions
This paper studies the measurement of shaft diameter with the structured light system composed of a laser linear light source and a camera, which can realize the in-situ and on-line measurement of shaft diameter. Based on the ellipse formed by the intersection of the light plane and the surface of the measured shaft, the measurement model of shaft diameter is established on the theoretical image plane. The measured shaft diameter can be obtained by optimizing the measurement model with the detected points on the ellipse. The measurement model requires axis of the measured shaft to be unchanged in the position of the machine tool, and general processing machine tools meet this requirement. The experimental results show that the measurement errors of three shafts with different shaft diameters at different speeds are 0.11-0.19 mm, so the measurement model of shaft diameter is accurate, and the measurement accuracy is high, which meets the engineering requirement. Compared with the existing vision measurement technology of the shaft diameter, the measurement method not only solve the influence of the projection distortion on the measurement, but also has good universality, that is, as long as the measurement shape on the laser plane is an ellipse (or a circle, which is the special shape of the ellipse), the measurement method is applicable.
If the detected points have higher accuracy, such as the precision of detecting the square corner points on the calibration plate, the measurement accuracy of the measurement model can be higher. The main factor affecting the measurement accuracy of the model is the error of the detected points on the ellipse, and the error is mainly affected by the surface roughness and the rotation speed of the shaft. Therefore, based on this measurement model, if a higher-precision measurement of the shaft diameter is required, to study the influence law of shaft surface roughness and rotation speed on the detection accuracy of the light stripe center is a desirable research direction.

Data Availability Statement:
The data presented in this study are available on request from the corresponding author.

Acknowledgments:
The authors are grateful to the editors and the anonymous reviewers for providing us with insightful comments and suggestions throughout the revision process.

Conflicts of Interest:
The authors declare no conflict of interest.

Appendix A
Normal vector (A, B, C) of the light plane can be obtained by the calibration board. So, the equation of the light plane is expressed as: Firstly, the direction cosine of the Z axis of the world coordinate system in the camera coordinate system is determined by the normal vector of the light plane: e 13 = A/ A 2 + B 2 + C 2 , e 23 = B/ A 2 + B 2 + C 2 , e 33 = C/ A 2 + B 2 + C 2 (A2) Then, the equation of the connection line between the three-jaw chuck and the top of a lathe is obtained by the calibration of using the device and method [21] in the camera coordinate system. a 1 31 x + a 1 32 y + a 1 33 z − t 1 = 0 a 2 31 x + a 2 32 y + a 2 33 z − t 2 = 0 (A3) In the planes passing through the connection line between the three-jaw chuck and the top, one plane is perpendicular to the light plane, and according to the point product of the normal vectors of the two planes is 0, the plane is obtained: λ(a 1 31 x + a 1 32 y + a 1 33 z − t 1 ) + (a 2 31 x + a 2 32 y + a 2 33 z − t 2 ) = 0 (A4) where λ = −(Aa 2 31 + Ba 2 32 + Ca 2 33 )/(Aa 1 31 + Ba 1 32 + Ca 1 33 ). The equation of the intersection line between the plane of Equation (A4) and the light plane is: (λa 1 31 + a 2 31 )x + (λa 1 32 + a 2 32 )y + (λa 1 33 + a 2 33 )z − (λt 1 + t 2 ) = 0 Ax + By + Cz + 1 = 0 (A5) According to Equation (A5), the direction cosine of the X axis of the world coordinate system in the camera coordinate system is: Finally, the direction cosine of the Y axis in the camera coordinate system is obtained by cross product of the direction numbers of the Z axis and X axis according to the right-hand rule. e 12 = e y1 / e 2 y1 + e 2 y2 + e 2 y3 , e 22 = e y2 / e 2 y1 + e 2 y2 + e 2 y3 , e 32 = e y3 / e 2 y1 + e 2 y2 + e Because the measured shaft is installed between the three-jaw chuck and the top of the lathe, the coordinates (t x0 , t y0 , t z0 ) of center of the ellipse formed by the intersection line between the light plane and the measured shaft surface can be obtained by Equation (A1)