Measurement method of pillow spring based on machine vision

In the current maintenance of pillow springs of railway freight cars in our country, the measuring method of manually using measuring scale and measure gauges is still common. In order to improve the quality and efficiency of the pillow spring measurement, and to support the automatic upgrade of the pillow spring maintenance line, a new method for measuring the size of the pillow spring based on machine vision is proposed. By analyzing the requirements and characteristics of pillow spring detection and matching, a visual measurement system was designed to replace manual measurement, and openCV was used for image processing, feature extraction and size calibration. Compared with manual measurement, the measurement accuracy and efficiency of this method are higher. Experiments were conducted under different lighting conditions, and the measurement results have good repeatability and stability, indicating that the method has good robustness to the light intensity of the pillow spring environment.

MMEAT 2021 Journal of Physics: Conference Series 1986 (2021) 012118 IOP Publishing doi: 10.1088/1742-6596/1986/1/012118 2 has begun to be applied in fields such as mechanical parts and agricultural products.For example, the paper [4][5][6][7] proposed some machine vision-based dimensional inspection technologies for bearing inner and outer rings, aviation rivets, brake pads and other workpieces; The paper [8] improves the accuracy of the bearing measurement by improving the median filter; the paper [9] compares the image of the standard part with the image of the measured part to measure the machining error of the workpiece; in the paper [10][11][12] Applying machine vision technology to the size and shape detection and classification of mango, perilla leaves and corn; Paper [13] designed a machine vision-based measurement method for the end face size of turnout rail parts; In the paper [14] , a double projection-based hole size measurement method was proposed. The phase shift method is used to calculate the phase of the grating image in two directions, and the reconstructed 3D shape in two directions is combined to measure the hole size.
The existing pillow spring measurement technology has low work efficiency and is difficult to adapt to the intelligent development of bogie maintenance. Due to the special structural characteristics of the pillow spring and the complicated measurement environment, the existing measurement methods based on machine vision technology are difficult to be fully applicable. Therefore, for the specific detection object of the pillow spring, this paper studies and designs a method for measuring the size of the pillow spring based on machine vision technology, which realizes the measurement of the free height and diameter of the pillow spring.

System design and workflow
This vision measurement method is mainly composed of an image acquisition system, an image processing and analysis system. The Fig. 1 is pillow spring and image acquisition system；Fig. 2 is a flow chart of the implementation of the method scheme; Fig. 3 is a flow chart of the image processing system algorithm. As shown in Fig. 1(A), the picture shows the detected target pillow spring. In this method, the diameter of the end face of the pillow spring and the free height of the pillow spring are measured respectively. Fig. 1 (B) shows the image acquisition system, and its main components are the camera, the pillow spring detection platform, the PLC controller, and the three-coordinate motion system. Fig.  2 shows that the specific detection process is: realize the movement of the camera through the three-coordinate motion system; after obtaining the image of the detection target, the image processing algorithm is used to obtain the corresponding size information and display and output.In this method, 3 the camera used is a 5 million pixel CCD camera with model GMT200-H, and the lens model is SA1620M-10MP. In order to ensure the image quality, the backlighting scheme is used for light source compensation in this method. The measured target pillow spring is placed between the light source and the camera. The measured target body is a black shadow in the collected image, which can be displayed to the greatest extent. The edge profile of the pillow spring. In this method, the work surface on which the pillow spring is placed is made of transparent acrylic material.    3 is a flowchart of the image processing system algorithm of the method. In the process of image acquisition by the system, factors such as the camera's shooting angle, lens distortion, and pillow spring position will cause errors in the final measurement results. Therefore, in the image processing process, the image needs to be corrected. Then through a series of morphological processing, the image noise is reduced in order to accurately find the contour of the pillow spring. Finally, edge extraction, contour fitting and size calculation are performed on the image.

Image correction
In order to improve the measurement accuracy of the pillow spring size, reduce the camera angle and the distortion of the camera lens itself. This method uses Zhang Zhengyou calibration method to correct the image. First, use the camera to take 20 images of the chessboard at different angles. The chessboard is a grid of alternating black and white, and the number of corners of the chessboard is 11*11. Then, sub-pixel positioning method is used to detect and draw the corners in the chessboard. The detected corner points are added to the vector of coordinate points, and the calibration parameter, which is the distortion matrix, is calculated. The calibration model between the world coordinate system and the camera coordinate system can be expressed as: is pixel in the world coordinate system; ( ) is the pixel in the camera coordinate system; G is the distortion correction matrix.
The result of matrix G can be obtained by calibration:

Image brightness correction
Due to the complexity of the actual measurement environment, the light source compensation equipment cannot completely avoid the unevenness of illumination. In order to reduce the influence of uneven illumination on the subsequent image preprocessing results, this method uses a brightness equalization algorithm to correct the brightness of the image, so that the brightness of the image is more balanced.
The principle of the brightness equalization algorithm is as follows: Assuming the image of Through the adjustment of Lum  , makes the brightness between adjacent sub-regions smooth.

Morphological processing
In order to reduce the amount of data in the image processing process, improve the effect of edge fitting and extraction. This method performs binarization processing on the collected original image to  Fig. 4 shows the original image captured by the camera and the image after binarization. The binary mathematical model is: is the value of pixel ( )   6 shows the edge lines of Canny and Laplacian edge detection algorithms. In the figure, the Canny algorithm has a clearer edge than the Laplacian algorithm, and the edge of the Canny algorithm is composed of one pixel, while the Laplacian algorithm is composed of three pixels. The Canny detection algorithm indicates that the edge is more accurate and is as close as possible to the actual edge. This method uses the canny algorithm for edge detection. The Canny edge detection algorithm is mainly based on the first and second derivatives of the image, but the derivatives are usually very sensitive to noise, so filters must be used to improve the performance of noise-related edge detection. This method uses Gaussian filtering to eliminate noise, that is, a discretized Gaussian function is used to generate a set of normalized Gaussian kernels, and Step 1：The image is smoothed and filtered by the Gaussian function ( ) is the filtered and smoothed image, ( ) y x f , is the original image. Its mathematical model is expressed as: Where,  is the standard deviation of Gaussian function; * is the symbol of convolution operation.
The first-order differential operator of ( ) in the x, y direction is as follows: Where, x G and y G are the first-order differentials of the smooth image ( ) can be obtained.
Step 2：In order to exclude non-edge pixels, only candidate edges are retained. The interpolation method is used to suppress the non-maximum value of local pixels. Find the local maximum of a pixel, set the gray value corresponding to all non-maximum points as the background pixel, and the local optimum of the gradient value in the neighboring area of the pixel will be judged as the edge of the pixel. Relevant information of other non-maximum values is suppressed, and most non-edge points are proposed using this criterion.
Step 3： In order to determine the final edge pixel point, it is necessary to set the hysteresis threshold. The high threshold set in this method is 100 = , then the pixel will only be retained if it is connected to a pixel higher than a high threshold.

Feature extraction and size acquisition
In this method, the outline diameter 1 r of the reference object in the image is obtained by the smallest outer rectangle, Contour diameter of pillow spring image 1 R and the height of the pillow spring 1 H .Finally, the height H and contour diameter R of the pillow spring are obtained from the ratio  .

Extract contour
In order to accurately extract the contours of the reference object and the pillow spring, this method traverses the detected contours in sequence. The area size of the extracted contour area is checked to avoid the interference of image noise, and the final contour area is circumscribed. As shown in Fig.7, the left side of the figure is the reference object, and the right side is the detection target body pillow spring. The green rectangle is the circumscribed rectangle of the outline.  Fig. 7 Geometric model

System size calibration
The size of the pillow spring in the image is obtained by calculating the Euclidean distance between two pixels, and then the actual size of the pillow spring is obtained by the ratio  . The ratio is the ratio of the pixel width of the object to the true width of the object. The reference object in this method is uniquely identifiable in any case.
The calculation formula of the ratio is as follows: Where，  is ratio. That is, the ratio of the pixel size to the real size； 1 r is the pixel size of the calibration object; 0 r is the actual size of the calibration object, mm r 38 0 = 。

size parameters
After edge detection and feature extraction, the contour diameter 1 R of the pillow spring image and the height 1 H of the pillow spring can be obtained through the smallest circumscribed rectangle of the contour. From ⑿, the dimensions R and H of the pillow spring can be obtained, as shown in the following formula: Where, R 、 H is the size of the pillow spring； 1 R 、 1 H is the pixel size of the pillow spring.

Analysis of measurement results
In this test experiment, the hardware platform configuration used is:Intel i7-3632QM CPU. The software environment is configured as: Visual Studio 2017 and OpenCV 4.1.1。 In order to verify the reliability of this measurement method under different lighting conditions, the same pillow spring was measured at different times. In order to ensure the accuracy of the data and reduce the interference data, the positions of the camera and the pillow spring of the target detection body are fixed during the image acquisition process in this article.  Table 1. As shown in Table 1, the measurement error under different lighting conditions is also different under the influence of lighting conditions. The error range is within mm, which can meet the requirements of pillow spring measurement.
To test the stability of the measurement accuracy of this method. Under the same conditions, the visual measurement method and the vernier caliper were used to repeatedly measure the contour diameter and free height of the same sample. The measurement results are shown in Fig. 9.  Fig. 9 and Fig. 10, the abscissa axis represents the number of measurements, and the ordinate axis represents the measured value. It can be seen from the measurement results shown in the figure that the measurement results of the two methods are relatively close. Affected by various environmental factors, the results of manual measurement and visual image measurement have a certain degree of error. The visual image measurement method is more efficient than the manual measurement method using a vernier caliper, and meets the accuracy requirements.

Conclusions
⑴ In this paper, a method for measuring the size of pillow springs based on visual images is designed. In the image acquisition system, the light source is assisted by backlighting, so that the edge of the pillow spring is clear, and the effect of the original image is guaranteed to the greatest extent. In the process of image preprocessing, distortion correction is performed on the image by the method of checkerboard grid, and the morphological processing algorithm of brightness correction and Gaussian filtering is used to remove the interference noise in the image. The canny edge detection algorithm is used to obtain the contour edge, the minimum contour matrix and the reference object to realize the measurement of the free height and diameter of the pillow spring.
⑵ Compared with the traditional contact-type pillow spring size measurement method, the accuracy and repeatability of the measurement results obtained by this measurement method in the actual test are basically the same as those obtained by manual vernier calipers. In terms of efficiency and scalability, the visual image measurement method is better than the traditional measurement method. 10 ⑶ In practical engineering applications, due to the limitations of actual environmental factors and the conditions of the pillow spring, it is difficult to achieve high-precision measurement based on the machine vision-based size measurement method of the pillow spring. In-depth research is needed to improve the accuracy of edge detection.