# Automated Optical Inspection System for O-Ring Based on Photometric Stereo and Machine Vision
## 2 The Proposed System
### Processing of Defect Detection
\begin{array}{c}\alpha N_{x}=(y_{1}-y_{0})(z_{2}-z_ {0})-(z_{1}-z_{0})(y_{2}-y_{0})\\ \alpha N_{y}=(z_{1}-z_{0})(x_{2}-x_{0})-(x_{1}-x_{0})(y_{2}-y_{0})\end{array} \right]\] (16)
11. We define A equal all of constant relative with \(z\), and B equal \(\alpha N_{x}\) and \(\alpha N_{y}\). Then, we can get the relative height of each pixel \(Z\) by using the function (14). \[Z=\left(A^{T}A\right)^{-1}A^{T}B\] (17)
12. At last, we create a 2.5-D model by using the photometric stereo method. The result is shown in Figure 9a. With the photometric stereo method, errors resulting from surface dirt in the inspection process were effectively prevented. On the other hand, we used the image from button light of defect detection mechanism (\(I_{6}\), Figure 9b) to produce a binary image (Figure 9c). Moreover, this binary image was one of the materials used to produce a smooth surface model \(M_{\text{S}}\) (Figure 9d). Figure 5: Flowchart of the O-Rings defect detection process. The green region is image capture relative processing and the yellow region is defect detection relative processing. Which \(M_{\text{P}}\) and \(I_{6}\) replace with result of optical profilometer reconstruction when the verification stage. Figure 6: Images \(I_{i}\) (\(i\) = 1,2,3,4,5,6) from the camera of defection detection system capture. Figure 7: A set images \(I_{i}\) (\(i\) = 1,2,3,4,5,6) without background information. We generated two factors to produce smooth surface model. One was a binary image of \(I_{6}\) (Figure 9c) and the other one was the photometric stereo model \(M_{\text{S}}\). First, we extract contours [14] from Figure 9c. the method of find contour can be explained simply as a curve joining all the continuous points (along the boundary), having same color or intensity. The contours extracted based on chain code 8-connectivity are shown in Figure 10a. then, we used cubic Bezier curve to describe to contours. Before the transformation between contour and cubic Bezier curve. we named all of the control points of the cubic Bezier curve shown in Figure 11. Therefore, we defined the cubic Bezier curve in Equation (18), which we obtained with starting point \(p_{00}\), end point \(p_{03}\), tracking points \(p_{30}\) with corresponding parameter \(\omega\), all of \(\omega\) held values that varied between 0 and 1. Which parameter \(\omega\) is used to describe cubic Bezier curve. After that, we obtained \(p_{01}\) and \(p_{02}\) using the solution of  
Figure 8: Unit vector field \(\overline{N}\) by using function (11). Figure 9: Each stage output of defect detection processing: (**a**) Model of photometric stereo produce; (**b**) \(I_{6}\), this image capture with the button light source in defect detection mechanism (Figure 3); (**c**) binarization and inverse image of (**b**); (**d**) smooth model \(M_{\text{S}}\), created by Figure 5; (**e**) result of (**d**) subtracted from (**e**); (**f**) candidate defect area, which create by sliding windows. simultaneous Equation (19). We used the contour start point \(p_{00}\), end point \(p_{03}\), two tracking points \(p_{30}\) with corresponding parameter \(\omega\) to solute Equation (19). Which tracking points selected by one-third point and two-thirds points of contour points. In Figure 10b, the red points are the cubic Bezier curve's control points and the green curve is the cubic Bezier curve. In other words, we used the solution of the simultaneous Equation (19) to acquire \(B_{1}\) and \(B_{2}\). Moreover, we acquired the path vector \(\overrightarrow{p}\) of the O-Ring by interpolating both \(B_{1}\) and \(B_{2}\). \[p_{30}=(1-\omega)^{3}p_{00}+3\omega(1-\omega)^{2}p_{01}+3\omega^{2}(1-\omega)p _{02}+\omega^{3}\,p_{03}\,\omega\in[0,\,1] \tag{18}\]  
\[3\omega(1-\omega)^{2}p_{01}+3\omega^{2}(1-\omega)p_{02}=p_{30}-(1-\omega)^{3} p_{00}-\omega^{3}\,p_{03} \tag{19}\]  
Secondly, we obtained several vectors of height \(\overrightarrow{h}\) (Figure 10c by using the path \(\overrightarrow{p}\) as a factor.