Cattle Body Size Measurement Based on DUOS–PointNet++

Simple Summary In intelligent agriculture, non-contact, automatic body size measurement is widely used for livestock. However, the common measurement methods based on the whole point cloud are complex and prone to errors because of the positions of the cattle. To measure the body sizes of livestock more accurately, a cattle body measuring system is proposed. The system includes a new algorithm called dynamic unbalanced octree grouping (DUOS), based on PointNet++, and an efficient method of body size measurement based on segmentation results. The network divides the cow into the following seven parts: body length, withers height, hip height, thoracic circumference, abdominal circumference, and cannon circumference. Compared with some of the other models, the system has higher segmentation accuracy and lower measurement errors. The system can be widely applied in the non-contact body measurement of livestock; in addition, it can increase efficiency and reduce costs. It also has broad prospects in the intelligent livestock industry. Abstract The common non-contact, automatic body size measurement methods based on the whole livestock point cloud are complex and prone to errors. Therefore, a cattle body measuring system is proposed. The system includes a new algorithm called dynamic unbalanced octree grouping (DUOS), based on PointNet++, and an efficient method of body size measurement based on segmentation results. This system is suitable for livestock body feature sampling. The network divides the cow into seven parts, including the body and legs. Moreover, the key points of body size are located in the different parts. It combines density measurement, point cloud slicing, contour extraction, point cloud repair, etc. A total of 137 items of cattle data are collected. Compared with some of the other models, the DUOS algorithm improves the accuracy of the segmentation task and mean intersection by 0.53% and 1.21%, respectively. Moreover, compared with the manual measurement results, the relative errors of the experimental measurement results are as follows: withers height, 1.18%; hip height, 1.34%; body length, 2.52%; thoracic circumference, 2.12%; abdominal circumference, 2.26%; and cannon circumference, 2.78%. In summary, the model is proven to have a good segmentation effect on cattle bodies and is suitable for cattle body size measurement.


Introduction
In evaluating cattle indicators, body size parameters are essential [1].In the past, livestock data were measured manually [2,3], resulting in detrimental effects related to animal welfare protection [4].Non-contact measurement is the key aspect of the integration of intelligence into animal husbandry, and previous studies have reported many successful cases [5].
A two-dimensional (2D) image acquisition measurement system was established to calculate the size data of cows [6].A foreground extraction algorithm based on SLI and FCM and a point extraction measurement algorithm were proposed to extract and calculate the body size of sheep [7].
However, the two-dimensional image processing method requires strict calibration and only measures partial body sizes accurately, while lacking precision for three-dimensional (3D) spatial data.To solve these problems, several researchers have used the Kinect series of depth cameras for depth data collection [8][9][10].In [11,12], multiple depth cameras were used to obtain the point cloud and perform 3D reconstruction, which is a common method.Subsequently, the Poisson surface reconstruction algorithm was used to complete the measurements [13].The symmetry properties of unilateral or bilateral point clouds have been applied [14,15].With registration using a cuboid and the polar coordinate transformation algorithm, it was possible to calculate the parameters more accurately [16].Kinect v4 and YOLOv5 were used to remove cattle from the environment to measure body size [17].Subsequently, fusion processing methods based on 2D and 3D data were proposed [18].Depth-based camera features were used to classify and transform a pig's posture based on its skeleton [19].An acquisition method with a single depth camera placed on a rod was proposed [20].In addition, an improved segmentation model to measure pig body size using part of the body was proposed [21].Machine learning algorithms were used to measure the body size and weight of cows [22,23].Depth images were used for cattle body condition scoring [24].
At present, most of cattle body size measurements based on a point cloud use the complete cattle point cloud after registration.The relationship between body size parameters and genome-wide association studies was investigated [25].A measurement method involving the extraction of key points from the point cloud of the entire body of the cow was used to measure body size [26].
The advantage of this method is that it reduces the number of data processing steps and ensures the continuity of the data.However, due to the large number of points in the collected and processed cow's complete point cloud, along with the varying positions and occlusions of different body parts, considerable time is consumed in model calculation.This also results in interference from the point clouds originating from other parts of the body, resulting in the positioning error of key points.Moreover, for nonrigid objects such as cattle, the traditional point cloud segmentation network model causes inaccurate segmentation, low evaluation parameters, poor robustness, and other problems.
To solve these problems, an improved deep learning model based on the improved octree algorithm and the segmentation model of PointNet++ is proposed.The proposed method can segment each part of the cattle point cloud, then locate the key points of cattle body measurement according to the geometric features, effectively improving the accuracy of the subsequent body measurement of cattle.Simultaneously, a measurement method is proposed to measure cattle body size based on the segmented body of the cow.The proposed method makes it easier to extract the key points of measurement, achieving higher accuracy.

Materials and Methods
In this study, no animals were used or cared for.Moreover, no animal care or ethics committee approval was required because the data used in the study were obtained from routine cattle herd management practices.

Data Collection
The cattle data collection was completed in 2023 in the pasture of Shengquan Animal Husbandry Co., Ltd., located in Wengniute Banner, Chifeng City, Inner Mongolia Autonomous Region, China.Kinect V2 was chosen because it is one of the most widely used cameras.It is able to cope with the body size measurement requirements in most cases.Three KinectV2 cameras were installed directly above and on the left and right sides, 1.2 m from the channel.When a target cow entered, each camera detected and collected the data synchronously, and the data were then saved to the computer.A field image is shown in Figure 1.

Point Cloud Preprocessing
Following the storage of the 3D cattle body point cloud data, RANSAC [27] and ICP [28] were used to register the data as a complete point cloud.The algorithms are simple, commonly used, and relatively effective registration algorithms.Filtering is used to remove the background point clouds, and part of the background point cloud noise is removed using CloudCompare software 2. 13. alpha.Outlier points are removed through radius filtering.The point cloud preprocessing is shown in Figure 2. The point cloud data are normalized in the model before sampling, and the specific steps are as follows: 1.
Take the average of each row of data in the point cloud to obtain the centroids; 2.
Translate the point cloud so that the centroid is located at the origin; 3.
Calculate the maximum norm of the point cloud data and normalize the data according to the maximum norm, so that the range of the point cloud data is between [−1, 1].

Data Marking
According to the real requirements of cattle body size measurement, the whole point cloud of the cow's body is segmented to facilitate the follow-up body size measurement.Given that the head and tail of the cow play a minimal role in body size measurement in this study, they are excluded from the point cloud.The multiple complete point clouds of the cow are divided into several parts using CloudCompare software.Specifically, the legs and body of the cow are separated into seven distinct parts using CloudCompare, with each part being labeled accordingly.In addition, the cow's legs are subdivided into four parts labeled 0-3, while the body of the cow is subdivided into three parts labeled 4-6, representing the front, middle, and back.

Improved Model 2.4.1. Overall Framework
Previous studies have proposed using the PointNet [29] and PointNet++ [30] methods to process point clouds and make improvements.The PointNet++ model uses the farthest point sampling (FPS) algorithm, which captures rigid deformation well.However, it does not perform well for nonrigid objects such as cattle.Therefore, in this study, an improved dynamic unbalanced octree sampling method is proposed to replace FPS in order to improve cattle segmentation using PointNet++.The specific architecture of the improved model is shown in Figure 3.

1.
The processed cattle point cloud data, including the total number of data, the number of single data, and the data dimensions, are input; 2.
The cow's body point cloud is sampled and grouped based on the dynamic unbalanced octree grouping (DUOS) algorithm, and the maximum point that the number of leaf nodes can accommodate is n, where n 1 is defined as the number of sampling centers; 3.
After sampling and grouping, the local point cloud is processed using PointNet; 4.
The feature vectors are processed using PointNet.
The following inverse distance-weighted interpolation (Formula (1)) is used to calculate the weight according to the reciprocal of the distance; the attribute value of the unknown position is estimated, and the data are obtained.Hence, the characteristics of the point cloud ignored in the downsampling process and the labels of each point in the complete point cloud are obtained.
Seven classification values are obtained after processing.The maximum value is taken as the output result to complete the target cow's point cloud segmentation.The cross-entropy loss function (Formula ( 2)) is used as the loss function for the network.
where y i,k means the true label, K is the number of label values, and p i,k is the probability of y i,k .The algorithm flow chart is shown in Figure 4.

Dynamic Unbalanced Octree Grouping
The proposed algorithm (1) constrains the number of points allowed in a leaf node instead of setting layers and (2) adds density determination to the sampling point selection in each leaf node.
Traditional octree segmentation is based on the number of layers, but cattle point clouds are characteristically dense in the body and sparse in the limbs.If the number of layers is fixed, the point cloud of the legs cannot properly fill the leaf node, which affects the feature weights in subsequent sampling.The DUOS algorithm determines whether to continue layering by controlling the amount of data in each leaf node and then constructs a non-balanced octree that better deals with the density of the point cloud in different regions.
To avoid noise points and extract richer feature points, a near-point dynamic collection system of adjacent points is set up to filter the noise points.The process is mainly divided into the following steps: (1) Select the node center point and take the point closest to the center point.(2) Establish the corresponding weights in each leaf node according to the number of points; then, the number of points from different leaves is dynamically extracted.
(3) Set up the density measurement algorithm.When the number of target points extracted by each leaf remains unchanged, the density in a circle with a certain radius around each extraction point is measured.When the density is less than the threshold value, this point is removed and replaced by the next point until sufficient target points are extracted or all the points are looped.

Cattle Body Size Measurement
The entire point cloud of the cow is segmented; then, key points based on different parts are located and calculated to eliminate interference from other parts.Figure 5 shows the measurement methods, in which the parameters are abbreviated as follows: body length (BL), withers height (WH), hip height (HH), thoracic circumference (TC), abdominal circumference (AC), and cannon circumference (CC).

Body Height Measurement
To determine the cow's WH and HH, (i) the front body point cloud and front leg point cloud and (ii) the back side point cloud and hind leg point cloud are used, respectively.The yellow areas are local extreme values selected from the upper part of the point cloud of the hind legs.Then, the midpoints p 0 and p 1 of the yellow areas and the midpoint p c of the two points are calculated.The plane parallel to the Y-axis is determined by p c .A body slice A is obtained, and the point with the maximum z value in A is taken as the HH key point p hip .The vertical distance from p hip to the ground is the cow's HH.

Circumference Measurement
The two front legs and the front body are used to determine TC.Then, p 2 and p 3 of the left and right front legs, respectively, are selected as the key points for measurement.The plane parallel to the Y-axis is determined by p 2 and p 3 .A body slice B is obtained.The alpha shape is used to extract the measurements.The circumference comprises a point set E = {e 1 , e 2 , . . . ,e n t }, (e i = (xe i , ye i , ze i ), i = 1, 2, . . ., n t ), and the P thoracic of the tested cow is expressed as follows (Formula (3)); the following calculation is similar.
The mid-body area is used to determine AC.The smallest point p 4 of the Z-axis in the middle body is selected, and a plane is constructed from this point.The plane is extended along the Y-axis to obtain the body point cloud slice C, which forms the outline of AC.Considering the environment at the time of the shooting, one side of the body was shielded by the fence, resulting in incomplete point cloud data.Hence, a repair algorithm is proposed in this study.The proposed algorithm can reduce the calculation error caused by the absence of a unilateral point cloud.(1) The binary norm between all the contour key points α x , α y , β x , β y is calculated, and all the points between the farthest neighboring points are extracted to form set A. (2) The maximum point of the Y-axis is taken as the origin, and the axis of symmetry is parallel to the Y-axis.Moreover, set B is obtained by symmetrizing set A. (3) The distance to α x is calculated by taking the minimum value of the Y-axis in set B as the endpoint.Then, the points in set B are shifted to α by the arithmetic value, resulting in a repaired point cloud.

Cannon Circumference Measurement
CC is measured in the smallest dimension of the front leg of the cow's body by extracting the boundary point in the contour of the leg point cloud.The two points with the closest X-axis distance are extracted, and the leg point cloud is sliced to form the outline of the CC.The linear interpolation algorithm is applied to find the point on the other side of the base side.

Body Length Measurement
The front and back of the body were used to determine BL.Moreover, the point cloud density algorithm proposed in this study to extract key points was used twice to extract the low-density regions and unwanted points at the edge of the point cloud.The threshold of the density was determined based on the location of the collected cattle point cloud data.After extraction, K-means clustering was conducted to cluster the shoulder-end cloud and the ischiatic-end cloud.Finally, two parts of point clouds D and E were obtained.The point p 5 with the smallest x value in D and the point p 6 in E were extracted as the key points, and the distance between the two points was the BL.

Experimental Environment
In this study, a self-built dataset was used as the training and test data for the experiment.A total of 137 cattle of different breeds were collected in the pasture, and 150-200 frames of point cloud data were collected on each side of each cow with different body positions.The point cloud data were processed using translation, rotation, etc., for data augmentation.The dataset was constructed after selection.The data were divided into the training set, validation set, and test set in a ratio of 8:1:1.All training and testing were conducted using Windows 10 and A6000 devices.The programming software was Pycharm 2022.1.2,and the environment was Python 3.9.

Evaluation Indicators of Segmentation Results
Overall accuracy (OA) and mean intersection (mIoU) are used to evaluate performance.OA is the proportion of correctly segmented points relative to the total number of points (Formula (4)): The mean intersection (mIoU) is the ratio of the intersection size to the union size between the predicted and ground truth results, as follows (Formula ( 5)): In Formulas ( 4) and ( 5), k + 1 is the number of classes.p ii represents the amount correctly predicted; p ij and p ji represent the number of false negatives and false positives, respectively.

Cattle Body Point Cloud Segmentation Results
The proposed FPS [30], octree-PointNet++ [21], and DUOS were trained to compare the results.A comparison between the training results is shown in Figure 6.The proposed model achieved higher accuracy and mIoU in the training and testing sets than the other models.The model had good fitting ability and generalization.DUOS could provide more accurate segmentation results; it was better at performing the cattle body segmentation task, and it had the ability to meet the requirements of main point location in body size measurement.This is necessary for our application of cattle body segmentation, which can effectively improve the accuracy of subsequent body size calculations.The successful and unsuccessful segmentation results are displayed in Figure 7a-c.The segmentation results of the standard positions and the nonstandard positions of body bending and bowing are shown in (a) and (b), indicating that the model still maintains stability when applied to different positions.In a small number of the segmentation results, jagged edges or slight offsets appeared at the junction of the parts of the body, as shown in Figure 7c; this was due to registration errors and manual segmentation errors.Fortunately, these issues had little impact on the key point extraction.Given that this study aims to be applicable to cattle farms, it is essential to automatically segment the preprocessed cattle after field collection to achieve automatic body size measurement in animal husbandry.Figure 7d shows that the model can also complete the segmentation task well for unsegmented individuals, which has great advantages for practical applications.Furthermore, the model can accurately segment cattle data collected in the pasture.Figure 8 shows the comparison results between different models, and it is clear that DUOS has higher segmentation accuracy and smoothness.

Body Measurement Results
The cattle in the standard position were chosen for manual body size calculation.We measured the real body size data of cattle in the same environment.Figure 9 shows that the same person measured the same body size parameters.To evaluate the quality of the measurement algorithm, manual measurement parameters were used as benchmarks.A comparison of our results with the two conventional algorithms is shown in Table 1, where RE represents the relative error between each parameter and the true value.Each parameter is compared to two traditional methods based on the overall point cloud, expressed as traditional first and traditional second.The purpose of the linear measurements is to locate the extreme and curvature key points under the whole point cloud.Circumference measurements are circumference calculations that locate extreme points to fit the surface and slicing algorithm under the whole point cloud [18, 25,31].The values in bold in the table indicate the results that are closer to the manual measurement results.The values in bold indicate the results that are closer to the manual measurement results.
The average BL measurement error was 2.52%.The error in the result was affected by the shielding of the vertical fence.The error values of the height were lower because the point cloud of the back side was less occluded, and the calculation was easier.The segmented method could locate the key points more accurately, regardless of whether the parts were considered individually or jointly.The accuracy of the three body measurement parameters improved slightly, with average values of 2.12%, 2.26%, and 2.78%.The AC positioning was more accurate because the segmented part could find the key points of the abdomen more accurately, and the point cloud repair could effectively improve the calculation accuracy.The precision error of the CC was higher than that of the other parameters.As it is a new CC measurement method, there is still room for further research.The relative error of the measurement result depended on the needs of the ranch, but it did not exceed 5%.The results are acceptable.In general, the relative error of most of the cattle body size parameters measured using this method is closer to the true value than those measured using the whole point cloud and traditional key point measurement algorithms.

Discussion
In the cattle segmentation experiment, compared with the traditional model, the proposed method is more accurate in terms of the mIoU parameters.The proposed model is robust in terms of adaptability to point cloud shape and noise processing.Thus, it was effectively applied to segmented cattle bodies.The model accurately divided the cow's body into seven parts, which was very helpful for the subsequent experiments conducted to locate the key points of each part and measure the body size.
Regarding BL and CC, extracting the whole point cloud will yield many redundant points, affecting the subsequent clustering.The partitioned body part point cloud can completely eliminate the point cloud of the excess part, making it easier to locate the target area.When the maximum body is extracted directly, it will cause a significant deviation.Because of the different postures that affect the result, the distribution of the morphological features in the point cloud data will change.In contrast, after segmentation, the key points can be extracted according to the density value.The BL measurement can be accurately obtained by extracting the area of a certain density at the front of the shoulder and hip, which is less affected by the nonstandard stance of the cow.With the use of the proposed new measurement method, the combination of segmentation algorithms can make the calculation results more accurate.Hence, a method measuring the narrowest point is proposed; the method can be used to accurately locate the key point and measure the circumference, and the contour point extraction algorithm can effectively reduce the calculation time without affecting the calculation accuracy.The segmented data of the front leg can be directly selected without considering the impact of the hind leg.Regarding AC, when the cattle are in a nonstandard position, the body shows a C shape at the top of the viewing angle, affecting the positioning accuracy.Instead, our method requires only a slice of the abdominal area and does not need to consider the other parts.Regarding body height, the midpoint of the two front legs can be used to avoid the key point deviation problem caused by the legs being in a nonstandard position.Thus, this method is different from the methods based on the whole point cloud, which are used to directly find the extreme curvature value of the back side.

Conclusions
To solve the problem of the inaccurate positioning of key points in the automatic measurement of cattle body sizes based on the whole point cloud data, a measurement method based on the segmentation results of the cattle body point cloud is proposed.Compared with other traditional algorithms, the proposed DUOS algorithm improved the sampling and grouping methods.The proposed method can provide better results in the cattle point cloud data: 92.87% in OA and 85.91% in mIoU.Compared to octree-PointNet++ and PointNet++, the model improved the results by 0.53% and 1.21%, respectively.Moreover, the proposed method can automate the body size measurement of parts using body size segmentation.The algorithm has higher accuracy and practicability than other methods based on the whole point cloud.Specifically, secondary local density detection and clustering algorithms are used for BL.For TC and AC, the key points are collected according to the segmented point cloud, from which the point cloud slice is extracted.The key point compensation algorithm is used to deal with unilateral point cloud voids caused by the AC barrier.For CC, a new method for measuring the minimum distance of the corresponding points is proposed to find the thinnest part.The experimental results of the cattle body size measurements show that, compared with the whole point cloud measurement method, the proposed method based on point cloud segmentation is more consistent with the actual measurement results.The study had some limitations.Computational correction methods were used to reduce the measurement errors, but the errors still exist.The data sample size is small.We will try to address these issues in future studies.Therefore, the proposed DUOS-PointNet++ model can better complete the cattle body size segmentation task.The research can be applied to body size measurement, and it can also be extended to weight estimation or to scoring the body condition of individual parts.Additionally, it can be applied to other medium-and large-sized livestock; thus, it has good prospects and applicability in the development of intelligent animal husbandry.

Figure 3 .
Figure 3. Specific architecture of improved PointNet++ segmentation network based on DUOS.

Figure 5 .
Figure 5. Schematic diagram of body size measurement.

Figure 6 .
Figure 6.Comparison of the results of training sets and test sets: (a) Acc; (b) mIoU; (c) loss.

Figure 9 .
Figure 9. Manual measurement of cattle body size parameters.

Table 1 .
Comparison between the proposed method and traditional measurement methods.