Development of a measuring system for the diameter of a smooth plug gauge based on machine vision technology

Aiming at the problems of low efficiency of the traditional method for detecting smooth plug gauges and poor repeat accuracy of measurement parameters, a measuring system for the diameter of a smooth plug gauge based on machine vision technology is designed. This system drives the work-piece to move by two-dimensional work platform and collects image data through CCD, and the diameter parameters of the smooth plug gauge are obtained by processing the image which uses the threshold neighborhood location and segmentation method. In this paper, the mechanical structure and control structure of the measuring system are designed, the measurement principle and calibration method are explained, the relationship between the diaphragm and the threshold value under a fixed light intensity, and the relationship between the light intensity and the threshold value under a fixed diaphragm are studied. Finally, experiments have verified that the measuring system can complete the measurement efficiently, automatically, and with high precision within 20 s, and the repeatability of the measurement does not exceed 1 μm.


Introduction
The measurement of hole parts is one of the important contents in the machinery manufacturing industry. In mass manufacturing industries such as automobiles and aerospace, high precision and high efficiency requirements are put forward for the inspection of hole parts. In production practice, the inspection of hole parts is widely used for measuring with smooth limit gauges. However, due to frequent use, the smooth limit gauge wears quickly, and it is necessary to be frequently measured to ensure that its own dimensions are qualified. 1 In recent years, the measurement technology based on machine vision has developed rapidly. It has become more and more widespread to use machine vision instead of human vision to engage in various industrial detection, target tracking, and other activities instead of human vision. [2][3][4] Photoelectric detection technology is an advanced detection technology in the field of measurement technology. [5][6][7] Especially in Japan, Germany, and the United States, due to the constant emphasis on the development of optical applications, some achievements have been obtained in the development of related measuring system. For example, Japan's Kyoto Industry Group has developed ST-370 series laser displacement meters, and its measurement accuracy reaches 60.0075 mm. The measurement accuracy of the DLG series external measuring system produced by German company reaches 60.3 mm. The measurement accuracy of American Auto-B3 series measuring system reaches 60.1 mm. 8 In many measuring systems which used the machine vision technology, it measures accurate data by acquiring the overall image which has high requirements on the performance of the imaging equipment and poor economy. [9][10][11] A kind of image measuring instrument is studied in this paper. It only needs to calibrate the system once to achieve long-term measurement, and there is no human error, and it has very low requirements for the operator. It can realize automatic measurement with one key. It is not only economical but also high efficiency.
In this paper, a new measurement method is proposed, which is different from traditional optical measurement and the measurement which used the overall image. It takes high-precision images of part of the profile of the work-piece, which is obtained through multiple acquisitions. The image segmentation uses the threshold neighborhood location and segmentation method. In addition, combining the reading data of the raster ruler, the outer diameter of the plug gauge is measured. This method has no human error, good repeatability, and high accuracy that can reach 1mm.

Mechanical structure design
There are many structural designs of outer diameter measuring systems, Gao et al. 12 designed the system for diameter measurement, which applied structural design of infinity optical objective. The design of the measuring system in this paper includes structures such as raster ruler and surface light source. The overall design of the mechanical system is shown in Figure 1. It mainly includes the support 9, the pedestal 11, the X workbench 12 which moves perpendicular to the paper, the Y workbench 15 which moves parallel to the paper, the linear guides 8 and 14, the arc guide 5, the seat of cone 16, the upright 17, the locking device 4, the CCD camera 2, the handle 1, and other components. The mechanical structure is mainly used to provide support and location for the photoelectric system and the workpiece be measured.
The boundary of the plug gauge is one of the objects of study. In order to obtain a more accurate plug gauge boundary image, the local boundary image of the plug gauge is obtained with the same camera resolution. Therefore, the system uses a two-dimensional stage with two stepper motors and raster rulers to measure the diameter of plug gauge.

Control system design
The control part of the smooth plug gauge outer diameter measuring system includes the raster and its subdivision box, the stepper motor and its motor drive, the digital microscope and its data bus, the light source and its power supply, etc. Its control system block diagram is shown as in Figure 2.

Motion control scheme
The smooth plug gauge outer diameter measuring system adopts the two-dimensional photoelectric measurement. The X workbench and Y workbench are driven by a driving device composed of a stepping motor and a ball screw, but the location is positioned by raster and raster signal processor. The digital microscope is positioned by a upright, a guide tube, and a set of worm gears. In order to maintain the work-piece perpendicular to the axis of camera, a three-coordinate measuring instrument is used to measure and grind the contact surface is polished when the upright is installed.
Before the measurement process, the length l of the working face of the work-piece to be measured and the general diameter d of the work-piece to be measured must be input, because they are used when the origin of the image coordinate system is determined in the program.
During the measurement process, the CCD takes pictures of n transverse points on one side of the workpiece, and the movement of this process is controlled by X-axis raster ruler, X-axis stepper motor and software. In order to obtain images of n points on the other side, the Y-axis stepper motor controlled by the Y-axis raster ruler and software is used to move to the other side of the work-piece. Through these steps, the motion control of the measurement is completed. As shown in Figure 3, processes 1, 2, and 3 constitute the entire measurement motion control process.

Measuring principle
There are many methods to measure the outer diameter. Liu et al. 13 proposed a new measurement method for a tube's endpoints based on machine vision. Hsu et al. 14 propose a quadratic transformation method used to describe the relationship between the image coordinates and the world coordinates. The measuring system in this paper also involves the X-Y and U-V coordinate systems.
The main feature of the smooth plug gauge outer diameter measuring system is that the system involves the use of two coordinate systems, which are the orthogonal raster coordinate system X-Y formed by the Xaxis and Y-axis raster rulers and the image coordinate system U-V of the image measuring system. The raster coordinate system X-Y whose unit adopts the length unit system commonly used in engineering measurement is defined as an absolute coordinate system and the image coordinate system U-V, as shown in Figure 4, whose position of the image coordinate system relative to the raster coordinate system can be changed as a relative coordinate system. The two axes of the image   coordinate system should be parallel to the two axes of the raster coordinate system. The next step is equivalent calculation. The image obtained by the image measuring system is in pixels, so the measurement unit of an image with a size of m 3 n should be converted into that in the raster coordinate system, based on the area i 3 i of each photoelectric conversion element and the magnification k of the optical lens, then the equivalent conversion coefficient is obtained as m = i/k. In this way, the conversion factor of the equivalent calculation is obtained. When the work-piece is placed between the light source and the microscope, the part hidden by the work-piece in the image is black, otherwise is white. The edge of the work-piece forms a gray transition zone due to light diffraction and other reasons, and it increases the difficulty of work-piece detection. But through a large number of experiments, the gray threshold b at which the work-piece is accurately measured can be obtained. When being measured, the edge of the work-piece may not be parallel to the axis of the coordinate system. The measuring system obtains the images of the detection points a and b on the work-piece c, and extracts the edge of the image with the gray threshold b. The origin coordinates of the image coordinate system can be obtained from the raster ruler which are (X 1 , Y 1 ) and (X 2 , Y 2 ). Therefore, the coordinates of point a and point b are (X 1 + mU 1 , Y 1 + mV 1 ) and (X 2 + mU 2 , Y 2 + mV 2 ). Then, the dimension L between the two points a and b can be calculated according to the following formula (1): The image edge line l1 and the edge line l2 can also be obtained through the slopes of the two points a and b. Assuming that they are K 1 and K 2 , the angle g can be calculated according to the following formula (2): Then, the diameter d of smooth plug gauge can be calculated according to the following formula: The measuring system adopts advanced measurement principles which can effectively avoid errors caused by non-parallelism between the edge of the work-piece and the image coordinate system.

The principle of CCD calibration and calibration process
The CCD calibration is a very critical part, and Xiong et al. 15 propose a method to calibrate the CCD in the frequency domain. Ma et al. 16 presente a line-scan camera calibration method in a plane not perpendicular to but parallel to the optical axis, without requiring the camera motion or a complex calibration pattern. Peng et al. 17 present a precise calibration method for a CCD with a small field of view. In the design of this paper, CCD calibration is based on raster ruler and resolution.
The calibration of the pixel size of the digital microscope is carried out by using a standard rod with diameter D. The standard rod is clamped on the measuring system. According to the image on the computer display, the height of the guide tube and the position of the CCD should be adjusted and changed until the edge of the standard rod is clear. The edge of the standard rod is moved to the middle of the image coordinate system, and the edge state characteristics and the position of the raster coordinate system are recorded. The transition zone threshold at this time is used as the segmentation threshold to extract the edge of the image, and the curve equation of the edge is obtained by fitting. Then the X direction is kept unchanged, and the standard rod is moved to the other side along the Y direction. When the edge state feature is basically the same as the previous one, the coordinate position of the raster coordinate system is recorded. The edge of the image at this time is extracted by using the previous transition zone threshold, and the curve equation of the edge is obtained by fitting. According to the reading of the raster and the resolution of the digital microscope, the actual size of the pixel in the current state can be calibrated.
A standard rod with a diameter of D is used as a debugging part. Figure 5 shows a schematic diagram of the calibration process. The magnification k of the optical lens is adjusted, and the digital image of edge is represented by a 14 3 10 square grid. When the image coordinate system is XOY, the reading D 1 of the raster is read and recorded. The digital image at point A is acquired and threshold-ed. Then the image coordinate system is moved to the other side X#O#Y# of the standard rod, the reading D 2 of the raster is read and recorded. The digital image at point B is acquired and thresholded. Therefore, the reading difference of the raster is n# = D 2 2 D 1 . Because the resolution of the digital microscope is m3n, the pixel position of point A in the digital image is calculated, assuming it is (n i , n j ). Similarly, B is (n i #, n j #). It is known that the actual length l# of the raster ruler and the raster ruler is subdivided into N divisions. Then, the actual distance of each division of the raster is l#/N. The position of A in the image is represented by (x A , y A ), the pixel size is represented by m, and the number of rows and columns of A and B in the digital image are represented by n i , n j , n i #, n j #. Then the coordinates (x A , y A ) and (x B , y B ) are: According to the calculation formula (3), the calculation formula for the diameter D of the standard rod can be deduced. Furthermore, the calculation formula (4) for the pixel size m can be deduced too. It is: Image processing

Image processing and acquisition of plug gauge boundaries
The process of digital image processing is shown in Figure 6. As shown in the Figure 3, the motion control scheme consists of three processes. The images obtained in process 1 are processed to form one boundary of the plug gauge and the images obtained in process 3 are processed to form the other boundary of the plug gauge, as shown in Figure 7.

Image threshold neighborhood location and segmentation method
The image segmentation of the measuring system uses the threshold neighborhood location and segmentation method. Because the resolution of the image acquired by the image sensor is m 3 n, the image is stored in the computer in the form of a two-dimensional matrix with m rows and n columns. Therefore, there are m grayscale values in each column of the matrix and n grayscale values in each row. Image segmentation is also based on this two-dimensional matrix. A threshold b and a neighborhood radius a are selected, so the neighborhood of the threshold is (b 2 a, b + a). The average grayscale value of the overall image is selected as the initial threshold b 0 . The image is segmented into two parts by the initial threshold. The average grayscale value of each part are calculated as b 1 and b 2 . Then the threshold b and the neighborhood radius a are: A two-dimensional array Z(x, y) is used to store data. Its x is used to store the number of columns, and y is used to store the average value of all gray levels in the threshold neighborhood of each column. If all the grayscale values of a column are not in the neighborhood of the threshold, then y is 21. Each column is validated from left to right, and the points whose y value is 21 are deleted. Finally, a two-dimensional  array is obtained, and the value in it is the grayscale value of the real edge, as shown in Figure 8. The value of x in the two-dimensional array Z is used as the ordinate and the value of Y is used as the abscissa. The straight line is obtained by the least squares method and the slope of the edge straight line is obtained, which will be used in the calculation of the measurement results later.
As shown in Figure 7, after the acquired images are processed according to the above method, the pictures obtained in process 1 and 3 are sequentially placed on a horizontal plane. Because of the gap between the guide rail and the slider, the workbench will have uncertain offset in the process of movement. It will be found that the plug gauge boundary of each picture is not on a horizontal line. In order to obtain the entire boundary of the plug gauge, p n points are evenly selected on the boundary of each segment. As shown in Figure 9, the straight line L is obtained by using the least squares method to fit all n 3 p n points, and it is one boundary of the plug gauge. In the same way, the other side boundary of the plug gauge can be obtained, and the diameter of the plug gauge can be obtained by using the measurement principle shown in Figure 3.

The relationship between threshold and diaphragm
In the measuring system, a surface light source is used. Bernard et al. 18 study the relationship between filters and light sources, etc. Bruehl et al. 19 discuss the existence of control holes and slits. In order to minimize the impact of non-parallel light on the edge image of the work-piece, a diaphragm is installed between the work-piece and the light source, as shown in Figure 10.
Therefore, it is necessary to find the relationship between the threshold value and the diaphragm width during image segmentation under a fixed light intensity. The experiment was carried out under the conditions of light intensity of 160, temperature of 21°C, and humidity of 42%. The relationship between the threshold and the width of the diaphragm during image segmentation was found through the experiments. Taking the measurement data of a 30 mm diameter smooth plug gauge as an example, and the accurate value of its outer diameter measured by thread measuring machine (XPL-C200, IAC, NLD) is 30.00465 mm.
Before the measurement, high-strength alcohol was used for cleaning the surface of the plug gauge and a marble temperature table was used to set the temperature of it in the metrology laboratory. The measured data is shown in Table 1.    The data in the table need attention. For example, when the diaphragm width is 7 mm and the threshold value is 63, the outer diameter measurement value is slightly smaller than the accurate value; when the threshold value is 64, the measurement value is slightly larger. The boundary of the plug gauge is extracted respectively at the thresholds 63 and 64, then their intermediate value is taken as the boundary data for the final measurement calculation. To represent this situation, a non-integer threshold is used.
The relationship between the threshold value and the diaphragm width is displayed as a smooth curve, as shown in Figure 11, it contains smooth plug gauges with a diameter of 3, 10, 20, 30, 40, and 50 mm.

The relationship between threshold and light intensity
As shown in Figure 12, the experiment of threshold and light intensity is used to illustrate the clarity of the boundary at different light intensities. In algorithm, Baigvand et al. 20 compared the feature values with the threshold values which are predetermined by an expert. In this paper, because that the light intensity is less than 120 will make the image of the work-piece dark, image threshold processing can only be carried out in a very small threshold range, and a small threshold change will cause a large deviation in the grayscale value of the edge of the work-piece. The same effect will be caused when the light intensity is higher than 190. Therefore, the appropriate light intensity will reduce the difficulty of system debugging.
Therefore, it is necessary to find the relationship between the threshold value and the light intensity during image segmentation under the condition of a fixed diaphragm. The experiment took the diaphragm of 7 mm as an example, and was carried out at a temperature of 23°C and a humidity of 52%. The data in Table 2 is the measurement data of a 30 mm diameter smooth plug gauge, and the accurate value of its outer diameter measured by thread measuring machine (XPL-C200, IAC, NLD) is 30.00465 mm.
The relationship between the threshold and light intensity is displayed as a smooth curve, as shown in Figure 13, it contains smooth plug gauges with a diameter of 3, 10, 20, 30, 40, and 50 mm.    Figure 13. The relationship between threshold and light intensity.

Experiment and analysis
As shown in Figure 14, it is the physical image of the smooth plug gauge outer diameter measuring system. Under the experimental conditions of room temperature of 23°C, a diaphragm of 7 mm, a light intensity of 169, and a humidity of 45%, the data of smooth plug gauges with diameter range from 1.3 to 50 mm were measured, and the exact value of their outer diameters was measured by thread measuring machine (XPL-C200, IAC, NLD).
The measurement data is shown in the Table 3. After a lot of experiments, it is found that a plug gauge of certain has a corresponding threshold that enables the plug gauge to be accurately measured.

Conclusions
In this work, a measuring system for the diameter of a smooth plug gauge based on machine vision technology was successfully developed. Different from conventional image measurement that take overall image to obtain accurate data, it takes high-precision images of part of the profile of the work-piece. The profile of the work-piece is obtained through multiple acquisitions.The image segmentation uses the threshold neighborhood location and segmentation method. In addition, the use of advanced measurement principles can effectively avoid errors caused by the nonparallelism of the work-piece edge and the image coordinate system. The system can automatically, efficiently and accurately measure the diameter parameters of a smooth plug gauge with high measurement repeatability. The relationship between the diaphragm and the threshold under the fixed light intensity and the relationship between the light intensity and the threshold under the fixed diaphragm are simultaneously studied.
Experimental results demonstrated that: (1) The diameter range measured by the system is 0-50 mm which is clearly proposed by the research purpose. (2) The measurement accuracy and repeat measurement accuracy of the system are verified, and the measurement errors are less than 1 mm. (3) The repeatability of the measurement does not exceed 1 mm. Figure 14. The physical picture of the measuring system.