1 Introduction

The advancement of technology and the realizations of Industry 4.0 in modern world applications have amplified the research possibilities in the field of machine vision and industrial inspections. Image-based inspection and automatic application analysis, such as robot guidance, process control, and automatic inspection, are the mainstream technologies of machine vision in today’s industries [29, 32]. These conventional technologies usually involve a stream of integrated systems, hardware products, methodologies, and expertise that use software algorithms across sensors, cameras, and hardware processing to automate mundane and complex inspections that guides the precise handling of tasks and equipment during the assembly of products. The distinctions of such applications vary from verification, positioning, flaw detection, identification, and measurement. In the bit to improve control quality, low production cost, and higher yields, a machine vision system can work pertinaciously accomplishing very low error rates during inspection processes [26]. The system configuration involves diverse components, ranging from the sensor cameras to image acquisitions for inspection, critical to the processing framework that provides and communicates the outcome [27]. With the rapid development of image processing and pattern recognition, machine vision technology has attracted more and more attentions and is widely used in industry area, for its simplicity, non-contact, and robustness [21]. It is a pre-eminent tool for quality control inspection of a variety of products such as industrial components and manufacturing tools.

Most industrial and haulage application use gears as common mechanism for conveying power and motion. This element is important and frequently used as fundamental component [1]. As current methodologies of gear measurement are expensive and time consuming, precision and accuracy become evidently crucial in the measurement and inspection of industrial products. There are very few methods available of measuring gear parameters accurately, and at the same time, minimizing error and production cost [11]. As a key to production and inspection, the utilization of machine vision applications to develop accurate and precise measurement system with the ability to perform appropriate inspection and measurement is fundamental to any manufacturing process [13].

The aim of this paper is to deploy an improved machine vision application to determine the precise measurement of gears, at subpixel level, with the potential to improve quality control, reduce downtime, and optimize the inspection process. The original contribution of this paper can be summarized as follows:

  • Implementation of the algorithm on an improved system configuration, with the use of a telecentric lens.

  • high-quality setup with low system calibration error obtained.

  • Increase amount of experimental proofs on the gear inspection process.

  • Significantly low tolerance to enhance a limited error-prone system for an improved quality control inspection.

  • Methodological study of the uncertainty associated with the measurement process.

The paper is arranged as follows. Section 2 describes related works done. In Section 3, we describe the overall layout of the proposed system and Section 4 describes the system calibration process. Section 5 describes the algorithmic structures and the calculations of the other parameters of the gear nomenclature. The inspection decision process is described in Section 6. Section 7 shows a deep analysis of the uncertainty of the inspection. Sections 8 and 9 include validation and conclusion respectively.

2 Related works

Kerr [22] observed that vision systems have been widely used in many applications. Computer vision systems have been developed for quality control and started to be used as an objective measurement and evaluation systems [7]. Robinson et al. [28] described the design of an involute spur gear inspection system in which measurements were made using a video camera and image analysis software. They investigated the possible measurement accuracy and the possible sources of error identified. They concluded that the measurement accuracy is comparable with that of current methods for tolerance inspection of spur gears. In addition, the low cost and ease of use made image analysis measurement systems an attractive alternative.

Sung et al. [33] utilize wavelet transform, with high accuracy, to identify the positions of deformities in a gear system. The research reviews significant studies of gear dynamics, gear deficiencies, and the background theories of wavelet transform. A gear failure test rig was designed and envisioned for the implementation of the technique of wavelet transform. The study reports the possible improvement of fault identification of a gear transmission system using this designed approach, especially when the angular speed of the faulty gear rotates in a manner close to those of the other gears. However, this research does not address measurement accuracy precisely.

Hui et al. [39] proposed a gain-scheduling fault detector and augmented system based on the uncertain linear-parameter varying model. The scheduling vector relates to the vehicle longitudinal velocity for an electric ground vehicle. Due to the difficulty to measure the longitudinal velocity precisely, the uncertain measurement on the longitudinal velocity is considered. To deal with the uncertainties, Lemma 2 and Lemma 4 [23] are adopted, in which the studied setup is a Takagi-Sugeno fuzzy system. Due to the nonlinearities of the model and the uncertainties in the scheduling vector, the fault detection work proved to be more challenging. Yunfeng et al. [18] proposed an adaptive robust triple-step control method for compensating cogging torque and model uncertainty. The model uncertainty was estimated by an extended state observer that consisted of an adaptive steady-state controller and robust feedback controller. The effectiveness and the satisfactory control performance of the controller were evaluated through comparative experiments. The related works on robust control attempt to improve the proposed method designs; nevertheless, a methodological study of the uncertainties associated with the measurement process is found lacking.

The use of machine vision systems for inspection aspires to improve the quality control process of manufacturing industries, especially as market demand constantly requires higher quality productions [5]. Several measurement estimations by either perimeter [30], diameter [6], or area [34] have been developed to enhance machine vision inspection systems. However, a challenge often faced when developing a machine vision system is the attempt to resolve, either by reduction or by elimination, measurement uncertainty and error.

Gadelmawla [12] utilized computer vision technology to develop a non-contact measurement system capable of measuring most of spur gear parameters rapidly with a reasonable accuracy. This can facilitate and speed up the measurement and inspection processes of spur gears. The investigation demonstrated the maximum differences between the calculated parameters and the design values as ± 0.101 mm for a spur gear with 156 mm outside diameter. The accuracy of the system is affected by the size of the gear to be measured. Hence, the difference between the calculated parameters and the design values can be decreased by measuring small gears.

This paper expands the conceptual model of Gadelmawla [12] to determine the accuracy of the system affected by the size of the gear measured. It also tests if the number of gears measured within the system limit reveals a varied effect on the accuracy level, and hence determine the sensitivity of the inspection process and the authenticity of the Vision2D application. In addition, a methodological study of the uncertainty associated with the measurement process is established.

3 The proposed system

The Vision2D application has been developed to perform inspections and measurements to determine the precise and accurate measurement of the gear parameters to enhance quality inspection control. Figure 1a shows the proposed system configuration. The gear was placed in a mechanical system configuration by an M-10iA Fanuc robot (1). The robot is a six-axis, high-performance industrial robot. It weighs 130 kg and provides 10-kg payload with the highest wrist moments and inertia in its class. The M-10iA can be floor or wall mounted at any angle. For the experiment of this paper, the robot was floor mounted. A dynamic inspection belt was used to convey the gear piece from a start state, during the inspection (Fig. 1b). The belt configuration is setup with a sensor. The sensor triggers when the gear is detected. The robot receives the trigger signals from the sensor, automatically picks the gear from the dynamic belt, and places it on the mechanical system (3). When the gear has been placed on the mechanical system, a Manta G-504 camera acquires the image of the gear. The Manta G-504 is a machine vision camera that combines the high-quality Type 2/3\({}^{\prime \prime }\) (11.016 mm diagonal) Sony ICX655 CCD sensor with a resolution of 2452 (H) × 2056 (V). This camera runs at 9.2 frames per second at full resolution. With a smaller region of interest, higher frame rates are possible. The Manta is an adaptable GigE Vision camera with an extensive range of characteristics. It is attached to a telecentric lens (4) that can take advantage of high-resolution detectors such as 5 MP - 2/3\({}^{\prime \prime }\), acquiring images with exceptional fidelity and precision maximizing the performance of the proposed system. Telecentric lenses eliminate the parallax error characteristic of standard lenses by having a constant, non-angular field of view. A high-performance telecentric illuminator (2) specifically designed to back illuminate objects imaged by telecentric lenses was used. The telecentric illuminators offer higher edge contrast when compared with diffused back light illuminators and therefore higher measurement accuracy. This type of illumination is especially recommended for high-accuracy measurement of round or cylindrical parts where diffusive back lighting would offer poor performances because of the diffuse reflections coming from the edges of objects under inspection. The Vision2D application was developed in-house in C# programming and Visual Studio 2015, incorporating the Halcon 13 integration libraries. Halcon 13 is a comprehensive standard software for machine vision with an integrated development environment. Its flexible architecture facilitates rapid development of any kind of machine vision application. C# programming was used to develop the user interface for a better touch and feel. To perform the measurement process, several image processing and machine vision algorithms are applied (explained in Section 5) to the acquired images.

Fig. 1
figure 1

The proposed system configuration. a Robot and telecentric lens configuration. b The inspection belt. c The vision2D application interface

4 System calibration

Calibration in machine vision associates the pixel coordinates of the camera sensor to a world coordinate system. This associative process determines the relationship that distinguishes a distance measured in pixel in the camera to the real distance of the imaged object. The system memory records an array of the amount of charge generated at each discrete sensor pixel position. Conventional electronic imaging in machine vision treats the top left corner of the image as origin and assembles all sources to the pixel position in a coordinate system in which position x-direction runs across the rows and position y-direction runs down the columns of the sensor [35].

4.1 Sensor coordinate system

The camera sensor frame of reference initiates characteristics located in the image, such as distances, lines, and edges, and scale to the prevailing scale of the frame. That is, when there is no calibration, all positions are in pixel coordinates as regards to the top left of the image, and the subsequent recorded distances are in pixels as well. Calibration procedures enables for the specification of further useful system of coordinates and scaling. A calibration object of notable accurate metric properties is necessary for the best completion of a calibration process [35]. The caliber of the calibration object and images acquired overly determines the success rate of the calibration. In order to understand the importance of the calibrations in a measurement system, it is necessary to know the internal geometry of the camera and its behavior. The calibration process allows for the specification of important parameters of the new calibrated coordinate system. The camera parameters are divided into the extrinsic and intrinsic camera parameters.

4.1.1 Extrinsic camera parameters

The extrinsic parameters define the position and orientation of the world coordinate system relative to the camera coordinate system in space, hence expounding the 3D pose. Thus, extrinsic camera parameters are rotation and translation of the Euclidean coordinate transformation. Figure 2 shows the graphical Euclidean tranformation of the coordinates. The mathematical definition of the Euclidean transformation of the 3D points to 2D in matrix form is given as follows:

$$ \left[\begin{array}{lll} x \\ y \\ 1 \end{array}\right] = \left[\begin{array}{lll} \vec{R} & \overrightarrow{t}\\ \overrightarrow{O}_{3}^{T} & 1 \end{array}\right] \left[\begin{array}{lll} X\\ Y\\ Z\\ 1 \end{array}\right] $$
(1)
Fig. 2
figure 2

Euclidean transformation from world coordinates to camera coordinates

Where \(\vec {R}\) is the rotation matrix and t⃗ is the translation matrix. The coordinates (X, Y, Z, 1) represent the point of the object in space while the coordinates (x, y, 1) represent the point of the image plane.

4.1.2 Intrinsic camera parameters

The intrinsic camera parameters expound the distinctive features of the camera in use. These parameters notably define the dimension of the sensor and the projection properties of the combination of lens and camera in use. These parameters represent digital and geometric optical characteristics that define the operation of camera. The intrinsic parameters which serve to understand the concept of imaging are:

  • Perspective projection

  • Focal length

  • Principal point

  • Skew

  • Distortion coefficients

Perspective projection consists of the projection of a 3D point in space with coordinates (X, Y, Z) known through the intersection of the center of the camera and the 3D cutting with a flat point image [16]. In the first place, it is assumed that the world coordinates of the points of the space and the coordinates of the camera are aligned. In this way, the camera plane is parallel to the image plane. Figure 3 shows a projection model of a pinhole camera, a simple camera without a lens but with a small aperture. The plane Z cuts with the image plane and generates a point called the main point (P).

Fig. 3
figure 3

Projection model of the pinhole camera

The expressions of the equation are obtained by similarity of triangles, as follows:

$$ x = f\frac{X}{Z} $$
(2)
$$ y = f\frac{Y}{Z} $$

The screening process can be expressed mathematically using homogeneous coordinates as a linear system in the following way:

$$ \left[\begin{array}{lll} x \\ y \\ 1 \end{array}\right] = \left[\begin{array}{lll} fX \\ fY \\ Z \end{array}\right] = \left[\begin{array}{llll} f & 0 & 0 & 0\\ 0 & f & 0 & 0 \\ 0 & 0 & 1 & 0 \end{array}\right] \left[\begin{array}{lll} X\\ Y\\ Z\\ 1 \end{array}\right] $$
(3)

abbreviated as:

$$ x = PX = KP_{N}X $$
(4)

P is the projection matrix, product of the matrix K, matrix of intrinsic parameters, and PN matrix of standardized homogeneous projection. The vector x defines the projected 2D point in the image plane while the vector X represents the 3D point in space.

These equations mathematically represent the ideal model. However, they do not represent the real model. The real model has several imposed inaccuracies that make some of these expressions vary. On the one hand, the distortions generated in the images mean that, in the projection of the points of the main plane, the 3D point, the 2D projected point, and the center of the camera are not aligned; therefore, the mathematical expressions that have been described so far will be altered by this effect. On the other hand, another effect that modifies the ideal behavior previously presented is the lack of perpendicularity of the sensor with respect to the lens. As a consequence, the pixels of the image stop being squares and acquire an inclination called skew. Figure 4 and expression (5) represents this effect.

$$ s = \tan \alpha \frac{f}{s_{y}} $$
(5)
Fig. 4
figure 4

Skewing of pixels

This effect generates two different focal lengths depending on sx and sy pixel dimensions. These focal lengths are calculated according to the following equations:

$$ f_{x} = \frac{f}{s_{x}} $$
(6)
$$ f_{y} = \frac{f}{s_{y}} $$

Thus, taking account of this effect, Eq. (3) results in:

$$ \left[\begin{array}{lll} x \\ y \\ 1 \end{array}\right] = \left[\begin{array}{lll} f_{x}X \\ f_{y}Y \\ Z \end{array}\right] = \left[\begin{array}{lll} f_{x} & s & 0\\ 0 & f_{y} & 0 \\ 0 & 0 & 1 \end{array}\right] \left[\begin{array}{llll} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{array}\right] \left[\begin{array}{lll} X\\ Y\\ Z\\ 1 \end{array}\right] $$
(7)

Lastly, despite the fact that the origin of the coordinates of the image plane coincides with the principal point, it is not always the case. In general, the coordinate system of the image is usually found at the upper left corner; therefore, the point that cuts the main plane is not in the origin but moved (px, py). Therefore, taking into account the mentioned effects, the equation that models the projection of a real camera is the following:

$$ \left[\begin{array}{lll} x \\ y \\ 1 \end{array}\right] = \left[\begin{array}{lll} f_{x} & s & p_{x}\\ 0 & f_{y} & p_{y} \\ 0 & 0 & 1 \end{array}\right] \left[\begin{array}{llll} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{array}\right] \left[\begin{array}{lll} X\\ Y\\ Z\\ 1 \end{array}\right] $$
(8)

Normally, apart from the regular challenges of image processing, a standard lens presents diverse minimizing considerations that affect measurement application accuracy such as poor image resolution, image distortion, perspective error, object edge position uncertainty, and changes in magnification. The use of a telecentric lens removes or diminishes nearly all of these challenges. Therefore, the development of high-accuracy applications hinges on its usage. In the case of an object displacement, the image size stays unaltered, due to the particular path of the rays within the optical system, in as much as the object remains within a given range, usually called the depth of field (DOF), as illustrated by Fig. 5. Hence, it is important that the front lens diameter should be measurably as large as the object field diagonal.

Fig. 5
figure 5

a Rays entering a standard lens generates images of distinct sizes on the sensor when changing the object to lens distance. b Rays entering a telecentric lens generate images of unaltered size on the sensor with object to lens distance rearrangement

Figure 6 illustrates the projection model of a camera with a telecentric lens. (Xw, Yw, Zw) is the 3D coordinate of the object point P in the 3D world coordinate system. (Xc, Yc, Zc) is the 3D coordinate of the object point P in the 3D camera coordinate system. (xu, yu) is the image coordinate of P(Xc, Yc, Zc) if a perfect orthographic projection model is used. (xd, yd) is the actual image coordinate which differs from (xu, yu) due to lens distortion. (u, v) is the image coordinate of the computer in pixels. Telecentric lenses perform scaled orthographic projection [16]; thus, the projection of an arbitrary point P to the ideal (undistorted) image plane in metrical units is expressed as:

$$ \left[\begin{array}{lll} x_{u} \\ y_{u} \\ 1 \end{array}\right] = \left[\begin{array}{llll} m & 0 & 0 & 0\\ 0 & m & 0 & 0 \\ 0 & 0 & 0 & 1 \end{array}\right] \left[\begin{array}{lll} X_{c}\\ Y_{c}\\ Z_{c}\\ 1 \end{array}\right] $$
(9)
Fig. 6
figure 6

Perspective projection model of a camera with a telecentric lens

where m is the effective magnification of telecentric lens, which needs to be calibrated. And the relationship between the world and camera coordinate systems (extrinsic parameters) is given by the same Eq. (1).

Without any loss of generality, the image coordinate system oxy coincident is set with the computer image coordinate system. Thus, the transformation from image coordinate (x, y) to computer image coordinate (u, v) in pixels is described by:

$$ \left[\begin{array}{lll} u \\ v \\ 1 \end{array}\right] = \left[\begin{array}{lll} 1/d_{u} & 0 & 0\\ 0 & 1/d_{v} & 0\\ 0 & 0 & 1 \end{array}\right] \left[\begin{array}{lll} x\\ y\\ 1 \end{array}\right] $$
(10)

where du and dv are the sizes of a pixel in the x and y directions respectively.

Combining Eqs. (1), (9), and (10), the orthographic projection of telecentric lenses is formed and expressed by the equation:

$$ \left[\begin{array}{lll} x_{u} \\ y_{u} \\ 1 \end{array}\right] = \left[\begin{array}{lll} m/d_{u} & 0 & 0\\ 0 & m/d_{v} & 0\\ 0 & 0 & 1 \end{array}\right] \left[\begin{array}{llll} r_{11} & r_{12} & r_{13} & t_{x}\\ r_{21} & r_{22} & r_{23} & t_{y} \\ r_{31} & r_{32} & r_{33} & t_{z} \\ 0 & 0 & 0 & 1 \end{array}\right] \left[\begin{array}{lll} X_{w}\\ Y_{w}\\ Z_{w}\\ 1 \end{array}\right] $$
(11)

4.2 Calibration process

As a result of different calibration processes [17, 40], the intrinsic parameters of the camera are determined to define the concept of imaging. There are different calibration techniques, but all of them have a common objective, they try to minimize projection errors [36]. The perfect calibration of a camera would guarantee that the projected points coincide with the points detected. In reality, however, there is a certain projection error calculated as the Euclidean distance between the two points. Therefore, the objective of the calibration process is to minimize these errors to ensure the highest possible accuracy.

A distinctive feature of a calibration process is based on matching specific measured positions on the camera sensor with the specific real-world position on a calibration target. A calibration target with accurately known metrics properties is chosen to fill approximately 80% of the field of view (FOV). Before calling the actual calibration, a series of images of the calibration object in different orientations are obtained and care is taken to make sure that the whole field of view or measurement volume is covered.

Figure 7 show a point in space with known coordinates (X, Y, Z). For that 3D point, a point (h, v) is detected in the image plane. In addition, 3D points are projected through several initial intrinsic parameters. The points detected (h, v) and the projected points do not occupy the same position in the plane. In such a way that it is necessary to apply the correction of distortions in order to obtain the point (p, q).

Fig. 7
figure 7

Perspective projection model

After applying the correction to the detected points, it does not occupy yet the same position in the image. Therefore, the difference between the horizontal and vertical coordinates of the corrected points (p, q) and the 2D projected points define the residual error terms (rp, rq) according to Eq. (12).

$$ r_{p} = (p_{i} - 2D_{Xi}) $$
(12)
$$ r_{q} = (q_{i} - 2D_{Yi}) $$

By grouping the terms of residual errors in a vector (Eq. (13)), the vector that is intended to be minimized by calibration is achieved.

$$ \left[\begin{array}{lll} r \end{array}\right] = \left[\begin{array}{lll} r_{11} \\ r_{21} \\ \cdot \\ r_{1N} \\ r_{2N} \end{array}\right] = \left[\begin{array}{lll} (p_{1} - 2D_{X1})\\ (q_{2} - 2D_{Y2}) \\ \cdot \\ (p_{N} - 2D_{XN}) \\ (q_{N} - 2D_{YN}) \end{array}\right] $$
(13)

The quality of the acquired calibration images and the calibration object directly influences the realization of a well-calibrated system. In the wake of an accomplished calibration, the optimized intrinsic and extrinsic parameters and the root mean square of the back projection of the optimization are generated. The root mean square error indicates, in general, the success of the optimization process. In this paper, a calibration target of 80 mm is used to generate the coordinates of the calibration marks in the acquired image and to calculate the estimate for the camera parameters. A root mean square error of 0.06 pixels was obtained. Figure 8 shows the Halcon calibration process interface.

Fig. 8
figure 8

Halcon calibration process interface with a used calibration plate image on the left

5 The algorithms

The Vision2D application interface performs the measurement of all gear parameters, as shown in Fig. 9, by calculating only three parameters: the outer diameter, the inner diameter (also called root diameter), and the number of tooth. These three parameters are the most necessary values needed to calculate the rest of the gear parameters. Many of the gear parameters are well known to be correlated to each other by known equations [14]. For example, the pitch diameter is correlated to the number of teeth and the module, while the module is correlated to the pitch diameter and the number of teeth. In this situation, computer vision algorithms were developed to calculate the outer diameter, the inner diameter, and the number of teeth of the gear to be measured; then, the rest of the gear parameters are calculated using their equations based on these three parameters.

Fig. 9
figure 9

Nomenclature of gear

The image processing starts with the camera acquiring the image, and several algorithmic steps are used for thresholding, segmentation, detection, and measurement of the gear. Figure 10 shows a block diagram of the algorithms used. The next sections describe the algorithms in detail.

Fig. 10
figure 10

Flowchart of the Vision2D application

5.1 Image segmentation

Bali et al. [2] describe segmentation as a method of partitioning an image or picture into different regions which has same attributes like texture, intensity, and gray level with the motive to yield object of interest from the background. Image segmentation methods have been extensively used in the identification of images and classification of image in numerous fields [38]. Thresholding, because of its clarity and direct nature, and clustering, because of its ability to categorize images efficiently, are the very well-known method for image segmentation between image segmentation techniques [8]. K. Singh et al. further discussed the different types of image segmentation thresholding techniques for the different application areas: pixel-based, edge-based, and region-based segmentation techniques [31]. Pixel-based segmentation is conceptually the simplest approach used for segmentation. In this approach, information from the input image fuses in a pixel-by-pixel basis either in the transform or in spatial domain. Edge-based segmentation is based on the fact that the position of an edge is given by an extreme of the first-order derivative or a zero crossing in the second-order derivative. Region-based method focus attention on an important aspect of the segmentation process missed with pixel-based techniques: it classifies a pixel as an object pixel judging solely on its gray value independently of the context. This paper implements thresholding at subpixel level using the edge-based method.

5.2 Edge detection subpixel

In industrial applications, like measurement of gears with high precision, it is sometimes necessary to detect edges with subpixel precision. The need of subpixel accuracy in image processing and analysis was firstly pointed out in the late 1970s [25]. Since then, the issue of edge detection at the subpixel level has gained attention of approaches of many scientists and researchers [10]. Detection of edges with subpixel accuracy improves the measurement accuracy and reduces hardware cost.

Hagara et al. [15] describe that most edge detectors at subpixel level fall in three groups: fitting, moment-based, and interpolation-based methods. Fitting method uses continuous functions, such as hyperbolic tangent [24], to fit samples of image function. Moment-based methods apply moment to determine unknown edge model parameters. For example, gray level moments tangent [9], spatial moments [3], Fourier-Mellin moments [4], or Zernike moments [37]. Interpolation-based methods achieve the subpixel accuracy by interpolating the image data to obtain a finer grid of pixels.Thresholding at the subpixel extracts segments from the image with subpixel accuracy. A segmentation process develops with the analysis of the input image as a surface, where the gray values are bilinearly interpolated amid the centers of the individual pixels. Each pixel is thus extracted forming a segmented line, consistent with the image surface, and then associated into intact topological contours. The segmentation contours therefore are accurately divided at intersecting points. Only image borders of areas containing extended gray values are generated. Figure 11 a, b, c, and d show the edge detection at different levels. Figure 11 a shows the edge pixel detection of the gear tooth. Figure 11 b shows the edge subpixel detection of the gear tooth. Figure 11 c shows the principal outer edge detected applying the threshold subpixel algorithm. Figure 11 d shows the diametric intersections generated to calculate the distance between two points of the outer tooth edge across the area center. It also shows the intersecting distance between two points in the inner circle across the area center.

Fig. 11
figure 11

The edge detection details. a The edge pixel detection of the gear tooth. b The edge subpixel detection of the gear tooth. c The outer edge detection of gear. d The intersection points to determine the diameter of tooth

5.3 The outer diameter algorithm

To calculate the external diameter of the gear from the extracted edge of the outer contour, the outer diameter algorithm was developed. Figure 12 shows the flow process.

  • Threshold the acquired image: The threshold subpixel algorithm extracts segments of the input image with subpixel accuracy.

  • Select edge contour: The select contour algorithm selects contours from the input image according to a contour length specified. All contours whose length is far away from the parameter specified are not returned.

  • Fit circle contour: The fit circle contour algorithm approximates the contours by a circle. The operator returns the area center, and the radius.

  • For five teeth, generate a radius line from two points: the tooth edge and the area center of the circle contour.

  • Extending the radius lines, the intersection points at the edge contour are generated for each teeth, and the corresponding distance diameter computed.

    $$ \text{Distance} = {\sqrt{((R1 - R2)^{2} + (C1 - C2)^{2})}} $$

    where R1 and R1 are the row coordinates of the first and second point respectively, and C1 and C2 are the column coordinates of the first and second points respectively.

  • The average of all the computed distances is reserved as the outer diameter.

Fig. 12
figure 12

Flowchart of outer diameter algorithm

5.4 The inner diameter algorithm

The root diameter algorithm calculates the inner diameter from the extracted edge pixels. Figure 13 illustrates the flow process.

  • Generate region from contour: The generate region contour algorithm creates a region from a subpixel contour. The contour is sampled according to the Bresenham algorithm [20]. Open contours are closed before converting them to regions.

  • The shape transform is used to transform the shape of the input regions to derive the largest circle fitting into the region.

  • Generate contour of region: The generate contour region algorithm generates contours from the regions.

  • Fit circle contour approximates the contours by circles. The operator returns the contour area center and radius.

  • Arbitrary lines are generated from the area center to intersect with the circle contours.

  • The average of all intersection points is then used to calculate the inner diameter across the area center of the circle contour.

Fig. 13
figure 13

Flowchart of inner diameter algorithm

5.5 The tooth number algorithm

The tooth number algorithm counts the number of teeth in the gear image. Figure 14 shows the flowchart. The algorithm works as follows:

  • Threshold the acquired image: The threshold subpixel algorithm extracts segments of the input image with subpixel accuracy.

  • Select edge contour: The select contours algorithm selects contours from the input image according to a contour length specified. All contours whose length is far away from the parameter specified are not returned.

  • Fit circle contour: The fit circle contour algorithm approximates the contours by a circle. The operator returns the area center, and the radius.

  • Intersect contours: Generates intersecting points of the tooth edge contour and circle contour which, if any, are returned.

  • Select object: This algorithm selects all the intersecting points generated.

  • Count object: This algorithm counts the intersecting points and determines as output parameter the average of the counted objects. The average is considered as the output because the number of teeth is twice the number of the intersection points.

Fig. 14
figure 14

Flowchart of tooth number algorithm

5.6 The other parameters

The above three algorithms calculate the outer diameter, the inner diameter, and the number of teeth of the gear to be measured. Using these parameters, all other gear parameters can be calculated. Table 1 describes the different gear parameters and the subsequent formulas used to generate the values.

Table 1 The gear nomenclature and formulas

6 Inspection process

To accomplish the desired quality inspection process, the measurement of the gear acquired from the Vision2D application is compared with the measurement of the nominal gear derived from the CMM analysis, within a specified tolerance. The interface of the Vision2D application (Fig. 15) deals with this process. The inspection process performed uses the following four steps:

  • The standard gear parameters: The standard gear parameters are set into the Vision2D application for automatic reference. The reference values were obtained from a CMM analysis of a nominal gear.

  • The tolerance: The tolerance is set in the Vision2D application. The parameters to be inspected are verified and their allowable tolerances assigned. Each parameter can be assigned unique tolerance values. Alternatively, the same tolerance values can be applied to all parameters.

  • Measuring the gear to be inspected: The gear to be inspected is acquired and measured by the Vision2D system; then, the calculated parameters are compared with the nominal gear parameters according to the tolerances given.

  • Taking an inspection decision: The inspection decision is displayed automatically in the Inspection section. The decision is accepted if all inspected parameters for the gear satisfy the corresponding parameter conditions from the nominal reference, within the specified tolerances. Otherwise, the decision is rejected.

Fig. 15
figure 15

The main interface of the Vision2D application

7 Measurement error and uncertainty analysis

The existence of some degree of uncertainty in any given measurement system is caused by different sources of error. Error is the discrepancy between the optimal value and the measured value. The quality of the experiment of a measurement system is certain by the minimization or eradication of as many sources of error. Measurement errors are grouped as either random or systematic. Random error usually emerges from unpredictable alterations of dominating quantities. It is almost impossible to requite for the random error of measurement; however, an increase in the number of experimentation can oftentimes minimize it. A system error emerges from an observable effect of a dominating quantity on a measurement. It is quantifiable. A level of rectification can be applied to requite for the effect. Random and systematic errors are analogous to precision and accuracy. Precision denotes the quality of measurement, with no attestation that the measurement is right, while accuracy ascertains that there is an optimal value, normally referenced, to know how distant the feedback is from the optimal value. According to GUM [19], uncertainty components are grouped into two categories based on their method of evaluation “A” and “B.” Both types are different forms to evaluate the uncertainty and are based on probability distributions. Type A standard uncertainty is calculated from a series of repeated observations and is the square root of the statistically estimated variance (i.e., the estimated standard deviation). This technique principally encompasses random errors. Type B standard uncertainty is also the square root of an estimated variance, but rather than being evaluated by repeated measurement, it is obtained from an assumed probability density function based on the degree of belief that an event will occur. This technique encompasses systematic errors and the other uncertainty factors considered important.

The individual uncertainty components ui (sometimes of type A and sometimes of type B) should be combined using the law of propagation of uncertainties, commonly called the “root-sum-of-squares” or “RSS” method to obtain the combined standard uncertainty, denoted by uc.

$$ u_{c} = \sqrt{\sum {u_{i}^{2}}} $$
(14)

However, when this is done, the combined standard uncertainty should be equivalent to the standard deviation of the result, making this uncertainty value correspond with a 68% confidence interval (with a normal distribution). If a wider confidence interval is desired, the uncertainty can be multiplied by a coverage factor (usually k = 2 or 3) to provide an uncertainty range that is believed to include the true value with a confidence of 95% (for k = 2) or 99.7% (for k = 3). This is called expanded uncertainty and is denoted by Uc.

$$ U_{c} = k\sqrt{\sum {u_{i}^{2}}} $$
(15)

Another possibility is, instead of assuming a normal distribution in all the uncertainties, calculating the coverage factor independently for each uncertainty depending on its specific distribution.

$$ U_{c} = \sqrt{\sum (k_{i}u_{i})^{2}} $$
(16)

In that case, Table 2 can be used to obtain the parameter k looking for a confidence of 95% that is the usual one. As our uncertainties only fall in rectangular or normal distributions, we will take k = 1.65 and k = 1.96 respectively.

Table 2 Coverture factor for different probability distributions

In this work, the most significant uncertainties (ui) that have been considered are:

  • Resolution uncertainty (type B)

  • Pattern (plate) uncertainty (type B)

  • Calibration uncertainty (type A)

  • Measurement uncertainty (type A)

7.1 Resolution uncertainty

One of the sources of uncertainty of an instrument is the resolution of the device (if it is a digital instrument), or the uncertainty due to the resolution of reading (if it is an analog instrument) that depends on the operator or the way used in the reading.

If the resolution of the indicating device is δx, the input signal value that produces an indication given X can be placed with equal probability at any point within the interval from (Xδx/2) to (X + δx/2). The input signal can then be described by means of a rectangular distribution with range δx and standard deviation (typical uncertainty) of:

$$ u_{r} = \frac{\delta x}{2\sqrt{3}} $$
(17)

Taking into account that the theoretical subpixel object space resolution is given by:

$$ \delta x = \frac{\text{FOV}}{256\times\#\text{pixels}} $$
(18)

where FOV is the field of view (70 mm), #pixels is the number of pixels, and each pixel has 8 bits of depth.

7.2 Pattern uncertainty

The uncertainty of the pattern should be given by the calibration laboratory, by a formula or simply by its value. In our case, the plate calibration certificate points out that the maximum uncertainty of the plate is 0.15 μm. That means an expanded uncertainty with a 100% level of confidence \(U^{\prime }_{p}\). The typical uncertainty is obtained by dividing the expanded uncertainty by the coverage factor. In this case \(k^{\prime }=3\) (normal distribution).

$$ u_{p} = \frac{U_{p}^{\prime}}{k^{\prime}} $$
(19)

Finally, to obtain the expanded uncertainty with a 95% level of confidence, a k = 1.96 should be used.

$$ U_{p} = ku_{p} $$
(20)

7.3 Calibration uncertainty

In most cases, the best available estimate of the expected value of a quantity that varies randomly (uncertainty type A), and for which n independent observations qk have been obtained under the same conditions of measurement, is the arithmetic mean or average \(\bar {q}\) of the n observations. The estimate of variance and its positive square root σ (standard deviation) characterize the variability of the observed values.

$$ \sigma = \sqrt{\frac{\sum\limits_{k=1}^{n}(q_{k} - \mu)^{2}}{n-1}} $$
(21)

According to statistical theory, the best estimate for type A standard uncertainty is given by standard deviation of the mean:

$$ u_{c} = \frac{\sigma_{c}}{\sqrt{n}} = \sqrt{\frac{\sum\limits_{k=1}^{n}(q_{k} - \mu_{c})^{2}}{n(n-1)}} $$
(22)

Knowing the nominal distance between two horizontal points in the plate (2.58065 mm), a set of 18 distance measurements close to 62 mm (roughly the size of the gear) were performed computing its μc = 65.6610 mm and σc = 0.0017 mm. A calibration correction can also be computed as follows:

$$ {\Delta} q_{c} = q_{0}-\mu_{c} $$
(23)

This calibration correction can be applied in two ways. On the one hand, correcting the value of the measurements, each time a measurement is made, with the deviation value obtained in the calibration correction Δqc. On the other hand (the chosen one in this work), including as a cause of calibration uncertainty the term of the systematic correction, assuming it distributed according to a normal function \(\frac {\Delta q_{c}}{\sqrt {9}}\). This is more comfortable as it has an expression that already introduces this systematic variation, although increases unnecessarily the value of the global uncertainty.

7.4 Measurement uncertainty

It is accepted that the variance obtained in the process of calibration be the same as that obtained in the process of usual measurement; so, the uncertainty associated with the measurement process will be the same as uc with n = 1, i.e., um = σc.

Before performing measurements, it is important to check the system error measuring the ground-truth nominal sample gear. Figure 16 shows the measurement data of different camera exposures of the ground-truth sample gear, in order to check the minimum system error. The minimum error obtained is 0.002 mm at a exposure time of 7500 μs, very coherent to um (see Table 4).

Fig. 16
figure 16

Graph to check the minimum system error

A summary of the different uncertainties involved in the combined standard uncertainty is shown in Table 3.

Table 3 Summary of involved uncertainties

8 Validation and analysis

For the proper verification of the gear system, the developed Vision2D application inspected twelve gear pieces. The inspection process aimed at ascertaining if each of the gear had any defective component. This is to enhance the quality control inspection in the inspection process. The Vision2D application applies the corresponding algorithms to the image processed and determines if the gear is non-defective or defective. If the image processed meets all the required conditions, the Vision2D application outputs “accepted,” and sends a positive signal to the robot sensor. The robot picks the gear piece from the configuration setup and delivers it to the appropriate section. If the image processed fails the required condition set, the Vision2D application outputs “rejected,” and sends a negative signal to the robot sensor. The nominal value acquired from the CMM with the ground-truth sample gear is used to verify the values generated by the Vision2D application. The error margin sets as tolerance of the system is ± 0.020 mm for a gear nominal diameter of 62.014 mm.

In order to compute the uncertainty of the process, before the gears measurement Table 3 is filled with numerical values (shown in Table 4).

Table 4 Summary of involved uncertainties with numerical values

This allows to conclude that if a measurement m is made close to 62 mm, and for instance 62.012 is obtained, the real value will be:

$$ M = (62.012 \pm 0.004~\text{mm}) $$
(24)

where the number following the symbol ± is the numerical value of an expanded uncertainty Uc, determined from (a combined standard uncertainty) uc and the related coverture factors based on both rectangular and normal distributions, and defines an interval estimated to have a level of confidence of 95%.

Once the measurement is made, the decision must be made to consider the piece valid or not, according to the value of the nominal size (m0), the specified nominal tolerance interval (t0) and the computed expanded uncertainty (Uc). The admissible zone is shown in Fig. 17 from the next equations:

$$ \begin{array}{lll} t_{as} = m_{0}+t_{0}-U_{c} =62.014+0.020-0.004 = 62.030 \end{array} $$
(25)
$$ t_{ai} = m_{0}-t_{0}+U_{c}=62.014-0.020+0.004 = 61.998 $$
Fig. 17
figure 17

Computation of the admissible zone

Table 5 shows the inspection result details of an accepted gear. The Vision2D application inspects and measures each tooth of the gear. It performs the evaluation, and the measured values and difference between the ground-truth value are generated. After the verification process, the Vision2D application accepts the gear because of the condition for verification is satisfied (i.e., if the tolerance limit is not exceeded).

Table 5 Inspection details of accepted gear 1

Table 6 shows the verification details of a rejected gear. In this case, the Vision2D application rejects the gear because of the tolerance limit (16 μm), considering the nominal tolerance and the vision system uncertainty, was exceeded.

Table 6 Inspection details of rejected gear 12

The inspection result details of all twelve gears are shown in Table 7. The summary verification chart for the twelve gear pieces inspected is shown in Fig. 18. The figure illustrates visibly the tolerance levels set for the gear. The data points below the set tolerance illustrate acceptance, while the data points outside of the set tolerance illustrate rejection.

Table 7 The inspectionresults
Fig. 18
figure 18

The verification chart

9 Conclusion

This paper further exposes the development of an improved Vision2D for quality control inspection. The experiments carried out with different gears reveal the functionality of the developed Vision2D application taking into account not only the nominal tolerance but also the computed uncertainty of the process. Several emphasized considerations were implemented to better enhance the results generated by the application, as follows:

  • The use of a telecentric lens.

  • An improved camera configuration and setup.

  • A high-quality system with a very low calibration error result.

  • A greater amount of proofs done on an increased number of gear inspections.

  • A significantly low tolerance to enhance a limited error-prone system for better quality control inspection.

  • A methodological study of the uncertainty associated with the process

The successful implementation of these emphasized considerations and the achievements of the significant uncertainties that have been considered are the contributions that distinguish this paper.

10 Future work

Many challenges often befall the calibration process due to various factors such as camera and sensor configuration setup, lighting effects, room temperature, camera resolution, and the quality of calibration plate. All of these variables can influence measurement error, accuracy, and precision of the machine vision system. The Vision2D application developed in this paper obtains a minimum calibration error of 0.06 pixel. Nevertheless, future research can be carried to obtain a calibration error of a lower degree, keeping in mind the aforementioned variables that could affect or impede the realization of the result. In addition, the global uncertainty associated with the process of measurement to know the tolerance limit for acceptance could be further improved upon.