## 4 Measurement of the Length, Width, and Diagonal of a Cross-Cutting Board
### Fitting Straight Lines to Edge Contours  
The result of extracting the contour of the cutting board edge is a point cloud collection formed by numerous points, rather than a single line, as shown in Figure 11.  
Therefore, in order to accurately locate and identify the intersection points of the edge, it is necessary to perform line fitting on the point cloud of the cross-cutting board's edge contour. The commonly used fitting methods include the algebraic approximation method, orthogonal distance regression method, and least squares method [25; 26; 27; 28]. This article uses the least squares method to achieve linear fitting. The least squares method matches the optimal point coordinates by finding the minimum sum of squared errors. Figure 10: Principle of calculating the length, width, and diagonal of a cross-cutting board. Linear regression:  
Assume that the equation of the fitted line is as follows:  
\[y=kx+b \tag{11}\]  
Among them, \(k\) represents the slope of the line, \(b\) represents the intercept. Assuming that the coordinates of points on the linear contour are \((x_{i},y_{i})\) with a total quantity of \(M\), \(x_{i}\) is known accurately; the least squares method aims to find suitable values for \(k\) and \(b\) in order to minimize the weighted sum (\(Q_{l}\)) of squared deviations in \(y_{i}\). This can be expressed as follows:  
\[Q_{l}=\sum_{i=1}^{M}[y_{i}-(kx+b)]^{2} \tag{12}\]  
Taking the partial derivative of Equation (12) and rearranging, we obtain the following:  
\[\left\{ \begin{array}{l}bM+k{\sum x_{i}}={\sum y_{i}}\\ b{\sum x_{i}}+k{\sum x_{i}}^{2}={\sum x_{i}y_{i}}\end{array} \right. \tag{13}\]  
Assuming that the four edges of the cross-section board can be fitted with a linear equation,  
Line one:  
\[y_{1}=k_{1}x_{1}+b_{1} \tag{14}\]  
Then:  
\[Q_{l1}=\sum_{i=1}^{M_{1}}[y_{1i}-(k_{1}x_{1}+b_{1})]^{2} \tag{15}\]  
Taking the partial derivative of Equation (15):  
\[\left\{ \begin{array}{l}b_{1}M_{1}+k_{1}{\sum x_{1i}}={\sum y_{1i}}\\ b_{1}{\sum x_{1i}}+k_{1}{\sum x_{1i}}^{2}={\sum x_{1i}y_{1i}}\end{array} \right. \tag{16}\]  
Line two:  
\[y_{2}=k_{2}x_{2}+b_{2} \tag{17}\]  
Then:  
\[Q_{l2}=\sum_{i=1}^{M_{2}}[y_{2i}-(k_{2}x_{2}+b_{2})]^{2} \tag{18}\]  
Figure 11: Collection of point clouds representing edge contours. Taking the partial derivative of Equation (18),  
\[\left\{ \begin{array}{l}b_{1}M_{1}+k_{1}{\sum x_{2i}}={\sum y_{2i}}\\ b_{1}{\sum x_{2i}}+k_{1}{\sum x_{2i}}^{2}={\sum x_{2i}}y_{2i}\end{array} \right. \tag{19}\]  
Line three:  
\[y_{3}=k_{3}x_{3}+b_{3} \tag{20}\]  
Then:  
\[Q_{l3}=\sum_{i=1}^{M_{3}}[y_{3i}-(k_{3}x_{3}+b_{3})] \tag{21}\]  
Taking the partial derivative of Equation (21),  
\[\left\{ \begin{array}{l}b_{3}M_{3}+k_{3}{\sum x_{3i}}={\sum y_{3i}}\\ b_{3}{\sum x_{3i}}+k_{3}{\sum x_{3i}}^{2}={\sum x_{3i}}y_{3i}\end{array} \right. \tag{22}\]  
Line four:  
\[y_{4}=k_{4}x_{4}+b_{4} \tag{23}\]  
Then:  
\[Q_{l4}=\sum_{i=1}^{M_{4}}[y_{4i}-(k_{4}x_{4}+b_{4})] \tag{24}\]  
Taking the partial derivative of Equation (24),  
\[\left\{ \begin{array}{l}b_{4}M_{4}+k_{4}{\sum x_{4i}}={\sum y_{4i}}\\ b_{4}{\sum x_{4i}}+k_{4}{\sum x_{4i}}^{2}={\sum x_{4i}}y_{4i}\end{array} \right. \tag{25}\]  
For example, taking the cross-cutting board image shown in this article, the calculated results for fitting line parameters are shown in Table 1.  
From Table 1, it can be concluded that the linear fitting has a good effect, and the equations for the four lines can be obtained. Line one:  
\[y_{1}=5030 \tag{26}\]  
Line two:  
\[y_{2}=-\frac{5020}{101}x-\frac{3,472,830}{101} \tag{27}\]  
Line three:  
\[y_{3}=5010 \tag{28}\]  
Line four:  
\[y_{4}=\frac{5020}{101}x-\frac{3,472,830}{101} \tag{29}\]  
The results of the straight-line fitting for the point cloud on the edge of the cross-cutting board are shown in Figure 12.