# Automated Optical Inspection System for O-Ring Based on Photometric Stereo and Machine Vision
## 4 Experiment Results and Discussion
### Dimension Measurement  
We compared the Ramer-Douglas-Peucker algorithm result points \(A\) and contour \(C\) with the method \(B_{\text{P}}\) we proposed, all of those points through homography matrix and Euclidean distance to calculate distance. Then calculated the internal and cross-section diameter. On the other hand, we employed the mean absolute error to estimate loss \(L\) to evaluate measurement results and stability. The formula of the loss \(L\) is shown in Equation (21). \[L=\Sigma(\left\lfloor\,v-d_{\text{s}}\,\right\rfloor)/n \tag{21}\]  
The \(d_{\text{s}}\) was the median size between the maximum allowable dimension and minimum allowable dimension from ISO. The loss \(L\) was acquired using the median size \(d_{\text{s}}\), which deducted the measurement result \(v\), and the \(n\) is the number of the same size O-Ring samples. The DVT measurement results of internal and cross-section diameters are shown in Figure 26a,b. Moreover, the DSI measurement results of internal and cross-section diameters are shown in Figure 26c,d. In addition, the DSP measurement results for the internal and cross-section diameters are shown in Figure 26e,f. All of the results display our processing can improve measurement result. \begin{table}
\begin{tabular}{c c c c} \hline \hline  & & \multicolumn{2}{c}{**True Condition**} \\ \cline{3-4}  & & **Positive** & **Negative** \\ \hline \multirow{2}{*}{Predicted Outcome} & Positive & 160 & 0 \\ \cline{2-4}  & Negative & 0 & 160 \\ \hline \multicolumn{2}{c}{Accuracy} & \multicolumn{2}{c}{100\%} \\ \hline \multicolumn{2}{c}{Precision} & \multicolumn{2}{c}{100\%} \\ \hline \multicolumn{2}{c}{Recall} & \multicolumn{2}{c}{100\%} \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Confusion matrix of the defect result with DK. Figure 25: **(a)** optical profilometer model; **(b)** smooth model \(M_{\text{S}}\); **(c)** subtracting result on defect candidate area. Figure 26: Cont. In those results, we can prove that the method we proposed can further improve the measurement error from edge protrusions. The detailed comparison is shown in Figure 27. There is some small noise at the O-Ring edge (Figure 27a). To improve the measurement, we ignore those protrusions using Ramer-Douglas-Peucker algorithm (Figure 27b). However, this method could lose the real edge of O-Ring too much from very large threshold. Such as the blue line and green line in Figure 27b, both lines were the measurement result  
Figure 26: (**a**) Result of \(d_{1}\) measurement with DVT; (**b**) result of \(d_{2}\) measurement with DVT; (**c**) result of \(d_{1}\) measurement with DSI; (**d**) result of \(d_{2}\) measurement with DSI; (**e**) result of \(d_{1}\) measurement with DSP; (**f**) result of \(d_{2}\) measurement with DSP. using Ramer-Douglas-Peucker algorithm. Moreover, if we set the threshold too small, the algorithm loses the ability to ignore edge protrusions. To further reduce measurement error, we proposed a new edge extracting algorithm in Section 2. This algorithm using a large threshold in Ramer-Douglas-Peucker algorithm. We fitted each contour \(C\) between every two points \(A\) by using the cubic Bezier curve. The cubic Bezier curve is shown in Figure 27c. In Figure 27c, red points are Ramer-Douglas-Peucker algorithm result points and cubic Bezier control points p\({}_{00}\) and p\({}_{03}\), and green points are cubic Bezier control points p\({}_{01}\) and p\({}_{02}\) by Equation (19) and the yellow curve was the fitting result of our cubic Bezier fitting algorithm. Thus, we can ignore edge protrusions and guarantee real edge information be keeping. Then, we use homography to calculate dimension. To verify measurement stability, we used the STD (standard deviation) as an index for measurement stability. The measurement results of \(d_{1}\) and \(d_{2}\) are shown in Tables 7 and 8. This result proves the measurement processing we proposed is the most stable in those three algorithms.