Keywords

1 Introduction

Screw thread measurement is motivated by the requirement of the manufacturing practice. According to measurement results is decided whether the inset part is the correct type or not. Main evaluated thread parameters are diameter, pitch and handedness. In our case the most difficult is to determine handedness. Two examples of tested parts are shown on the Fig. 1. Both threads are metric with diameter 39 mm, but the left-handed thread is on the left side and the right-handed thread is on the right side.

Fig. 1.
figure 1

Two examples of the metric screw thread M39x1.5. Left-handed thread is on the left side and right-handed thread is on the right side.

The customer’s requirement was that the screw thread has to be correctly recognized with at least 99.7% reliability. Real threads have different surface quality and color, also the light conditions are variable. Due to the used method has to be sufficiently robust.

2 Measurement

2.1 Diameter Measurement

The standard image processing methods are used for the diameter measurement. The hole’s ellipse is extracted from image and then the least squares method is used to find the best fit ellipse. The semi-major axis of the found ellipse corresponds with screw thread diameter.

2.2 Handedness Measurement

It is difficult to decide about handedness from the original image (see Fig. 1). Due to it is better to map the thread image back to cylinder and unfold it to the plane. This transformation will be described more precisely bellow.

The first step is to determine transformation between thread’s cylinder coordinate system (denoted as \(T\)) and camera coordinate system (denoted as \(G\)).

$$ {\Phi }_{T \to G} :\left\{ r \right\}_{T} \mapsto \left\{ r \right\}_{G} $$
(1)

Symbol \(\left\{ r \right\}_{T}\) denotes coordinates of the vector \(r\) in the coordinate system \(T\). This transformation can be known or can be estimated by the image features (e.g. hole’s ellipse orientation). Cylinder axis is identical to z-axis of the T base. This relation between camera and thread is displayed on Fig. 2.

The second transformation is projection to the focal plane. For simplicity, we assume unit focal length.

$$ \begin{array}{*{20}c} {{\Phi }_{p} :{\mathbb{R}}^{3} \to {\mathbb{R}}^{2} } \\ {\left( {\begin{array}{*{20}c} {x } \\ { y } \\ { z} \\ \end{array} } \right) \mapsto \left( {\begin{array}{*{20}c} {x/z} \\ { y/z} \\ \end{array} } \right)} \\ \end{array} $$
(2)

Cylinder points can be mapped to plane by the polar transformation which is described by the equation:

$$ \begin{array}{*{20}c} {{\Phi }_{c} :\left( {0,1} \right) \times \left( {0,2\pi } \right) \to {\mathbb{R}}^{2} } \\ { \left( {\begin{array}{*{20}c} {z, \varphi } \\ \end{array} } \right) \mapsto \left( {Cos\left( \varphi \right),Sin\left( \varphi \right), z} \right)} \\ \end{array} $$
(3)
Fig. 2.
figure 2

Geometric arrangement visualization. Green coordinate system \(T\) corresponds with thread’s cylinder and the blue coordinate system \(G\) corresponds with camera.

Composed map function \({\Phi } = {\Phi }_{p} \circ {\Phi }_{G \to T} \circ {\Phi }_{c}\) assigns image coordinates to polar coordinates of the cylindrical surface. If \(I\left( {x,y} \right)\) is brightness function of the camera image, then function \(\left( {I \circ {\Phi }} \right)\left( {z,\varphi } \right)\) is an image of the cylindrical surface in the polar coordinates. Example of this image transformation is shown on Fig. 3.

With real image it is also necessary to perform a transformation between physical and pixel coordinates. These details will be ignored in this article for simplicity, but the texture mapping and image warping is described more precisely in [1].

Fig. 3.
figure 3

Left-handed and right-handed threads mapped to detected cylindrical surface. The important edges are highlighted by red color. These edges are used to following processing.

This image can be processed by the many different approaches. Our procedure was chosen with respect to evaluation speed and robustness. To the edge detection, the image is processed by the some standard filters in the vertical direction. Then FFT is used to obtain image periodogram. 2D FFT method can be used to detect of fibres direction how is described in [2]. This idea is used to detect direction of the lines from Fig. 3. Both periodograms (left-handed and right-handed thread) are shown in Fig. 4.

Fig. 4.
figure 4

Image periodogram evaluated by FFT. Not all values are used to the following processing. Used points are highlighted by red color.

Image periodogram is thresholded and the selected points are processed by statistical moments. Let be \(p\left( {x,y} \right)\) value of the thresholded and normalized image periodogram, which can be considered as probability density. Let be \(S = \{ \left( {x,y} \right):p\left( {x,y} \right) > 0\}\). Then we can express the moments up to order 2 by the next equations:

$$ \begin{array}{*{20}c} {\mu_{x} = \mathop \smallint \limits_{S} x dp, \mu_{y} = \mathop \smallint \limits_{S} y dp } \\ { \mu_{xx} = \mathop \smallint \limits_{S} \left( {x - \mu_{x} } \right)^{2} dp} \\ {\mu_{xy} = \mu_{yx} = \mathop \smallint \limits_{S} \left( {x - \mu_{x} } \right)\left( {y - \mu_{y} } \right)dp} \\ { \mu_{yy} = \mathop \smallint \limits_{S} \left( {y - \mu_{y} } \right)^{2} dp} \\ { M = \left( {\begin{array}{*{20}c} {\mu_{xx} } & {\mu_{xy} } \\ {\mu_{yx} } & {\mu_{yy} } \\ \end{array} } \right) } \\ \end{array} $$
(4)

Eigensystem of the matrix \(M\) can be displayed as the ellipse which has axis identical with eigenvectors and axes lengths ratio is equal to ratio of the eigenvalues. These ellipses are shown in Fig. 5. The idea of image moments and moment invariants is usually used to pattern recognition. This topic is described in [3].

Fig. 5.
figure 5

Eigenvectors and eigenvalues visualized by the ellipses. Angle between ellipse semi-major axis and image vertical axis determines handedness of the thread.

Note that the real situation is influenced by the variable thread surface quality, variable light conditions and metallic shiny thread surface. In these cases is not possible to find edges in the same quality which are displayed above. But evaluation by described procedure seems to be sufficiently reliable.

2.3 Pitch Measurement

Pitch is measured from image of the cylinder map which is turned by the found angle. Image rotation makes the edge line horizontal and then is simple to measure pitch. We calculate point counts over rotated image rows. These counts as function of the row position have significant peaks. Distances between these peaks correspond to the pitch value.

3 Measurement Error

Quality of the image mapping to cylindrical surface depends on the function \({\Phi }_{T \to G}\). If this function is not determined exactly then the mapped image \(I \circ {\Phi }\) is deformed. That can adversely affects the result. Some errors that can occur in our case will be discussed below. For simplicity, assume unit cylinder radius and unit focal length. Let be.

$$ \begin{array}{*{20}c} {V = \left\{ {\left( {x,y,z} \right) \in {\mathbb{R}}^{3} :x^{2} + y^{2} = 1} \right\} } \\ { s\left( \alpha \right) = \left( {Cos\left( \alpha \right),Sin\left( \alpha \right),a \alpha } \right), \alpha \in \left( {0,\pi } \right), a > 0} \\ \end{array} $$
(5)

The point set \(\left\{ {s\left( \alpha \right),\alpha \in \left( {0,\pi } \right)} \right\} \subset V\) is a part of helix. Projection of this curve to the focal plane is \(s_{p} \left( \alpha \right) = \left( {{\Phi }_{p} \circ {\Phi }_{T \to G} } \right)\left( {s\left( \alpha \right)} \right),\alpha \in \left( {0,\pi } \right)\). Example of this projection is shown on the Fig. 6.

Fig. 6.
figure 6

Helix curve on the cylinder surface and its projection (red curve) on the focal plane (green plane). Z-axis of the thread coordinate system is represented by the arrow.

We want to map the curve \(s_{p}\) to the wrongly detected cylinder \(V_{E}\). Relations between the original cylinder coordinate system \(T\) and error cylinder coordinate system (denoted as \(E\)) is given by mapping \({\Phi }_{T \to E} :\left\{ r \right\}_{T} \mapsto \left\{ r \right\}_{E}\). For example, in our case, this error can be caused by detecting of the incorrect edge on the thread hole. Two cases which can occur in our task will be discussed next.

It is necessary to solve inverse problem to map the curve \(s_{p}\) to the error cylinder \(V_{e}\). Let be \(P_{f}\) focal point and \(\rho \left( t \right) = \left( {1 - t} \right)\left\{ {P_{f} } \right\}_{E} + t \left\{ {s_{p} \left( \alpha \right)} \right\}_{E} , t > 0\) for some \(\alpha \in \left( {0,\pi } \right).\) We want to find intersection \(\{ \rho \left( t \right):t > 0\} \cap V_{E}\). This leads to quadratic equation with one unknown parameter \(t\). Equation can be solved exactly for all \(t\) but for our case is sufficient to solve equation only for some points and use linear approximation.

3.1 Translation Error

Assume translation in \(x\)-direction. This transformation is described by function \(\left( {x,y,z} \right) \mapsto \left( {x + \delta , y,z} \right), d \in {\mathbb{R}}\). Evaluation for some discrete values of the parameter \(d\) is shown on Fig. 7.

Fig.7.
figure 7

Helix curve mappings to shifted cylinder for shift \(\delta \in \left\{ { - 0.1, - 0.05, 0, 0.05, 0.1} \right\}\). Blue curves for positive shift and red curves for negative shift value.

We use image processing as it is described above. Results for the original cylinder and shifted cylinders are shown on Fig. 8.

Fig. 8.
figure 8

Eigenvectors ellipses for three cases: \(\delta = 0.2\) (top), \(\delta = 0\) (middle) and \(\delta = 0.2\) (bottom).

3.2 Diameter Measurement Error

In this case we can suppose that error coordinate system \(E\) is identical with the thread’s cylinder coordinate system \(T\). But the projection to cylinder surface leads to equation \(\rho_{x}^{2} \left( t \right) + \rho_{y}^{2} \left( t \right) = \left( {1 + \delta } \right)^{2}\), where \(\rho \left( t \right) \in {\mathbb{R}}^{3}\) is parametric equation for infinite line which contains the focal point with some curve point on the focal plane. Alternatively we can suppose translation in the camera view direction. Due to projection the more distant cylinder seems smaller. It causes that the results are similar as it is mentioned for translation error in Sect. 3.1.

3.3 General Case

How it is mentioned in the previous section, the radius error can be considered as shift in the view direction. So the general case can be expressed as composition of some affine transformations. In our case the errors are caused by the detection of different edges on the screw thread (it depends how the thread is rotated around its axis). The error magnitude corresponds with the height of the thread.

Other case is when we expect the fixed position of screw thread but the real thread is shifted due to geometric tolerance. Methods mentioned above can be used to estimate maximal possible error. Alternatively, we can find conditions to ensure sufficient accuracy.

4 Conclusion

Methods mentioned in this article were used to develop camera inspection system which is used in manufacturing industry. System controls parts with internal screw thread and decides whether the inset part is the correct type. In this case some geometric conditions are known but methods can be generalized for the cases when the thread’s cylinder position is unknown. Method can also be used for the external screw thread.