# A Non-Contact Measurement of Animal Body Size Based on Structured Light
## 2 Materials and Methods
### Light Plane Calibration
#### 2.2.2 Calculate Light Plane  
After obtaining the chessboard calibration plate plane, we project the light plane above the chessboard area in the plate, shown in Figure 3. The selection of the number of stripes in the structured light image should be based on the object to be projected, and the distance between the camera and the projector should be based on the distance between the object and the device. We also set an angle between the axes of the camera and the projector to ensure that the light stripes projected by the projector are centered in the camera frame, which is not a fixed value, and its size depends on the specific circumstances during the experiment. It is sufficient as long as the light stripes are centered in the camera frame. These stripes appearing on the plate are the intersection lines of the chessboard calibration plate plane and light plane. We use an improved Otsu method to separate the image background and these lines. The Otsu method [24] is an efficient algorithm for image binarization, which was proposed by Japanese scholar [PERSON] in 1979. It utilizes the maximum between-class variance to divide the original image into the foreground and background. However, due to factors such as the material, color, and surface smoothness of the calibration plate, the reflectivity of the plate varies, which can easily lead to uneven brightness of the strips in the plate, as shown in Figure 4a. Using the Otsu method directly may separate the astigmatism region into the foreground area, as shown in Figure 4b. Therefore, we use the histogram equalization method and the Otsu method on the image and detect the gray-center of each pixel row. Then, we delete the rows in which the number of gray centers does not fit the stripes number. Because we are using structured light, we can estimate the pixel distances between these stripes, divide the original image into several different windows, and use the Otsu method in each window to solve the light scattering problem. The image only has two grayscale values: 0 and 255. Then, we use the image's grayscale to find the boundary of light stripes and obtain the gray centers of the light plane.  
After obtaining the gray centers of the light plane, we use the improved segment-facet intersection method to calculate those gray-centers coordinates in world coordinates. The improved segment-facet intersection method [25] was proposed by [PERSON] et al. They proved that the point coordinates in world coordinates can be calculated using Equations (5) and (6), where (\(Xw\), \(Yw\), \(Zw\)) are the point coordinates in world coordinates, \(A\), \(B\), \(C\) are the undetermined coefficients of the plane equation \(Ax+By+C=z\), matrix \(\mathbf{I}\) is the camera intrinsic matrix and (\(u\), \(v\)) are the point coordinates in pixel coordinates. Then, we rotate and translate the calibration plate to obtain several groups of gray centers, distribute those points into sets that belong to the same light plane, and calculate the light plane with the least squares method. The pseudo-code of light plane calibration is shown in Algorithm 1.  
\[\begin{bmatrix}X_{u}\\ Y_{n}\\ Z_{n}\end{bmatrix}=\mathbf{I}^{-1}\begin{bmatrix}u\\ v\\ 1\end{bmatrix} \tag{5}\]  
\[\begin{cases}\begin{array}{c}X_{w}=t\cdot X_{n}\\ Y_{w}=t\cdot Y_{n}\\ Z_{w}=t\\ t=\frac{-C}{A\cdot X_{n}+B\cdot Y_{n}-1}\end{array}\end{cases} \tag{6}\]  
Figure 4: (a) Original light stripe; (b) simply using OSTU for image binarization.  
Figure 3: Projecting the light plane above the area of chessboard Area.