# Automated Optical Inspection System for O-Ring Based on Photometric Stereo and Machine Vision
## 2 The Proposed System
### Processing of Dimension Measurement
#### 2.3.2 Dimension Measurement Processes  
The dimension measurement process is shown in Figure 14. This process starts with image \(I\), which is captured by the camera. Then, undistort \(I\) (Figure 15a) is acquired using distortion coefficients \(D\) and camera matrix \(M\). Finally, the contours [14] (Figure 15c) are acquired using the \(I\) binarization image \(I_{\text{b}}\) (Figure 15b).  
First, we divided the contours into two parts using hierarchy [14]. One was the internal contour (Figure 15c), the other was the external contour. Then, we converted those contours into the cubic Bezier curve. In the beginning of the process, we converted the contour into the Bezier curve, and divided contour \(C\) (Figure 15c) into contour \(C_{i}\) (the green line between Figure 15e, red points) using approximate points \(\overset{\rightarrow}{A}\) (Figure 15d) from the Douglas-Peucker algorithm [17]. The Douglas-Peucker algorithm is shown below:  
1. Find the start point \(P_{\text{A}}\) and end point \(P_{\text{B}}\) of object contour \(C\) (Figure 16a);
2. Connect start point \(P_{\text{A}}\) and end point \(P_{\text{B}}\). Then, find the furthest point \(P_{\text{C}}\) and calculate the distance \(D\) from the point \(P_{\text{C}}\) to the line \(\overline{P_{A}P_{B}}\) (Figure 16b).
3. If the distance \(D\) from the point \(P_{\text{C}}\) to the line \(\overline{P_{A}P_{B}}\) is bigger than the threshold we settled, divide the contour into two parts. Then, calculate the distance \(D\) from the point to the line, respectively (Figure 16c).
4. Else if all of the distance \(D\) from the point to the line is smaller than the threshold finish the approximate operation.  
Figure 13: The schematic diagram of projected relation between the image plane and object plane in measurement mechanism (Figure 3b).  
Figure 14: Flowchart of the dimension measurement.  
Figure 15: Cont.  
Figure 16: _Cont._  
Figure 15: Each stage output of dimension measurement processing: (**a**) The image \(I\) from camera capture; (**b**) the binarization and inverse image \(I_{\text{b}}\); (**c**) internal contour of the O-Ring; (**d**) approximate points \(\overset{\rightarrow}{A}\); (**e**) schematic diagram of the divided contour; (**f**) result of the converted cubic Bézier control points.  
By using the Douglas-Peucker algorithm, we could ignore the \(I_{\text{b}}\) (Figure 15b) edge noise and O-Ring burrs to obtain a perimeter. Though the perimeter was more accurate than the calculated contour, it cost us too much information regarding the real edge. As a result, we proposed a more accurate solution using the cubic Bezier curve to approximate each \(C_{i}\). We employed Equation (19) to acquire the cubic Bezier control points (Figure 15f) with each \(C_{i}\) and projected control points using homography \(H\)[16]. Finally, the arc length was calculated using the Euclidean distance via [PERSON]'s algorithm [18]. The process of the cubic Bezier curve conversion is shown in Figure 17.  
Figure 16: Schematic diagram of Douglas–Peucker algorithm: (**a**) A set of contour points and start point \(P_{\text{A}}\) and end point \(P_{\text{B}}\); (**b**) Connect start point \(P_{\text{A}}\) and end point \(P_{\text{B}}\). Then, find the furthest point \(P_{\text{C}}\) and calculate the distance \(D\) from the point \(P_{\text{C}}\) to the line \(\overline{P_{\text{A}}P_{\text{B}}}\); (**c**) If the distance \(D\) from the point \(P_{\text{C}}\) to the line \(\overline{P_{\text{A}}P_{\text{B}}}\) is bigger than the threshold we settled, divide the contour into two parts. Then, calculate the distance \(D\) from the point to the line, respectively; (**d**) Else if all of the distance \(D\) from the point to the line is smaller than the threshold finish the approximate operation.