# Feature-Model-Based In-Process Measurement of Machining Precision Using Computer Vision
## 3 Measurement Implementation and Verification
### Measurement of Rectangular Sealing Gaskets  
#### 3.3.1 Measurement of Straightness of Rectangular Sealing Gaskets  
Directness is defined as the difference between the maximum distance and the minimum distance between the two closest planes. This definition is based on measuring the distances from each point on the workpiece surface to these two planes, used to quantify the linearity of the workpiece surface. Figure 12 utilizes the contour point set of a rectangular sealing piece workpiece (\(x_{i}\), \(y_{i}\)) to form a set of data points, where \(i=1\), \(2\), \(\ldots\), \(n\). These points represent the coordinates on the workpiece surface or contour line. Initially, these data points are fitted into contour lines using the least squares method to ensure that the fitted line closely approximates the actual data points.  
\[S(m,c)=\sum_{i=1}^{n}\left(y_{i}-(mx_{i}+c)\right)^{2} \tag{24}\]  
where \(m\) is the slope and \(c\) is the intercept. \(S(m,c)\) represents the sum of squared errors that need to be minimized with respect to \(m\) and \(c\).  
\begin{table}
\begin{tabular}{c c c c c c c} \hline \hline \multirow{2}{*}{**Measurement Position**} & \multirow{2}{*}{**Part**} & \multicolumn{2}{c}{**Three Coordinate Measuring**} & \multirow{2}{*}{**This Article’s Algorithm**} & \multicolumn{1}{c}{**Sub-Pixel Edge Detection**} & \multicolumn{1}{c}{**Otsu–Canny Edge Detection**} & \multicolumn{1}{c}{**Canny Edge Detection**} \\  & & \multicolumn{2}{c}{**Measuring Machine (mm)**} & & **(mm)** & **Algorithm** & **Algorithm** & **Algorithm** \\ \hline \multirow{4}{*}{Length of the inner groove} & part 1 & 43.993 & 43.979 & 45.374 & 43.938 & **43.997** \\  & part 2 & 44.005 & **43.989** & 44.823 & 44.324 & 44.118 \\  & part 3 & 44.042 & **44.048** & 44.616 & 42.153 & 44.152 \\  & part 4 & 44.027 & **44.044** & 44.099 & 42.687 & 44.100 \\  & part 5 & 44.005 & **44.018** & 43.961 & 44.031 & 44.200 \\ \hline \multirow{4}{*}{Width of the inner groove} & part 1 & 30.002 & **29.991** & 29.664 & 29.096 & 30.060 \\  & part 2 & 29.980 & **29.991** & 28.596 & 29.974 & **29.991** \\  & part 3 & 30.026 & **30.022** & 30.319 & 30.043 & 30.181 \\  & part 4 & 30.017 & **29.991** & 29.761 & 29.233 & **29.991** \\  & part 5 & 30.008 & 29.991 & 28.010 & **30.009** & 30.043 \\ \hline \multirow{4}{*}{Distance from the circle to the edge} & part 1 & 30.588 & 30.554 & **30.564** & 30.549 & 37.349 \\  & part 2 & 30.581 & 30.711 & 30.498 & **30.576** & 30.047 \\ \cline{1-1}  & part 3 & 30.496 & **30.411** & 30.318 & 30.623 & 35.380 \\ \cline{1-1}  & part 4 & 30.496 & **30.501** & 30.569 & 30.551 & 28.858 \\ \cline{1-1}  & part 5 & 30.591 & **30.581** & 30.646 & 30.676 & 17.724 \\ \hline \hline \end{tabular} In the table, the best relative precision is in bold.  
\end{table}
Table 2: Statistical Table of Measurement Results.  
By taking partial derivatives of \(S(m,c)\) with respect to \(m\) and \(c\), and setting them equal to zero, we can obtain the estimated values of the slope \(m\) and intercept \(c\) for the best-fit line:  
\[c=\frac{n\sum_{i=1}^{n}x_{i}y_{i}-(\sum_{i=1}^{n}x_{i})(\sum_{i=1}^{n}y_{i})}{n \sum_{i=1}^{n}x_{i}^{2}-(\sum_{i=1}^{n}x_{i})^{2}} \tag{25}\]  
\[c=\frac{\sum_{i=1}^{n}y_{i}-m\sum_{i=1}^{n}x_{i}}{n} \tag{26}\]  
Once the slope \(m\) and intercept \(c\) of the best-fit line are obtained, the perpendicular distance \(d_{i}\) from each data point to the line can be calculated. Subsequently, the maximum and minimum distances can be determined:  
\[d_{i}=\frac{|mx_{i}-y_{i}+c|}{\sqrt{m^{2}+1}} \tag{27}\]  
\[\text{Straightness}=\max(d_{i})-\min(d_{i}) \tag{28}\]  
Finally, the calculated straightness value is used to assess the straightness quality of the workpiece surface. A smaller straightness value indicates a smoother and straighter workpiece surface, while a larger straightness value may indicate significant curvature or waviness on the surface.