A method for estimating the standing body size of walking sheep based on gait quantification
By constructing a gait quantification-based method and utilizing depth cameras and key point detection technology, the accuracy and efficiency issues of body size measurement in sheep's natural walking state were solved, achieving efficient and accurate body size measurement to meet actual breeding needs.
Patent Information
- Application Number
- CN202511004367.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-21
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2045-07-21
AI Technical Summary
Existing technologies make it difficult to accurately measure the body size of sheep while they are walking naturally, and existing methods suffer from insufficient measurement accuracy, low efficiency, and difficulty in adapting to actual breeding needs.
By constructing a gait quantization-based method, we used a depth camera to collect videos of sheep walking, detected key points, built an error prediction model, predicted the standing body size based on the gait quantization angle, used the YOLOv1-pose model and edge detection algorithm to correct the key points, and combined the Dijkstra algorithm to calculate the body size parameters.
It enables efficient and accurate measurement of sheep body size while they are walking naturally, reducing the difficulty of measurement, improving measurement efficiency and accuracy, and meeting the needs of large-scale breeding production.
Smart Images

Figure CN120510207B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent measurement and machine vision technology in animal husbandry, specifically a method for estimating the standing body size of walking sheep based on gait quantification. Background Technology
[0002] In the field of livestock farming, traditional methods for measuring sheep body size have many shortcomings. Manually measuring sheep body size requires manually restraining them to maintain a standing posture, and then using specialized measuring tools such as measuring rods, tape measures, and rulers. This method is labor-intensive, inefficient, and its accuracy is easily affected by the subjective factors of the measuring personnel. Furthermore, it can easily cause stress reactions in sheep, increasing the risk of zoonotic diseases.
[0003] While depth camera measurement methods can obtain more accurate distance information, most studies require animals to remain stationary or to collect data from fixed locations. For example, patent publication number CN 117576733 A discloses a computer vision-based method for automatically detecting the ideal standing posture of sheep, including: S1, collecting sheep body image data in a sheep farm and preprocessing the data; S2, extracting key points of the sheep skeleton using a keypoint detection deep learning model; S3, defining the criteria for judging the ideal standing posture of sheep according to sheep body size measurement requirements; S4, designing 21 sets of image feature vectors for judging the ideal standing posture of sheep based on the criteria; and S5, training a classifier to identify sheep in an ideal standing posture. Applying deep learning technology to sheep ideal standing posture detection achieves efficient, accurate, and automated automatic detection of sheep's ideal standing posture, helping the livestock industry quickly and accurately screen sheep images in ideal standing postures, and providing technical support for high-precision automatic measurement of sheep body size based on computer vision.
[0004] The methods based on two-dimensional images in the aforementioned patents and existing technologies calculate body size data based on key point detection results. Although these methods overcome the shortcomings of manual methods, sheep are three-dimensional creatures and cannot be strictly coplanar with the calibration board in real-world scenarios. In actual situations, due to the uncontrollability of sheep's movement and posture, the detected key point positions have varying degrees of deviation, resulting in unavoidable systematic errors.
[0005] Secondly, due to the influence of shooting angle and the dynamic posture of sheep, it is extremely challenging to make the camera direction perpendicular to the side of the sheep, which can easily introduce new errors. Furthermore, the two-dimensional image method is difficult to implement in actual breeding scenarios and is inefficient. The processing of multi-view point cloud data requires a large amount of computation, which is not conducive to field deployment and real-time requirements. At the same time, the number of animals participating in the experiment is small, resulting in insufficient model generalization ability.
[0006] Furthermore, most methods require livestock to remain stationary in a position perpendicular to the camera's viewfinder to achieve high accuracy, but this strict posture requirement is very difficult to achieve in practical applications; especially the requirement of being perpendicular to the camera, which is challenging even with manual assistance. In actual production, managers expect a body measurement system with the following functionality: after sheep naturally walk through a certain area in a passageway, their walking body size is detected by a side camera, and their standing body size is deduced from their walking posture. Current technology lacks a method to deduce the standing body size from the walking body size of sheep.
[0007] Therefore, this invention provides a method for estimating the body size of walking sheep based on gait quantification. When a sheep walks naturally through a certain area, its body size parameters in the walking state can be calculated, and its body size parameters when it is standing still can be estimated. This makes up for the problems of existing technologies that lack estimation of the body size of walking sheep when they are standing still, and the insufficient accuracy of direct estimation, which is difficult to meet the actual breeding needs. Summary of the Invention
[0008] The purpose of this invention is to overcome the defects and shortcomings of the existing technology and provide a method for estimating the standing body size of walking sheep based on gait quantification, thus solving various problems existing in the prior art.
[0009] To achieve the above objectives, the present invention provides the following technical solution:
[0010] A method for estimating the standing body size of walking sheep based on gait quantification, the method comprising the following steps:
[0011] S1, Data Acquisition
[0012] Walking paths were constructed in the sheep farm, and depth cameras were used to capture videos of sheep walking naturally from the side of the paths. The video data was then preprocessed to obtain two-dimensional planar images and three-dimensional depth images.
[0013] S2, Key Point Detection
[0014] Two types of body keypoints, namely the torso and legs, are detected in planar images using a keypoint detection model.
[0015] S3, Calculation of walking body size parameters
[0016] By registering the planar image and the depth image, the key points detected in step S2 are transformed into the depth image, and the three-dimensional coordinates of the key points are used to calculate various body size parameters of the sheep.
[0017] S4. Construction of an error prediction model based on gait quantization
[0018] The specific steps for constructing a standing body size parameter extrapolation model based on gait quantification and walking body size parameters are as follows:
[0019] a. Define the following four gait quantification angles: front leg angle, front knee angle, rear leg angle, and rear knee angle;
[0020] b. Collect videos of sheep of typical body size walking naturally; in each frame of the sheep's natural walking image, calculate the above four walking angles in planar angle (2D) and spatial angle (3D), and calculate its walking body size using the S3-step method; regard the body size measured manually when the sheep is standing as the true body size, and define the error between the true body size and the walking body size by dividing the true body size value as the percentage error; form an appropriate number of "walking angle - percentage error" sample sets of sheep of typical body size according to the above method;
[0021] c. Based on the above typical sample sets, a regression model is used to establish the mapping relationship between the quantitative angle of walking posture and the percentage error of various body sizes, forming a percentage error prediction model;
[0022] S5. Derivation of standing scale parameters based on walking scale and gait angle.
[0023] Using the percentage error prediction model in step S4, predict the error between the sheep's walking size and its standing size when walking naturally, and substitute it into the following formula to derive its standing size parameters:
[0024] ;
[0025] Where the parameters are:
[0026] : Calculated standing body size; The walking body size value is calculated based on key points; : Percentage error of the regression model prediction.
[0027] The key points in step S2 are distributed along the contours of the torso and legs, including: P1 at the anterior edge of the scapula, P2 at the middle of the foreleg, P3 at the middle of the foreknee, P4 at the bottom of the forehooves, P5 at the lowest point of the abdomen, P6 at the middle of the hind leg, P7 at the middle of the hindknee, P8 at the bottom of the hindhooves, P9 at the base of the tail, P10 at the highest point of the rump contour, P11 at the lowest point of the back contour, and P12 at the protrusion of the neck. Specifically, multiple key points are selected from the above key points and combined to accurately capture the morphological features and movement information of the torso and legs.
[0028] The various body size parameters of the sheep in step S3 include body length, body height, abdominal depth, abdominal circumference, and hip height.
[0029] The formula for calculating the oblique length of the body is as follows:
[0030] ;
[0031] Among them, the parameters are: : 3D coordinates of key points on the anterior border of the scapula; : The three-dimensional coordinates of key points at the base of the tail;
[0032] The formula for calculating the body height is as follows:
[0033] ;
[0034] Parameter meaning:
[0035] The distance from the key point of the withers to the key point of the foreleg;
[0036] : The distance from the key point of the front leg to the key point of the front knee;
[0037] : The distance from the key point of the foreknee to the key point of the forehoof;
[0038] The formula for calculating the abdominal depth is as follows:
[0039] ;
[0040] parameter:
[0041] : Three-dimensional coordinates of key points in the lower abdomen;
[0042] : Three-dimensional coordinates of key points in the upper abdomen;
[0043] The calculation process for the waist circumference is as follows:
[0044] ①. Identify key points in the upper and lower abdomen: Locate key point P5 in the upper abdomen and key point P11 in the lower abdomen on the depth map;
[0045] ②. Path planning: Use the Dijkstra algorithm to generate the optimal path from P5 to P11 on the depth map, and extract sampling points along the path. ;
[0046] ③. Three-dimensional coordinate transformation: Transform the two-dimensional coordinates of the sampling points. Convert to 3D coordinates ;
[0047] ④. Calculation of total path length:
[0048] ;
[0049] The meanings of each parameter in the formula are as follows:
[0050] for The three-dimensional coordinates of a point for The three-dimensional coordinates of a point;
[0051] ⑤. Ellipse circumference compensation:
[0052] ;
[0053] parameter:
[0054] Elliptic compensation coefficient;
[0055] The formula for calculating hip height is as follows:
[0056] ;
[0057] parameter:
[0058] The height of the key points of the withers;
[0059] The key points of the recommendation section are highly relevant.
[0060] In step S4, the specific definitions of the front leg angle, front knee angle, rear leg angle, and rear knee angle are as follows:
[0061] ①. Front leg angle: The front leg key point and the front knee key point are used. First, determine the front leg key point. Draw an auxiliary line vertically downward from the front leg key point as the origin. Then connect the front leg key point and the front knee key point and calculate the angle between the two line segments as the front leg angle.
[0062] ②. Angle of the front knee: Using the key points of the front leg, the front knee, and the front hoof, with the key point of the front knee as the origin, connect the key points of the front leg and the key points of the front hoof respectively, and calculate the angle between the two line segments.
[0063] ③. The definitions of the hind leg angle and hind knee angle are similar to those of the foreleg angle and fore knee angle described above;
[0064] The specific steps for establishing the "gait angle - percentage error" sample in step S4 are as follows: Based on the definitions of front leg angle, front knee angle, hind leg angle, and hind knee angle, collect quantitative gait angle data of sheep during the walking process; while collecting gait angles, detect key points on the sheep's body, and calculate various types of gait body size based on the detected key points according to the definition of body size; for each type of body size parameter, calculate the percentage error between its predicted value and the actual value measured manually, and the calculation formula is: percentage error = actual value | predicted value − actual value | × 100%; by following the above method, a sample set of "gait angle - percentage error" for a suitable number of sheep with typical body types can be formed.
[0065] Random forest is selected as the regression model, with normalized gait quantification angle data as input features and percentage error data of various body sizes as output targets to construct a regression model between gait quantification angle and percentage error of various body sizes. Then, new gait quantification angle data is input into the trained regression model to obtain the percentage error prediction results of various body sizes.
[0066] To improve the accuracy of sheep body key point detection, the feature key points extracted in step S2 are further corrected using an edge detection algorithm. This process includes the following steps:
[0067] (1) Use the YOLOv11-pose model to detect key points of the sheep target and its body to obtain an initial set of key points;
[0068] (2) The edges of the sheep in the color image are detected using depth and color images to obtain an edge feature map with depth information;
[0069] (3) Correct the key points in the initial key point set according to the edge feature map to obtain the corrected key point set.
[0070] The edge feature detection in step (2) specifically includes the following steps:
[0071] (a) Convert the color image to grayscale to obtain a grayscale image;
[0072] (b) The edges of the sheep in the grayscale image are detected using the Canny operator to obtain a preliminary edge detection result image;
[0073] (c) Generate a mask of the effective depth region using the depth image, set a depth threshold range, mark the pixels in the depth image whose depth values are within the threshold range as the effective depth region, and mark the remaining pixels as the invalid region, thereby obtaining the mask;
[0074] (d) Perform an AND operation between the preliminary edge detection result image from step (b) and the mask output from step (c) to obtain the edge feature map;
[0075] (e) Perform morphological expansion processing on the above edge feature map to make the edges more obvious and complete, and obtain an edge feature map with depth information.
[0076] In step (3), for each key point in the initial key point set, a circular region is determined with a fixed pixel value as the center. Within this circular region, a search is conducted to find the key points that are both located on the edge of the sheep body represented by the edge feature map output in step (2) (e) and within the effective depth region generated in step (c). The initial key points are then corrected based on the search results to obtain the corrected key point set.
[0077] Compared with the prior art, the beneficial effects of the present invention are:
[0078] (1) The present invention does not require sheep to stand still in the vertical camera capture direction. Sheep only need to walk naturally through a certain area to complete the body size measurement. It follows the natural behavior of sheep, greatly reduces the measurement difficulty, improves the measurement efficiency, and avoids stress on sheep. This makes the method highly feasible and practical in actual breeding scenarios, and can better meet the needs of large-scale breeding production, providing breeders with a more convenient and efficient means of body size measurement.
[0079] (2) This invention defines four angle indicators, namely, front leg angle, front knee angle, hind leg angle and hind knee angle, to quantify the standing posture of sheep and constructs a posture-body size error compensation mechanism; by using a regression model to predict body size, the influence of sheep posture changes on body size measurement is effectively reduced; after using mixed walking angles, the average absolute percentage error of various body size parameters is reduced, thus improving the accuracy of body size measurement.
[0080] In summary, this invention addresses the shortcomings of existing technologies and has achieved significant breakthroughs in measurement methods, measurement accuracy, and practical application adaptability. It has remarkable advantages and broad application prospects, and will provide strong technical support for the development of the sheep farming industry. Attached Figure Description
[0081] Figure 1 This is a flowchart of the steps of the present invention;
[0082] Figure 2 This is a schematic diagram of the channel device.
[0083] Figure 3 This is a schematic diagram of the distribution of key points in the sheep image of the present invention;
[0084] Figure 4 This is a schematic diagram showing the distribution of the four walking posture quantification angles of the present invention;
[0085] Figure 5 This is the specific process of Canny edge detection in this invention.
[0086] Figure label:
[0087] 1. Support frame; 2. Walking passage; 3. Wire; 4. Background board; 5. Depth camera. Detailed Implementation
[0088] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0089] See Figures 1-5 ;
[0090] A method for estimating the standing body size of walking sheep based on gait quantification, the method comprising the following steps:
[0091] S1, Data Acquisition
[0092] Walking paths were constructed in the sheep farm, and depth cameras were used to capture video data of sheep walking naturally. The data was then preprocessed. The dedicated walking paths consisted of two parts (such as...). Figure 1 As shown), the first part is the channel device, including a walking channel 2 erected by a support frame 1. One side of the shooting position of the walking channel 2 is a fence composed of horizontal wires 3 set at vertical intervals, and the other side of the shooting position is a background board 4. The second part is the visual perception module, including a depth camera 5 located outside the wire channel and erected by a camera bracket. The depth camera 5 transmits the video data of the sheep walking naturally to the background processing via a USB signal extension cable to obtain and save RGB images and depth maps in bag format. (Since the camera's video recording function automatically saves the video as a bag format file, it cannot be directly used for algorithm processing. Therefore, it is necessary to use the Orbbec official SDK source code to parse the video file, extract the video file according to the shooting frame rate, and match its color image frames and corresponding depth image frames.)
[0093] S2, Key Point Detection and Correction
[0094] Two types of body keypoints, namely the torso and legs, are detected in planar images using a keypoint detection model.
[0095] like Figure 2The locations of the 12 key points are shown in Table 1 below. The names and locations of each key point are as follows:
[0096] Table 1 - Names and Locations of Key Points
[0097]
[0098] When selecting key points, multiple key points are selected from the above key points and combined. This combination can accurately capture the morphological features and motion information of the torso and legs. The specific detection steps are as follows: each video segment is analyzed using the official source code of the depth camera. Color image frames and corresponding depth image frames are extracted from the video according to the shooting frame rate. The color image frames and depth image frames are aligned. Blurry images and images with high repetition are deleted. Images are randomly selected from each video segment and divided into training set, validation set and test set according to the proportion. Then, the images are labeled using an image annotation tool to obtain the target box and key points of each target object.
[0099] Furthermore, to further improve the accuracy of sheep body keypoint detection, the extracted feature keypoints P1-P12 are further corrected using an edge detection-based algorithm, specifically including the following steps:
[0100] (1) Key point detection: The YOLOv11-pose model is used to detect key points of the sheep target and its body to obtain an initial set of key points; the YOLOv11-pose model is trained based on a large-scale sheep body pose dataset and can accurately identify the position of each key point of the sheep body.
[0101] (2) Detection of sheep body edges: The sheep body edges in the color image are detected using depth and color images; the specific steps are as follows:
[0102] (a) Convert the color image to grayscale to reduce the complexity of the data and speed up subsequent processing to obtain a grayscale image;
[0103] (b) The edges of the sheep in the grayscale image are detected using the Canny operator to obtain a preliminary edge detection result image;
[0104] (c) Generate a mask of effective depth region using depth image. Specifically, set a depth threshold range, mark the pixels in the depth image whose depth value is within the threshold range as effective depth region, and mark the remaining pixels as invalid region to obtain mask. This mask is used to filter out regions with actual depth information and provide depth reference for subsequent key point correction.
[0105] (d) Perform an AND operation between the preliminary edge detection result image from step (b) and the mask output from step (c) to obtain an edge feature map, in which each point is on the edge of the sheep’s body and has depth information.
[0106] (e) Perform morphological expansion processing on the above edge feature map to make the edges more obvious and complete, and provide accurate edge information for subsequent key point correction.
[0107] (3) Correction of key points; For each key point detected by the YOLOv11-pose model, a circular region is determined with the key point as the center and NP pixels as the radius (NP is a pre-set fixed pixel value, which can be adjusted appropriately according to the actual image resolution and sheep size). Within this circular region, a search is conducted to find the key points that are both located on the sheep edge represented by the edge feature map output in step (2) (e) and within the effective depth region generated in step (c). The initial key points are corrected according to the search results to obtain the corrected key point set. If there are points that meet the criteria within the search circular area, calculate the Euclidean distance between these points and the original keypoint as the coordinates of the original keypoint. Select the nearest point and update the coordinates of the original keypoint to the coordinates of the nearest point. If there are no points that meet the criteria, check if the original keypoint has a depth value. If it has a depth value, retain the original keypoint. If it does not have a depth value, search for points with depth values in the depth image, centered on the original keypoint, within a circle with a radius of NP pixels. Calculate the Euclidean distance between these points and the original keypoint, select the nearest point, and update the coordinates of the original keypoint to the coordinates of the nearest point.
[0108] The formula for calculating Euclidean distance is:
[0109] ;
[0110] in, Represents the coordinates of the original keypoints. This represents the coordinates of the edge points within the search area that meet the criteria.
[0111] S3, Body Size Parameter Calculation
[0112] Calculate five body dimensions based on the three-dimensional coordinates of the new key point location in step S2: body length, body height, abdominal depth, abdominal circumference, and hip height.
[0113] Based on the formula for calculating the distance to key points:
[0114] ;
[0115] in: Let A be the Euclidean distance from point A to point B. Let A be the three-dimensional coordinates.
[0116] Here are the three-dimensional coordinates of point B;
[0117] Therefore, the formula for calculating the oblique length of the body is as follows:
[0118] ;
[0119] Among them, the parameters are: The three-dimensional coordinates of the key point at the anterior border of the scapula (P1); The three-dimensional coordinates of the key point at the root of P9's tail;
[0120] The formula for calculating the body height is as follows:
[0121] ;
[0122] Parameter meaning:
[0123] : The distance from the key point of the withers to the key point of the foreleg on page 12;
[0124] : The distance from the key point of the front leg to the key point of the front knee in P2;
[0125] : The distance from the key point of the front knee to the key point of the front hoof in P3;
[0126] The distance to key points is calculated using the following formula;
[0127] ;
[0128] in: Let A be the Euclidean distance from point A to point B. Let A be the three-dimensional coordinates.
[0129] Here are the three-dimensional coordinates of point B;
[0130] The formula for calculating the abdominal depth is as follows:
[0131] ;
[0132] parameter:
[0133] The three-dimensional coordinates of key points in the lower abdomen (P5);
[0134] : 3D coordinates of key points in the upper abdomen on page 11;
[0135] The calculation process for the waist circumference is as follows:
[0136] ①. Identify key points in the upper and lower abdomen: Locate key point P5 in the upper abdomen and key point P11 in the lower abdomen on the depth map;
[0137] ②. Path planning: Use the Dijkstra algorithm to generate the optimal path from P5 to P11 on the depth map, and extract sampling points along the path. ;
[0138] ③. Three-dimensional coordinate transformation: Transform the two-dimensional coordinates of the sampling points. Convert to 3D coordinates ;
[0139] ④. Calculation of total path length:
[0140] ;
[0141] The meanings of each parameter in the formula are as follows:
[0142] for The three-dimensional coordinates of a point for The three-dimensional coordinates of a point;
[0143] ⑤. Ellipse circumference compensation:
[0144] ;
[0145] parameter: Elliptic compensation coefficient;
[0146] The formula for calculating hip height is as follows:
[0147] ;
[0148] parameter:
[0149] The height of the withers (P12 is a key point);
[0150] Recommended key point P10 height.
[0151] S4. Construction of an error prediction model based on gait quantization
[0152] The specific steps for constructing a standing body size parameter extrapolation model based on gait quantification and walking body size parameters are as follows:
[0153] a. Define the following four gait quantification angles: front leg angle, front knee angle, rear leg angle, and rear knee angle;
[0154] like Figure 4The following is stated: ①. Front leg angle a: The front leg key point P2 and the front knee key point P3 are used. First, determine the front leg key point P2. Draw an auxiliary line vertically downward with the front leg key point P2 as the origin. Then connect the front leg key point and the front knee key point P3. Calculate the angle between the two line segments as the front leg angle.
[0155] ②. Angle b of the front knee: Using the key points P2 of the front leg, P3 of the front knee, and P4 of the front hoof, with the key point P3 of the front knee as the origin, connect the key points P2 of the front leg and P4 of the front hoof respectively, and calculate the included angle between the two line segments.
[0156] ③. Rear leg angle c: The rear leg key point P6 and the rear knee key point P7 are used. First, determine the rear leg key point P6. Then, draw an auxiliary line vertically downward with the rear leg key point P6 as the origin. Then, connect the rear leg key point and the rear knee key point P7 and calculate the angle between the two line segments as the rear leg angle.
[0157] ④. Rear knee angle d: Using the hind leg key point P6, hind knee key point P7 and hind hoof key point P8, with the hind knee key point P7 as the origin, connect the hind leg key point P6 and the hind hoof key point P8 respectively, and calculate the included angle between the two line segments.
[0158] b. Collect videos of sheep of typical body size walking naturally; in each frame of the sheep's natural walking image, calculate the four gait quantification angles of the sheep in both planar angle (2D) and spatial angle (3D), and calculate its walking body size using the S3-step method; regard the body size measured manually when the sheep is standing as the true body size, and define the error between the true body size and the walking body size by dividing the true body size value as the percentage error; form an appropriate number of "gait angle - percentage error" sample sets of sheep of typical body size according to the above method;
[0159] The specific steps for establishing a "gait angle - percentage error" sample set are as follows: Based on the definitions of front leg angle, front knee angle, hind leg angle, and hind knee angle, collect gait angle data of sheep during the walking process. While collecting gait angles, detect key points of the sheep's body. Based on the detected key points, calculate various types of gait body size according to the definition of body size. For each type of body size parameter, calculate the percentage error between its predicted value and the actual value measured manually. The calculation formula is: percentage error = actual value | predicted value − actual value | × 100%. By following the above method, a sample set of "gait angle - percentage error" for a suitable number of sheep with typical body types can be formed.
[0160] The gait angle data were normalized and mapped to the [0, 1] interval. SIMCA software was used for variable importance analysis to screen key angles affecting different body size errors. The specific steps for screening key angles are as follows:
[0161] (1) Use tables to collect data and error percentages for the four angles, check the completeness of the data, and standardize the data.
[0162] (2) Substitute the data from (1) into the SIMCA software, where the percentage error is set as the dependent variable and the four angle values are set as independent variables. Select the appropriate model according to the analysis purpose to analyze the contribution of the body size. Use methods such as cross-validation to verify the model, evaluate the stability and predictive ability of the model, set the variable projection importance (VIP) threshold, generally set the VIP threshold (usually variables with a VIP value greater than 1 are considered important), and select the angles with a VIP value greater than the threshold as key angles. The variable projection importance relationship between the percentage error of the body size and the plane angle is shown in Table 2 below:
[0163] Table 2 - Relationship between VIP (Percentage of Size Error) and Planar Angle
[0164]
[0165] The relationship between the percentage error in body size and the spatial angle (VIP) is shown in Table 3 below:
[0166] Table 3 - VIP Relationship between Body Size Error Percentage and Spatial Angle
[0167]
[0168] c. Based on the above typical samples, a regression model is used to establish the mapping relationship between gait angle and percentage error of various body sizes, forming a percentage error prediction model; the random forest regression algorithm is selected, with normalized gait angle data as input features and percentage error data of various body sizes as output targets, to construct a regression model between gait angle and percentage error of various body sizes; then, the new gait quantified angle data is input into the trained random forest regression model to obtain the percentage error prediction results of various body sizes;
[0169] By leveraging the powerful nonlinear fitting and feature learning capabilities of the random forest regression model, we can deeply explore the potential correlation between angle and error and establish an accurate angle error prediction model. Subsequently, during actual body size measurement, we can predict the possible errors that may occur at the current measurement angle based on this model, and then perform error compensation prediction on the measurement results to obtain data that is closer to the actual body size.
[0170] S5. Derivation of standing scale parameters based on walking scale and gait quantification angles.
[0171] During the acquisition and processing of body size data, the original measured body size values often contain a certain degree of error due to the combined influence of various factors such as the measurement environment, the accuracy of measuring tools, and human operation. To effectively reduce these errors and improve the accuracy of body size measurement, this invention uses a percentage of prediction error to correct the original predicted body size values. Simultaneously, during the training of the regression model, a comprehensive evaluation of the model's predictive performance is conducted to ensure that the model possesses good predictive capabilities.
[0172] Using the percentage error prediction model in step S4, predict the error between the walking body size calculated from key points and the standing body size when the sheep walks naturally. Substitute these values into the following formula to derive the standing body size parameters:
[0173] ;
[0174] Where the parameters are:
[0175] : Calculated standing body size; The walking body size value is calculated based on key points; : Percentage error in the regression model prediction;
[0176] The specific steps are as follows: First, based on existing data and models, a preliminary prediction of the original body size value is made, and the error between the predicted and actual values is calculated. Then, the percentage of prediction error is calculated based on this error. Finally, the original body size value is adjusted accordingly using this percentage of prediction error to obtain the corrected body size value. This correction step significantly reduces the error component in the original measurement data, making the corrected body size value closer to the true value, thus providing a more accurate and reliable data foundation for subsequent analysis and applications.
[0177] During the body size data processing stage, the original body size value is corrected using the percentage of prediction error. This correction method effectively reduces measurement error and improves the accuracy of body size measurement.
[0178] In the regression model training phase, multiple indicators were selected, including mean error (MAE), mean squared error (MSE), root mean squared error (RMSE), mean absolute percentage error (MAPE), and coefficient of determination (R²), to comprehensively and meticulously evaluate the predictive performance of the regression model from different dimensions, ensuring that the model possesses high accuracy and reliability. The specific labels for each indicator are as follows:
[0179] Mean Error (MAE): This measures the average level of error between the predicted and actual values. It can intuitively reflect the magnitude of the model's prediction error. The smaller the value, the higher the model's prediction accuracy.
[0180] Mean Squared Error (MSE): Calculated as the average of the squares of the errors between predicted and actual values, larger errors are given greater weight, thus more sensitively reflecting larger deviations in the model during prediction and helping to identify prediction instability under specific conditions. Root Mean Squared Error (RMSE): As the square root of the mean squared error, it has the same dimensions as the original data, making it easy to intuitively understand the magnitude of the prediction error. It also reflects the degree of dispersion of the error to some extent and is one of the commonly used and important indicators for evaluating model prediction performance.
[0181] Mean Absolute Percentage Error (MAPE): Expresses prediction error as a percentage, eliminating the influence of data units, making it more intuitive and convenient to compare model performance between different datasets, especially suitable for scenarios where the relative accuracy of prediction results is required.
[0182] The coefficient of determination (R²) measures how well a model fits the data. Its value ranges from 0 to 1. The closer it is to 1, the better the model fits the data, meaning that the model can better explain the changes in the dependent variable.
[0183] By comprehensively evaluating the regression model using the aforementioned multiple metrics during training, a thorough and in-depth understanding of the model's performance in different aspects can be achieved. Potential model problems, such as overfitting and underfitting, can be identified promptly, providing a strong basis for model optimization and improvement. This ensures the model possesses high accuracy and reliability in practical applications. Therefore, improving measurement accuracy through body size correction and ensuring model quality through regression model prediction performance evaluation provides a scientific, effective, and comprehensive solution for the fields of body size measurement and data analysis.
[0184] The specific implementation method is as follows:
[0185] (1) Experimental preparation
[0186] The experiment was conducted from January 4th to January 7th, 2025 at the Jianghuai Watershed Comprehensive Experimental Station, using 30 healthy ewes (18 sheep and 12 goats). Before the formal experiment, the sheep were driven back and forth through the passageway multiple times to familiarize them with the environment. Then, one sheep was randomly selected from the flock, and a numbered pendant was attached to it to identify it. Three staff members worked together to measure its body size parameters, and the average of three repeated measurements was taken as the true body size value.
[0187] (2) Data collection
[0188] Sheep were placed in the passage and driven to walk back and forth within it. A depth camera was used to record each time the sheep passed through the shooting area, collecting at least 10 valid videos. The videos were then named in the format of "sheep number - return sequence number".
[0189] (3) Dataset creation
[0190] Video data from 10 out of 30 experimental sheep were used as the test set to ultimately evaluate the performance of the proposed method. Data from the remaining 20 sheep were used for model training and validation. Three video clips were randomly selected from each of the 20 sheep, resulting in a total of 60 video clips used to train the YOLOv11-pose keypoint detection model. Each video clip was analyzed using the official source code of the depth camera, extracting and aligning color image frames and corresponding depth image frames according to the shooting frame rate, and removing blurry and highly repetitive images. Fifty images were randomly selected from each video clip, resulting in 3000 original images. These were then divided into a training set (2400 images), a validation set (300 images), and a test set (300 images) in an 8:1:1 ratio. The Labelme image annotation tool was used to annotate these 3000 images, resulting in a JSON-formatted label file.
[0191] (4) Model training and evaluation
[0192] Data processing was performed on a Windows 10 system, configured with an Intel(R) Core(TM) i9-13900K CPU, 128GB of RAM, an NVIDIA GeForce RTX 3090 GPU, a Python 3.9 runtime environment, and the PyTorch 2.2 deep learning framework. During object detection model training, input images were uniformly resized to 640×640 resolution, with an initial learning rate of 0.001. A Poly strategy was used to dynamically adjust the learning rate, and SGD was used as the optimizer for model training. The training iterations were 500, the batch size was 4, and the weight decay was 0.0005.
[0193] The effectiveness of the keypoint correction method was verified by comparing the average absolute percentage errors of various body dimensions before and after correction under different search radii. The results show that after using YOLOv11-pose for keypoint localization and combining image edge features with depth information for correction, the average absolute percentage errors of body height, abdominal depth, abdominal circumference, and hip height decreased by 0.13%, 0.51%, 0.58%, and 0.39%, respectively. Although the error in body oblique length increased by 0.05%, the overall body dimension measurement accuracy was still improved compared to the previous method, reducing measurement errors caused by keypoint offset.
[0194] Five evaluation metrics—mean error (MAE), mean squared error (MSE), root mean squared error (RMSE), mean absolute percentage error (MAPE), and coefficient of determination (R²)—were used to assess the predictive performance of different regression models. The results showed that the random forest regression model performed best in predicting body size errors. By introducing mixed gait quantization correction, the accuracy of body size measurements was significantly improved. Compared with the uncorrected results, the mean absolute percentage errors for body length, abdominal depth, abdominal circumference, body height, and hip height were reduced by 2.98%, 5.20%, 7.87%, 2.95%, and 4.04%, respectively.
[0195] Although this specification describes embodiments, not every embodiment contains only one independent technical solution. This way of describing the specification is only for clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment can also be appropriately combined to form other embodiments that can be understood by those skilled in the art.
[0196] Therefore, the above description is only a preferred embodiment of this application and is not intended to limit the scope of this application; that is, all equivalent modifications made in accordance with the scope of the claims of this application shall be within the protection scope of the claims of this application.
Claims
1. A method for estimating the standing body size of walking sheep based on gait quantification, characterized in that, Includes the following steps: S1, Data Acquisition A depth camera was used to capture side-view videos of sheep walking naturally, and two-dimensional and three-dimensional images were obtained after preprocessing. S2, Key Point Detection Key points of sheep's torso and legs were detected in 2D images using a key point detection model. S3, Calculation of walking body size parameters The key points detected are transformed into a three-dimensional image, and the three-dimensional coordinates are used to calculate various body size parameters of the sheep. S4. Construction of an error prediction model based on gait quantization a. Define four walking angles: front leg, front knee, back leg, and back knee angles; b. Collect videos of sheep of typical body size walking naturally; in each frame of the sheep walking, calculate the four walking angles of the sheep in both plane and space; calculate the walking body size using the S3 method; regard the body size measured manually when the sheep is standing as the true body size, and define the error between the true body size and the walking body size by dividing the true body size value as the percentage error; form a sample set of "walking angle - percentage error" for sheep of typical body size using the above method; c. Based on the sample set, a regression model is used to establish the mapping relationship between walking posture angle and percentage error of various body sizes, forming a percentage error prediction model; S5. Derivation of standing scale parameters based on walking scale and gait angle. The error between the sheep's walking body size and its standing body size was predicted using the S4 model, and the standing body size parameters were derived by substituting them into the formula: ; in : Calculated standing body size; : Calculate the walking body size value at key points; : Percentage error in the regression model prediction; The key features extracted in step S2 are further corrected using an edge detection algorithm, specifically including the following steps: (1) Use the YOLOv11-pose model to detect key points of the sheep target and its body to obtain an initial set of key points; (2) Using depth images and color images, the edges of the sheep in the color image are detected to obtain an edge feature map with depth information; (3) Correct the key points in the initial key point set according to the edge feature map to obtain the corrected key point set; Random forest is selected as the regression model, with normalized gait quantification angle data as input features and percentage error data of various body sizes as output targets to construct a regression model between gait quantification angle and percentage error of various body sizes. Then, new gait quantification angle data is input into the trained regression model to obtain the percentage error prediction results of various body sizes.
2. The method for estimating the standing body size of walking sheep based on gait quantification according to claim 1, characterized in that, The key points in step S2 are distributed along the contours of the torso and legs, including: P1 at the anterior edge of the scapula, P2 at the middle of the foreleg, P3 at the middle of the foreknee, P4 at the bottom of the forehooves, P5 at the lowest point of the abdomen, P6 at the middle of the hind leg, P7 at the middle of the hindknee, P8 at the bottom of the hindhooves, P9 at the base of the tail, P10 at the highest point of the rump contour, P11 at the lowest point of the back contour, and P12 at the protrusion of the neck. Specifically, multiple key points are selected from the above key points and combined to accurately capture the morphological features and movement information of the torso and legs.
3. The method for estimating the standing body size of walking sheep based on gait quantification according to claim 2, characterized in that, The various body size parameters of the sheep in step S3 include body length, body height, abdominal depth, abdominal circumference, and hip height.
4. The method for estimating the standing body size of walking sheep based on gait quantification according to claim 3, characterized in that, in, The formula for calculating the body's oblique length is as follows: ; Among them, the parameters are: : 3D coordinates of key points on the anterior border of the scapula; : The three-dimensional coordinates of key points at the base of the tail; The formula for calculating the body height is as follows: ; Parameter meaning: The distance from the key point of the withers to the key point of the foreleg; : The distance from the key point of the front leg to the key point of the front knee; : The distance from the key point of the foreknee to the key point of the forehoof; The formula for calculating the abdominal depth is as follows: ; parameter: : Three-dimensional coordinates of key points in the lower abdomen; : Three-dimensional coordinates of key points in the upper abdomen; The calculation process for the waist circumference is as follows: ①. Identify key points in the upper and lower abdomen: Locate key points in the upper abdomen on the depth map. and key points of the lower abdomen ; ②. Path planning: Generate path on the depth map using the Dijkstra algorithm. arrive Find the optimal path and extract sampling points along the path. ; ③. Three-dimensional coordinate transformation: Transform the two-dimensional coordinates of the sampling points. Convert to 3D coordinates ; ④. Calculation of total path length: ; The meanings of each parameter in the formula are as follows: for The three-dimensional coordinates of a point for The three-dimensional coordinates of point +1; ⑤. Ellipse circumference compensation: ; parameter: Elliptic compensation coefficient; The formula for calculating hip height is as follows: ; parameter: The height of the key points of the withers; The key points of the recommendation section are highly relevant.
5. The method for estimating the standing body size of walking sheep based on gait quantification according to claim 1, characterized in that, The specific definitions of the front leg angle, front knee angle, rear leg angle, and rear knee angle in step S4 are as follows: ①. Front leg angle: Using the front leg key point and the front knee key point, first determine the front leg key point, draw an auxiliary line vertically downward with the front leg key point as the origin, then connect the front leg key point and the front knee key point, and calculate the angle between the two line segments as the front leg angle. ②. Angle of the foreleg: Using the foreleg key point, the foreleg key point, and the forehoof key point, with the foreleg key point as the origin, connect the foreleg key point and the forehoof key point respectively, and calculate the angle between the two line segments; ③. The definitions of the hind leg angle and hind knee angle are similar to those of the foreleg angle and fore knee angle described above.
6. The method for estimating the standing body size of walking sheep based on gait quantification according to claim 1, characterized in that, The edge feature detection in step (2) specifically includes the following steps: (a) Convert the color image to grayscale to obtain a grayscale image; (b) The edges of the sheep in the grayscale image are detected using the Canny operator to obtain a preliminary edge detection result image; (c) Generate a mask of the effective depth region using the depth image, set a depth threshold range, mark the pixels in the depth image whose depth values are within the threshold range as the effective depth region, and mark the remaining pixels as the invalid region, thereby obtaining the mask; (d) Perform an AND operation between the preliminary edge detection result image from step (b) and the mask output from step (c) to obtain the edge feature map; (e) Perform morphological expansion processing on the above edge feature map to make the edges more obvious and complete, and obtain an edge feature map with depth information.
7. The method for estimating the standing body size of walking sheep based on gait quantification according to claim 6, wherein its features are as follows: The feature is that in step (3), for each key point in the initial key point set, a circular region is determined with a fixed pixel value as the center and a fixed pixel value as the radius. Within this circular region, a search is conducted to find the key points that are both located on the edge of the sheep body represented by the edge feature map output in step (2) (e) and within the effective depth region generated in step (c). The initial key points are then corrected based on the search results to obtain the corrected key point set.
Citation Information
Patent Citations
Method for automatically detecting ideal standing posture of sheep based on computer vision
CN117576733A
Animal body size measuring method and device, electronic equipment and storage medium
CN116558411A
Non-contact livestock body size measuring method and electronic equipment
CN118196175A
Binocular camera-based cattle body size performance measurement system
CN119941653A