Abstract
The body size parameter of cattle is an important index reflecting the growth and development and health condition of cattle. The traditional manual contact measurement is not only a large workload and difficult to measure, but also prone to problems such as affecting the normal life habits of cattle. In this paper, we address this problem by proposing a contactless body size measurement method for cattle based on machine vision. Firstly, the cattle is confined to a fixed space using a position-limiting device, and images of the body of the cattle are taken from three directions: top, left, and right, using multiple cameras. Secondly, the image is segmented using a fuzzy clustering algorithm based on neighborhood adaptive local spatial information improvement, and the image is processed to extract the contour images of the top view and side view. The key points of body measurements were extracted using interval division and curvature calculation for the side view images, and the key point information was extracted using skeleton extraction and pruning for the top view images, which realized the measurements of body height(BH), rump height(RH), body slanting length(BSL), and abdominal circumference(AC) parameters of the cattle. The correlation between body size and weight data obtained by contactless methods was investigated and the modeled using one-factor linear regression, one-factor nonlinear regression, multivariate stepwise regression, RBF network fitting, BP neural network fitting, support vector machine, and particle swarm optimization-based support vector machine methods, respectively. Information on body size parameters was collected from 137 cattles, and the results showed that the maximum errors between the measured and actual values of BH, RH, BSL and AC were 5.0%, 4.4%, 3.6%, and 5.5%, respectively. Correlation of BH, RH, BSL and AC with weight obtained by non-contact methods was > 0.75. The BH parameter can be selected in the single-factor growth monitoring. The multi-body scale can reflect the growth status of cattle more comprehensively, in which RH, BSL and AC are important detection parameter; the multi-factor nonlinear model can reflect the growth characteristics of cattle more comprehensively. The contactless measurement method proposed in the paper can effectively improve the work efficiency and reduce the stress reaction of cattle, which is a long-term and effective monitoring method, and is of great significance in promoting accurate and welfare cattle rearing.
Keywords
Introduction
As the main production area of the beef cattle industry in China, with the implementation of the “grazing ban, grazing rest, and rotational grazing” policy in recent years, the development of shed cattle breeding using rich agricultural by-product resources such as straw, and the transition from quantity-based breeding to quality-based breeding has become a basic strategy for the sustainable development of the livestock industry in Inner Mongolia and the surrounding areas [1]. In the process of cattle breeding production, continuous monitoring of their body size parameters can effectively reflect the growth status of cattle, which is an effective means to reflect the health of cattle in the breeding process and is a powerful tool to ensure animal welfare.
The traditional method of body size measurement is mainly by manual contact measurement using tools such as measuring sticks, circular touch-meters, and soft rulers [2]. This method is time-consuming and laborious and requires a high level of posture of the cattle. The non-contact body measurements method, on the one hand, can achieve the monitoring of the body condition of cattle and select and screen breeding cattle in good health, on the other hand, can improve the measurement efficiency and save a lot of labor costs and time costs compared with manual measurements. At the same time, the risk of disease in the herd caused by crowd entry is greatlyreduced.
In recent years, with the improvement of information technology and precision farming, the acquisition of livestock body size data is developing toward non-contact, high precision and high automation, and there are successful cases at home and abroad. For example, Zhang et al. proposed a sheep body size measurement method based on visual image analysis. Based on computer-aided visual image capture, they measured the body height, rump height, body length, chest depth, chest width, and rump width body size parameters of 27 sheep in different postures, and established a body weight prediction model based on these parameters [3]. Ozkaya et al. predicted body weight and estimated body measurements in Limousin cattle using digital image analysis [4]. Li et al. used three-dimensional computer vision to extract surface point cloud data of pigs, extracted body size parameters in the point cloud data, and used the method of least squares regression analysis to establish weight prediction models [5]. Huang et al. proposed a fast point feature histogram to automatically obtain the three-dimensional model data of cattle, using light detection and ranging sensors to obtain the original point data sequence of live cattle after K-means clustering extraction and segmentation by the random sample Consensus algorithm to obtain the shoulder height, chest depth, dorsal height, body length, and loin height body size parameters [6]. Shi et al. implemented contactless measurement of pig body measurements using binocular vision and the LabVIEW development platform [7, 8].
In previous studies, there have been some research on cattle body size measurement based on vision technology, but the automation level is low and the detection parameters are limited. How to obtain more body size parameters, classify cattle and automatically identify measurement points on contours by non-contact, high precision and high automation measurements becomes a key issue.
Based on the research foundation mentioned above, this paper proposes a machine vision-based method for cattle body size measurement and weight prediction, and the main work is as follows. Three CCD camera was used to acquire the RGB image information of the bovine body, and a fuzzy C-mean clustering algorithm based on improved neighborhood adaptive information was used to acquire the foreground image of the bovine body. For the lateral view image of the bovine body, the contour is extracted from the foreground image using the Canny edge detection algorithm, the contour is divided into intervals and the interval contour is fitted, and the key measurement points are found using the curvature maximum method. For the top view image, we use skeleton extraction and pruning to extract key point information. The correlation between body size and body mass data obtained by contactless methods was investigated and the relationship between body size and body mass was modeled using one-factor linear regression, one-factor nonlinear regression, multivariate stepwise regression, RBF network fitting, BP neural network fitting, support vector machine(SVM), and particle swarm optimization-based support vector machine(PSO-SVM) methods, respectively.
Material and methods
Measuring principle of cattle size
Measurements of bovine body size are used to describe the assessment of the appearance of cattle in the spatial dimension, and research has focused on their growth and developmental characteristics, the correlation between body size and growth, and the genetic expression of individual body size parameters. The parameters of body measurements in this paper are body height, cross section height and body slant length. Body height(BH) is the vertical height from the point of the cattle’s jerkin to the ground, Rump height(RH) is the vertical height from the point of the posterior margin of the sit bones to the ground, and body slant length(BSL) is the straight line distance from the point of the anterior margin of the sternum to the point of the posterior margin of the sit bones. Abdominal circumference(AC) refers to the circumference of the abdomen [9, 10]. The body size measurement illustration is shown in Fig. 1 and cattle body size measurement regulations is shown in Table 1.

Body size measurement illustration. 1. Body height(BH); 2. Body slant length(BSL); 3. Rump height(RH); 4. Abdominal circumference(AC); 5. Ground reference line(GRL).
Cattle body size measurement regulations
The experiments were carried out in the Inner Mongolia Autonomous Region Clothing Agriculture and Animal Husbandry Ranch, the location of the ranch is located in Hulustai Gacha, Wengniuote Banner, Chifeng City, Inner Mongolia. The experimental animals were 137 randomly selected Simmental cattle.
Since cattles are highly gregarious animals that usually move together, this paper uses a structured device that restricts the space in which the cattles can move to measure the body size parameters of the cattles, restricts the cattles to a certain space, and then utilizes the CCD camera pre-installed on the device to capture images of the cattles in the upward, leftward, and rightward directions under the condition of natural light, as shown in Fig. 2.

Camera layout and location diagram. 1. Left side camera; 2. Left camera optical axis; 3. Right side camera; 4. Right camera optical axis; 5. Top Camera; 6. Top camera light axis.
The enclosed aisle was 1.2 m wide and 3.6 m long, with a switchable gate at the mouth of the aisle to hold the cattle in place, and a weighing scale on the ground to measure the weight of the cattle, the site plan is shown in Fig. 3.

Schematic diagram of the site.
The captured image of the cattle is shown in Fig. 4.

Cattle body image. (a) side view. (b) top view.
Image preprocessing
Since the image is acquired under natural lighting conditions, the external lighting changes are not controllable, and the acquisition process, affected by lighting, will cause the image to be bright and dark, and these phenomena have a higher impact on image segmentation than the impact of the differences between the body coat colors of different cattles on the segmentation. In order to improve the adaptability of the image to the subsequent algorithms under different lighting conditions, light compensation is done on the image first. The preprocessing results are shown in the Fig. 5.

Preprocessing results graph. (a) Original image. (b) Preprocessed image. (c) original image. (d) Preprocessed image.
Image segmentation is a key step from image processing to image analysis and cluster analysis is based on similarity for statistical analysis and has uses in discovering internal structure, natural division of data and data compression. It can be used to extract regions of interest in an image. Fuzzy C-means algorithm (FCM) is one of the commonly used unsupervised clustering algorithms and is widely used for image segmentation. Considering the problem of complex background and too much noise in the dataset, the traditional FCM algorithm can not merge the local information space well, which leads to poor classification results, this paper uses an FCM algorithm based on adaptive neighborhood information improvement, when the noise in the image is high, the neighboring pixels of each pixel may also contain abnormal features. A weighted fusion strategy of nonlocal and local information is used to set the adaptive weighting factor of spatial information that can be updated automatically, and a regular term is introduced in the image segmentation process to produce high-quality sub-segmentation results [11–19]. The objective function and constraints are as follows.
Where, i is the color level, i ∈ [1,q]; q is the number of regions of the superpixel image, q ∈ N+; S i is the number of pixels in the ith R i ; x p is the Color pixel information within the ith region obtained by superpixel segmentation; β is the regular term coefficient;α k is the spatial weighting factor; w k is the non-local information of the pixel. Compared with the objective function of the old FCM, the new objective function introduces neighborhood information and adaptive information, and the number of color classes is equal to the number of regions in the superpixel image since each color pixel in the original image is used instead of the average of the color pixels in the corresponding region of the superpixel image, which greatly reduces the computational complexity. Using Lagrangian operators, the above problem is transformed into an unconstrained optimization problem with minimized objective function as follows:
Where, λ is the Lagrange multiplier; u ki is the affiliation matrix; v k is the clustering center, by calculating the partial differential equation of the objective function with u ki and v k equal to 0, we get:
Solving for Equations (5) and (6) yields:
According to Equations (1) to (8), the flowchart of the algorithm is shown in Fig. 6.

Algorithm flow chart.
In the cattle foreground image segmentation experiment, the parameters of FCM algorithm are set as follows: the clustering center cluster is 3, and the balance parameter m is 2. After obtaining the segmented image, the similar clusters are merged, and the complete cattle foreground image is obtained after eliminating the small concatenated domains, image smoothing, and occlusion repairing and other image post-processing algorithms, and the results are shown in Fig. 7.

Foreground extraction results. (a) Side view. (b) Prospect extraction results. (c) Top view. (d) Prospect extraction results.
The three parameters of body height, body slant length and hump height are relatively easy to calculate and only require the measurement of the length of a straight line between two critical points, with reference to the formula shown by calculating Equation (9):
Whereas the calculation of the abdominal circumference parameter is relatively more complex, we can approximate the circumference of the abdomen as the circumference of an ellipse. In the top view we measure the width of the abdomen and use this length as the short axis of the ellipse, and in the side view we measure the distance between the bottom of the abdomen and the highest point of the back in a straight line and use this distance as the long axis of the ellipse. Knowing the lengths of the long and short axes of the abdominal circumference ellipse, we can measure the length of the abdominal circumference by calculating Equation (10):
Interval dividing
The Canny operator is used to extract the cattle body contour curve [20], in order to facilitate the extraction of each body size measurement point, we firstly standardize the cattle body orientation, that is, the head left and tail right orientation is the positive direction, the cattle body contour map is shown in Fig. 8.

Outline drawing of a cattle’s body.
Based on the characterization in Table 1, it can be seen that it is necessary to identify the location of the outer front and rear feet of the cattle from the image for locating the ground reference line. Withers, The chest base measuring points, front foot in the left half of the image. The posterior end of the sciatic tuberosity, back foot in the right half ofthe image.
The side view of the cattle body towards the standardization was divided by the interval of the distribution of measurement points, as shown in Fig. 9.

Illustration of the division of intervals.
where (x1, y1) are the coordinates of the upper left corner of the foreground image region. (x2, y2) are the coordinates of the lower right corner of the foreground image region. The image is divided into the left and right halves using a center vertical line with horizontal coordinates of (x1 + (x2 - x1)/2). Search for the point with the largest vertical coordinate in the left half of the image and the right half of the image, respectively, which is the outer left footer, denoted as Foot_left and the outer right footer, denoted as Foot_right. Take x3 as the horizontal coordinate of the plumb line in the left half of the image, take the region from x1 to x3 horizontal coordinate as zone 1, find the highest convex point in zone 1, this point is the highest point of the head, denoted as Head. Search between Head and Foot_left (zone 2) for the first point that corresponds to the first 0 point for each point on the horizontal coordinate axis and form an array, which is the Withers measurement interval. Search between x1 and Foot_left (zone 3) for the last 0 point corresponding to each point on the horizontal coordinate axis, forming the chest base measuring points measuring point interval. The first zero-value point corresponding to each point on the horizontal coordinate axis was searched between the centerline and x2 (zone 4), constituting the point of measurement of the posterior margin of the sciatic end. Also, look for the first wave crest on this fitted curve as the highest measurement point on the back. In the zone 4, the same method described above was used to make a fitting curve to find the first trough point as the lowest measurement point of theabdomen.
Least squares fitting is a commonly used curve fitting method [21], which is to minimize the sum of squares of the errors, thus obtaining a system of linear equations, and then solving the system of linear equations, i.e., the curve to be fitted can be obtained. The fitted curves for each interval are shown in Fig. 10.

Fitting curve images. A. The fitted curve for zone 2. b. The fitted curve for zone 3. c. The fitted curve for zone 4. d. Abdominal curve fitting.
A commonly used method of extracting contour feature points is to use a set of neighboring contour points to calculate the curvature of each point on the contour line, which has the advantage of being less computationally intensive [23]. On the contour line of the upper left half of the bovine body image, Withers is represented in the image as a bump between the concave point of the neck and the concave point of the back, and is represented as a crest between two troughs on the fitting curve, so Withers can be detected by the crest and trough detection method. The point of the posterior edge of the end of the sciatic bone and the point of the anterior edge of the sternum are detected by local curvature, in the Euclidean space, the curvature of a straight line is zero, and the curvature of a circular arc is a non-zero constant, using the curvature-maximizing principle to take the rump height measurement point and the anterior edge of the end of the sternum; the curvature of the curved curve is calculated in Equation (11),
After determining the measurement point of the body size, the straight line formed by the front foot point and the rear foot point is the reference, and the detection results of each body size parameter are shown in Fig. 11.

Measurement point extraction results.
The top view image of the cattle is a non-rigid symmetric body, and the skeleton line of the cattle body can be extracted using Matlab’s bwmorph function, and the centerline of the cattle body can be extracted by skeleton pruning and curve fitting, as shown in Fig. 12.

The centerline of the cattle’s body.
Make a perpendicular line in the direction of the tangent to the centerline and find the line where the intersection of the external contour of the cattle’s body with the perpendicular line is the largest, and the length of this line is the length of the short axis of the abdomen,as shown in Fig. 13.

Abdominal circumference short axis.
In the body size calculation, it is necessary to calculate the pixel reference value of a fixed size reference in the image space to calculate the size of the body size parameters in practice, using the following method: after the camera and cattle position are determined, a 100 cm size is placed in the standing position of the cattle as a reference before the body size measurement, and the conversion is performed according to Equation (11):
We compared the data measured by the method of extracting parameters through image analysis with the data obtained from actual manual measurements. It was shown that the maximum error between the body height, rump height, body slant length and abdominal circumference measurements obtained by this method and the actual values were 5.0%, 4.4%, 3.6% and 5.5%, respectively, and the measurement data are shown in Table 2.
Measurement of bovine body size parameters
The error is calculated as shown in Equation (12),
Correlation analysis between body weight and parameters
Statistical information on body size parameters and body weight data of 137 Simmental cattles is shown in Table 3.
Statistical result of cattle body parameters and weight got by non-contact method
Statistical result of cattle body parameters and weight got by non-contact method
Before modeling weight prognosis, a correlation analysis is needed, and the confidence ellipses for weight and each body size metric are shown in Fig. 14.

Confidence ellipses for body weight and each body size parameter. a. Confidence ellipses between weight and WH(r = 0.78). b. Confidence ellipses between weight and RH(r = 0.75). c. Confidence ellipses between weight and BSL(r = 0.76). d. Confidence ellipses between weight and AC(r = 0.82).
The correlation between the variables was measured by the ratio of the long and short axes of the confidence ellipse, and the graphs show that each body size parameter has a strong correlation with body weight.
In the beef cattle breeding chain, production performance will directly affect the economic efficiency of beef cattle breeding, and live weight of beef cattle is a widely accepted and recognized index. In this paper, 137 different beef cattles were selected as experimental materials and weighed in the morning before grazing and feeding to minimize the effect of feeding. The recording apparatus was measured using a precision balance with an accuracy of 0.1 kg. In this paper, several methods were used to predict body weight, including univariate linear regression, univariate nonlinear regression, step-by-step multivariate linear regression (stepvise-MLR) [22], radial basis function network, BP neural network, and support vector machines (SVM), as well as particle swarm optimization-based support vector machines (PSO-SVM) [23, 24]. 100 of the 137 sets of data were used as the training set and the remaining 37 sets were used as the test set, and the correlation coefficients and root-mean-square errors for each of the prediction models and the predicted values with the actual measured values. As shown in Table 4.
Cattle weight prediction modeling
Cattle weight prediction modeling
In the Table 4, x1 is Body height, x2 is Rump height, x3 is Body slant length, x4 is Abdominal circumference. RMSE is Root Mean Square Error, which is the square root of the ratio of the square of the predicted value to the true value to the number of observations n, measuring the deviation between the predicted value and the true value. R is Correlation coefficient, which is a measure that examines the degree of linear correlation between variables, with a range of values of [0,1], and the larger the value, the better the prediction. The larger the value, the better the prediction effect. The expressions are shown in (13) and (14).
The test dataset was used to test the accuracy of each model and the results are shown in Table 5.
Precision test of prediction models of cattle weight
Precision test of prediction models of cattle weight
From Table 5, it can be concluded that the body slant length based model has less error in the single-factor weight prediction model, and the particle swarm optimization-based support vector machine performs better in the multifactor weight prediction model, and is also the model with the best results among the multiple prediction methods.
From the results, the measurement accuracy is higher and the model prediction ability is stronger compared to the measurements obtained by Lee et al. [25]. using a deep neural network with residual connections by extracting weight-related features based on two-dimensional image information and Gebreyesus G et al. [26]. using a three-dimensional image method. However, there are still some problems to be solved: Image acquisition has high requirements for the scene, and the study of more relaxed image preprocessing methods can reduce the requirements for the environment and help increase the practicality of the methods. In this paper, we measured four parameters, namely, body height, rump height, body slant length and abdominal circumference, and the number of parameters is small, so the method is more difficult to estimate the parameters of the circumference category, or it can be solved by adopting three-dimensional stereoscopic imaging technology and increasing the depth of field information of the image.
Conclusions
In this paper, we propose a contactless measurement method based on image analysis to obtain the body size parameters of cattle, which can avoid the direct contact between human and cattle and reduce the chance of human and animal diseases. We measured four body size parameters: body height, rump height, body slant length, and abdominal circumference, and the accuracy of the body size parameters obtained using this method was high in terms of measurement accuracy, with a maximum relative error of no more than 5.5%.
This paper also analyzes the correlation between body size data obtained using images and body weight, demonstrating the feasibility of an image analysis-based method for cattle growth detection. A nonlinear model of body height, rump height, body slant length, and abdominal circumference to body weight accurately predicted cattle growth, and a particle swarm-based support vector machine model yielded a correlation coefficient of up to 0.9825 with an error of about 5%. Experiments have demonstrated that the method can be effectively used in cattle selection efforts.
Declaration of Competing Interest
The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.
Footnotes
Acknowledgments
This research was supported by Program for Young Talents of Science and Technology in Universities of Inner Mongolia Autonomous Region under Grant NJYT23063, and in part by the National Natural Science Foundation of China under Grant 61966026. The authors appreciate the funding organization for their financial supports.
