A sow backfat thickness automatic measurement method based on depth map and point cloud

CN122887985APending Publication Date: 2026-10-09HUAZHONG AGRI UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611121505.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-27
Publication Date
2026-10-09

AI Technical Summary

Technical Problem

这种方式存在显著缺陷:首先,劳动强度大且效率低下,难以满足大规模群体的快速普查需求;其次,人工近距离接触和操作极易引起母猪的应激反应,增加了生产管理的难度与风险;此外,测量结果往往受操作人员经验及主观因素影响,一致性较差

Benefits of technology

[0018]有益效果:(1)本发明仅采用安装于限位栏上方的单台深度相机进行数据采集,无需多视角相机协同工作,设备成本较低,安装方式简单,由于相机位于母猪身体正上方,不易受到母猪碰撞及排泄物污染,符合养殖场实际应用需求,具有较好的稳定性和安全性;

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122887985A_ABST
    Figure CN122887985A_ABST
Patent Text Reader

Abstract

The application discloses a kind of sow back fat thickness automatic measurement method based on depth map and point cloud, comprising the following steps: S1 image acquisition;S2. Key point detection model construction and training;S3. Key point mapping and detection frame segmentation;S4. Histogram segmentation: to the point cloud data of S3, automatically determine the segmentation boundary by combining main peak detection and concave point positioning, complete the automatic extraction of pig body point cloud under the limit column area;S5. Back fat regression model construction and training, the pig body point cloud extracted in S4 is input into PointMamba network model to carry out back fat regression prediction.The application can be applicable to limit column scene, hardware deployment is safe and convenient, and the automatic non-contact measurement method can be monitored in real time and has high precision.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of pig measurement technology, specifically to an automatic method for measuring the backfat thickness of sows based on depth maps and point clouds. Background Technology

[0002] Backfat thickness in sows is an important physiological indicator reflecting their nutritional status, body condition score, and reproductive performance. Scientific and accurate monitoring of backfat thickness is crucial for guiding precision feeding, improving sow reproductive efficiency, and extending their productive lifespan.

[0003] Currently, in large-scale pig farming, backfat thickness measurement mainly relies on contact ultrasound and computed tomography (CT) technology. In contact ultrasound, workers typically use an A-mode or B-mode backfat measuring instrument. This requires shaving the hair at specific measurement points on the sow's back (such as the last rib) and applying a coupling agent, then manually holding the probe against the skin for measurement. This method has significant drawbacks: firstly, it is labor-intensive and inefficient, making it difficult to meet the needs of rapid surveys of large herds; secondly, close manual contact and operation easily cause stress in sows, increasing the difficulty and risk of production management; furthermore, measurement results are often affected by the operator's experience and subjective factors, resulting in poor consistency. Computed tomography (CT) technology is an imaging method that uses X-ray imaging technology to generate tomographic images of the internal structures of humans or animals through computer reconstruction algorithms. While it can measure various internal components of pigs more accurately, its high cost and demanding measurement conditions, requiring anesthesia, limit its application in pig farming and breeding. In addition, both of these measurement methods are contact measurements, which may cause stress reactions in pigs. At the same time, biosafety issues in the measurement process should not be ignored.

[0004] To address the aforementioned issues, non-contact measurement technologies based on computer vision have gradually become a research hotspot. Existing technologies have yielded some solutions for backfat estimation using depth cameras and image processing algorithms, but these still suffer from limitations in application scenarios, high algorithm complexity, or difficulties in hardware deployment.

[0005] Patent CN120747357A discloses a non-contact method for measuring backfat thickness in pigs based on point cloud and deep learning. This method uses two Azure Kinect DK cameras to acquire images from the top and side, respectively, performs segmentation using a SAM model, and builds a regression model based on PointNet++. However, this method has limitations in practical applications: firstly, it is mainly suitable for pigsty aisle scenarios, not gestation pen scenarios, where the free movement of pigs can easily lead to unstable image acquisition quality; secondly, the SAM segmentation model used has a huge computational load, requiring extremely high hardware computing power, which is not conducive to low-cost real-time deployment in farms.

[0006] Patent CN121545006A discloses a method and system for estimating backfat thickness in sows based on deep learning and image processing. This method uses a depth camera located directly behind the gestation pen to acquire rump depth images, extracts the Region of Interest (ROI) using the YOLOv8 model, and combines this with two-dimensional morphological parameters for estimation. However, this technical solution also has shortcomings: First, the camera is installed directly behind the gestation pen, requiring it to be positioned directly facing the gap for shooting. This location is highly susceptible to contamination from sow excrement or impacts from the sow, posing a safety hazard of equipment damage. Second, this method primarily relies on the contour and statistical features of two-dimensional images. Its image processing involves various morphological operations and parameter fitting steps, making it susceptible to changes in sow posture and background interference in complex breeding environments, leading to insufficient stability and accuracy in the estimation.

[0007] In conclusion, developing an automated, contactless method for measuring backfat thickness in sows that is suitable for gestation crates, has safe and convenient hardware deployment, and can balance real-time performance and high precision is a technical problem that urgently needs to be solved in the current smart animal husbandry industry. Summary of the Invention

[0008] To address the shortcomings of existing technologies, the purpose of this invention is to provide an automatic measurement method for sow backfat thickness based on depth maps and point clouds. This method uses a top-mounted single-view camera to photograph sows in gestation crates, predicting their backfat thickness upon entry. The YOLO11 model and point cloud histogram method are used to automatically segment and filter the point cloud, and the PointMamba model is employed to achieve high-precision backfat thickness prediction. This method is suitable for gestation crate scenarios, offers safe and convenient hardware deployment, and provides real-time monitoring with high accuracy.

[0009] To achieve the above objectives, the technical solution of the present invention is: an automatic measurement method for backfat thickness in sows based on depth maps and point clouds, comprising the following steps: An automatic measurement method for backfat thickness in sows based on depth maps and point clouds includes the following steps: S1 Image Acquisition: The camera acquires an image of the sow directly above the restraint bar, obtains the depth image and 3D point cloud data of the sow's back, and measures and records the backfat thickness data; S2. Construction and training of key point detection model: Select several depth images of sows from S1, construct a key point detection model for the pig body based on the YOLO11n-Pose network, and train and validate the model. S3. Keypoint Mapping and Detection Box Segmentation: Based on the pig body keypoint detection model, YOLO detection boxes are used to segment the point cloud of the remaining sows, geometric constraints are constructed to automatically remove the head and tail regions, and point cloud data where all keypoints are visible are filtered. S4. Histogram segmentation: The point cloud data obtained from S3 is automatically segmented by combining peak detection and concave point localization to complete the automatic extraction of pig body point cloud under the restraint area. S5. Backfat Regression Model Construction and Training: The pig body point cloud extracted in S4 is input into the PointMamba network model to construct the backfat regression model. During the training phase, the network is optimized using an exponentially weighted loss function. During the prediction phase, the median of the ear mark is taken as the final output for the prediction results of the same pig in multiple frames.

[0010] The method for constructing the pig body key point detection model in step S2 includes: S21. Construct a pig body key point detection dataset: Randomly select samples from the sow population, and divide their depth images into training, validation and test sets; Use annotation tools to annotate the detection boxes of pig body targets, and define 6 key points including the neck, left and right shoulders, left and right hips and tail root, and use triplet form containing two-dimensional coordinates and visibility labels for annotation; S22. Construct a lightweight YOLO11-Pose base network: Using YOLO11n-Pose as the base framework, set the input image size to 640×640 pixels, and adopt data augmentation strategies of random rotation, translation and horizontal flipping; S23. Construct a visibility-pose decoupled keypoint detection head: Based on the basic network, construct a detection head that includes an independent pose prediction branch and a visibility context branch; the pose prediction branch is used to regress the two-dimensional coordinates of keypoints, and the visibility prediction branch is used to classify the occlusion state of keypoints. The two branches share the main features but use independent convolution parameters for learning. S24. Wing Loss Optimizes Keypoint Localization: During model training, the Wing Loss function is used to replace the original keypoint location loss function. This enhances the network's sensitivity to subtle localization errors through nonlinear mapping within the error interval. S25. Model Training and Performance Validation: The network is iteratively trained using the labeled dataset, and the hyperparameters are adjusted according to the validation set metrics to finally obtain the trained pig body key point detection model.

[0011] The formula for calculating Wing Loss in step S24 is as follows: In the formula, x and y are the actual x and y coordinates of key points in the network input image, respectively. and Here, ω represents the x-coordinate and y-coordinate of the keypoints predicted by the network; ω and ε are user-defined values, in this study ω=10; ε=2; e is the Euclidean distance of the keypoint prediction error. Loss at key locations.

[0012] Final loss function L total =12L pose +2L vis +10L CIoU +1.5L DFL +0.2L class ; The loss at the key point location is L pose : in, For the first A key point is the Logit output in the classification branch. For the Sigmoid activation function, For the first The true category labels of the key points and , The number of samples used in the calculation; The target bounding box loss is L CIoU : in, The intersection-union ratio (IU) of the predicted bounding box and the ground truth bounding box. and These represent the center coordinates of the predicted bounding box and the ground truth bounding box, respectively. This represents the Euclidean distance between the center point of the predicted bounding box and the center point of the ground truth bounding box. It is the length of the diagonal of the minimum bounding rectangle that simultaneously encloses the predicted bounding box and the ground truth bounding box. The difference in aspect ratio between the predicted bounding box and the ground truth bounding box. ,in , , , These represent the width and height of the predicted bounding box and the ground truth bounding box, respectively. These are the weighting coefficients. ; The distribution focus loss is L DFL : in , The predicted probabilities are the left and right adjacent discrete positions. , For the corresponding interpolation weights, satisfying + = 1; The classification loss is L class : in For the first Logit output from each category branch, For the Sigmoid activation function, For true category labels and , The number of samples used in the calculation.

[0013] In step S3, the removal of point cloud data from the head and tail regions is achieved by constructing a shoulder direction vector using key points on the left and right shoulders, and using the neck key point as a reference to construct a dividing line parallel to the shoulder direction vector. The main body region is determined based on the side where the shoulder center is located, and only the point cloud data located on the same side as the shoulder center is retained, thereby automatically removing the head region. Using the tail root key point as a reference point, a hip direction vector is constructed in combination with the left and right hip key points. Similarly, the normal vector is calculated to divide the space. By introducing the neck key point as a direction discrimination criterion, the tail region is automatically removed.

[0014] The S4 histogram segmentation involves automatic extraction of pig body point clouds based on histogram peak analysis. The specific steps include: S41. Based on the point cloud data obtained by S3, extract the three-dimensional coordinate information of the point cloud, and perform preliminary cropping of the point cloud in the Z-axis height direction according to the prior knowledge of the scene to remove background areas that do not obviously belong to the target pig body. S42. Project the point cloud after initial cropping along the Z-axis height direction, count the number of points in each height interval and perform Gaussian smoothing to obtain a smoothed histogram. S43. Determine the global maximum value based on the smoothed histogram, use a certain proportion of this maximum value as a threshold to determine the candidate peak area, and select the candidate peak area with the largest area as the target main peak area; S44. Concave Point Boundary Search: Starting from the center of the main peak, search for local minima to the left and right as concave point boundaries to determine the Z-axis segmentation range; S45. Using the Z-axis segmentation results obtained in S44, the point cloud is cropped to obtain the main body region of the pig. The point cloud of this region is reconstructed along the Y-axis direction, and the segmentation boundary in the Y-axis direction is obtained according to the main peak detection and concave point search methods in steps S42 to S44. S46. Perform density-based clustering analysis to denoise the segmented point cloud; S47. Perform an overall quality assessment on the pig body point cloud after cluster analysis, and retain the point cloud that meets the final point count requirement as the valid pig body point cloud output.

[0015] Step S5 specifically includes: S51. Point cloud grouping: The center point is uniformly selected by sampling the farthest point and the local neighborhood is extracted by combining K-nearest neighbor search. The coordinates of the neighborhood points are converted into local representations relative to the center point, and a point cloud block input containing local geometric structure information is constructed. S52. Local Feature Encoding: Input local point cloud blocks into Point Encoder for feature encoding, converting them into a fixed-dimensional feature sequence to form the feature sequence required for subsequent sequence modeling; S53. Mamba Sequence Modeling: Input the feature sequence obtained in S52 into the sequence modeling module to gradually fuse local geometric features into local feature representations with global semantic information; S54. Global Feature Aggregation: Perform max pooling on all local feature representations in the spatial dimension to extract the feature information with the strongest response and form a global feature vector; S55. Backfat Thickness Regression Prediction: Input the obtained global feature vector into the regression prediction module and output the final backfat thickness prediction result; S56. Multi-frame prediction aggregation based on ear tags: The prediction results of multiple point cloud samples belonging to the same pig are classified by ear tag number, and the multi-frame prediction results under the same ear tag are aggregated by median statistics to obtain the final backfat thickness prediction value of the pig. S57. Model Training and Optimization: The network is trained using an exponentially weighted loss function based on label distribution.

[0016] The exponentially weighted loss function is: L b = w( ) × ( - )² w( ) = exp(0.5 × | |), w( )≤4 Among them, L b The weighted loss value. These are the model's predicted values. For the actual label value, w( ) represents the dynamic weight of the corresponding sample. Represents the standardized label value, | | represents the absolute value of the standardized label value.

[0017] The mean absolute error (MAE) of the backfat regression model on the test set was 1.5768 mm, and the coefficient of determination (R²) was 0.7035.

[0018] Beneficial effects: (1) This invention uses only a single depth camera installed above the limit bar for data acquisition, without the need for multi-view cameras to work together. The equipment cost is low and the installation method is simple. Since the camera is located directly above the sow's body, it is not easily affected by collisions with the sow or pollution from excrement. It meets the actual application needs of farms and has good stability and safety. (2) This invention uses the YOLO11n-POSE key point detection model to obtain the key anatomical locations of the pig body, and combines the point cloud height histogram segmentation method to extract the pig body region. The computation is smaller and the hardware resource requirements are lower, which can meet the real-time deployment needs of the breeding site. At the same time, by combining key point localization with geometric constraints, the head and tail and other areas with low correlation with backfat thickness can be removed simultaneously, thereby improving the quality of the input point cloud. (3) The present invention uses the PointMamba network to construct a backfat thickness regression model. Compared with the traditional PointNet++ network, it can more effectively model long-distance spatial dependencies and improve the point cloud feature expression ability. Combined with the ear tag aggregation strategy and weighted loss function, the backfat thickness prediction accuracy is further improved. Attached Figure Description

[0019] Figure 1 This is a flowchart of the present invention; Figure 2 Here is a flowchart of the PointMamba network model; Figure 3 A flowchart of the YOLO11-Pose network for detecting key points on the pig body; Figure 4 This is a schematic diagram illustrating the automatic removal of the head and tail regions of a pig's point cloud based on key point constraints. Detailed Implementation

[0020] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the described embodiments of this disclosure without creative effort are within the scope of protection of this disclosure.

[0021] Example 1 like Figure 1 As shown, this invention provides a method for estimating backfat thickness in sows based on deep learning and image processing, including the following steps: image acquisition, key point detection model construction and training, key point mapping and detection box segmentation, histogram segmentation, backfat regression model construction and training, and sow backfat thickness prediction.

[0022] S1 Image Acquisition: The camera captures an image of the sow directly above the restraint bar, obtains the depth image and 3D point cloud data of the sow's back, and measures and records the backfat thickness data.

[0023] First, a Femto Bolt depth camera was used to collect data from sows located in their stalls. During acquisition, the camera was positioned directly above the sow to simultaneously acquire depth and point cloud video data of the sow's back area, and the results were saved as MKV files. The acquisition time for each sow was approximately 3 minutes. The acquired video files were named after the sow's ear tag number to establish a one-to-one correspondence between video data and individual sows. After video acquisition, a backfat thickness measurement was performed using an ultrasound backfat analyzer, and the measurement value was recorded as real label data for subsequent model training and feature analysis.

[0024] All data were collected from Fengmeihe Pig Farm in Wuhan City from August 13, 2025 to November 5, 2025. After removing corrupted files and data with measurement errors, a total of 990 sows were included, including replacement gilts and multiparous sows. The gestation days of multiparous sows included 30 days, 50 days, 70 days, and 90 days.

[0025] Subsequently, the acquired MKV video files undergo fixed-interval frame extraction, with an interval of 15 frames, to obtain discrete depth map frame sequences and their corresponding point cloud data. For each frame of depth map data, its 16-bit raw depth value is extracted and preprocessed, including: removing invalid depth values, including NaN or Inf values, and initially cropping the depth value according to the sow's position within the restraint fence scene, limiting the depth value to a preset depth range. In a preferred embodiment, the preset depth range is -500 mm to -2000 mm. The preprocessed depth values ​​are mapped to grayscale images, generating and saving aligned PNG format depth maps; simultaneously, the 16-bit raw depth values ​​are retained, and based on camera intrinsic parameters, the two-dimensional pixel coordinates are mapped to three-dimensional spatial coordinates.

[0026] Specifically, for each frame of the depth map, a 3D point cloud is generated using a pixel-by-pixel back-projection method. Specifically, all valid pixels in the depth map are traversed, and the pixel coordinates and their depth values ​​are converted into 3D coordinates in the camera coordinate system according to the camera calibration model; invalid points, illegal points, and points exceeding the set spatial range are removed; finally, a ply format point cloud file is generated and saved. This yields 3D point cloud data corresponding to each frame of the depth map, providing foundational data for subsequent pig body keypoint detection, point cloud mapping, and target region segmentation.

[0027] S2 Construction and Training of Keypoint Detection Model: Several sow depth images were divided into training, validation and test sets. A visibility-pose decoupled detection model for pig body keypoints was constructed based on the YOLO11n-Pose network, and the model was trained and validated.

[0028] Among them, the visibility-pose decoupling detection model for key points on the pig body addresses the problems of frequent occlusion, difficulty in visibility judgment, and insufficient localization accuracy of key points on the pig body. It improves the original YOLO11-Pose network to achieve accurate localization of key anatomical points on the pig body in complex farming environments. The construction steps of the visibility-pose decoupling detection model for key points on the pig body include: S21: Construct a pig body keypoint detection dataset From 990 sows obtained from S1, 35 sows were randomly selected as the keypoint detection dataset samples. All depth maps belonging to these sows were randomly divided into training, validation, and test sets in an 8:1:1 ratio. To avoid data leakage caused by the same sow image appearing in different datasets simultaneously, the data was divided on an individual sow basis, ensuring that each sow's image existed only in one of the training, validation, or test sets. A total of 5054 depth map samples were obtained, including 4007 in the training set, 495 in the validation set, and 552 in the test set. The Labelme annotation tool was used to annotate the detection boxes and keypoints on the pig bodies. Six pig body keypoints were defined: neck, right shoulder, right hip, tail base, left hip, and left shoulder.

[0029] Each keypoint is represented by a triple (x, y, v), where x and y represent the two-dimensional coordinates of the keypoint, and v represents the keypoint's visibility label. v is set to 1 when the keypoint is clearly visible; it is set to 0 when the keypoint is occluded, outside the field of view, or cannot be accurately determined. Therefore, the dimension representation of keypoint annotation for a single pig is 6 × 3 = 18.

[0030] S22. Construct a lightweight YOLO11-Pose base network A lightweight pig body keypoint detection network was constructed using YOLO11n-Pose as the basic framework. This network simultaneously performs pig body bounding box detection, keypoint location prediction, and keypoint visibility prediction. The input image size is 640×640 pixels. During training, data augmentation strategies such as random rotation, translation, scaling, and horizontal flipping are employed to improve the network's adaptability to changes in pig body pose and acquisition viewpoint.

[0031] S23. Constructing a Visibility-Pose Decoupling Keypoint Detection Head Traditional YOLO-Pose integrates keypoint 2D coordinate prediction and keypoint visibility prediction into the same regression branch, achieving joint prediction through shared convolution parameters. However, in pig keypoint detection tasks, using the same feature representation for keypoint localization and keypoint visibility determination can easily lead to gradient conflicts, thereby reducing their respective accuracy. To address this issue, this invention proposes a visibility-pose decoupled keypoint detection head. For each scale feature map, a pose prediction branch and a visibility prediction branch are constructed separately: The Pose Branch is used to predict the two-dimensional coordinate information of all key points. Its output dimension is 6×2=12, consisting of two convolutional modules and one 1×1 convolution, to realize the spatial location regression of key points.

[0032] The Visibility Branch predicts the visibility state of corresponding keypoints. Its output dimension is 6×1=6, consisting of two convolutional layers, two levels of ECA (Efficient Channel Attention) attention modules, and one 1×1 convolutional layer. The two levels of ECA attention modules are embedded after the two convolutional layers, and through adaptive learning of the importance weights of each channel, they enhance the feature responses related to keypoint visibility and suppress irrelevant features from the background and occluded areas.

[0033] The pose prediction branch and the visibility prediction branch share the multi-scale features extracted by the backbone network, but they are learned using completely independent convolutional parameters. Finally, the coordinate prediction results and the visibility prediction results are reassembled to form a complete keypoint output. Compared with traditional coupled keypoint detection heads, this invention reduces optimization interference between different tasks through task decoupling at the structural level, improves keypoint localization accuracy and prediction stability in occluded scenes, and is beneficial to the optimization of both tasks.

[0034] S24. Wing Loss optimization for key point localization The original YOLO-Pose keypoint loss is based on OKS (Object Keypoint Similarity), which has limited ability to distinguish small-scale positioning errors. To further improve the positioning accuracy of pig body keypoints, this invention uses Wing Loss to replace the original keypoint position loss.

[0035] Let the key point prediction error be expressed as: Wing Loss is defined as: Where x and y are the actual x and y coordinates of key points in the input image, respectively. and Here, ω and ε represent the x and y coordinates of the keypoints predicted by the network; ω and ε are user-defined values, in this embodiment ω=10; ε=2; e is the Euclidean distance of the keypoint prediction error, and L is the distance between the x and y coordinates. pose The loss function is used for keypoint location. A logarithmic function is employed to amplify the loss and enhance the network's sensitivity to subtle localization errors. When the prediction error is large, Wing Loss uses a linear penalty method to avoid excessive gradients affecting training stability, thus balancing fine localization capability and training stability.

[0036] S25. Model Training and Performance Validation The training parameters are set as follows: the number of training epochs is 300, the batch size is 64, the weight of the key point location loss is set to 12, the weight of the key point visibility loss is set to 2, the weight of the target box loss is set to 10, and the weight of the classification loss is set to 0.2.

[0037] Final loss function L total =12L pose +2L vis +10L CIoU +1.5L DFL +0.2L class ; The loss at the key point location is L pose The keypoint visibility loss is L vis The visibility state of keypoints is monitored using the same binary cross-entropy (BCE) loss function, and its calculation formula is as follows: in, For the first A key point is the Logit output in the classification branch. For the Sigmoid activation function, For the first The true category labels of the key points and , The number of samples used in the calculation.

[0038] The target bounding box loss is L CIoU This embodiment introduces Distribution Focal Loss to further improve the accuracy of bounding box regression. Specifically, in, The intersection-union ratio (IU) of the predicted bounding box and the ground truth bounding box. and These represent the center coordinates of the predicted bounding box and the ground truth bounding box, respectively. This represents the Euclidean distance between the center point of the predicted bounding box and the center point of the ground truth bounding box. It is the length of the diagonal of the minimum bounding rectangle that simultaneously encloses the predicted bounding box and the ground truth bounding box. The aspect ratio consistency term measures the difference in aspect ratio between the predicted bounding box and the ground truth bounding box, and is expressed as: in , , , These represent the width and height of the predicted bounding box and the ground truth bounding box, respectively. The weighting coefficients are expressed as follows: The distribution focus loss is L DFL This loss function models the probability distribution of the bounding box boundary, allowing the model to focus on discrete values ​​near the boundary. in , The predicted probabilities are the left and right adjacent discrete positions. , For the corresponding interpolation weights, satisfying + = 1.

[0039] The classification loss is L class : in For the first Logit output from each category branch, For the Sigmoid activation function, For true category labels and , The number of samples used in the calculation.

[0040] The SDG optimizer is used in conjunction with a cosine annealing learning rate decay strategy, and an early stopping mechanism is set to improve model training efficiency and reduce the risk of overfitting.

[0041] Experimental results on the test set demonstrate that the proposed method can achieve high-precision detection of key points on a pig's body. The target detection mAP50-95 reaches 0.8957, and the key point detection mAP50-95 reaches 0.9883. The key point visibility judgment accuracy reaches 95.53%. The mean absolute error (MAE) for key point localization is 9.29 pixels, and the root mean square error (RMSE) is 12.25 pixels.

[0042] The improved keypoint detection network contains 211 layers with only 2.73 M model parameters, and the theoretical computational cost for a single 640×640 input image is 6.9 GFLOPs. While maintaining its lightweight characteristics, it achieves high-precision pig body keypoint detection, which can meet the needs of edge device deployment and real-time detection in actual farming scenarios.

[0043] Experimental results show that the visibility-pose decoupled keypoint detection head proposed in this invention, combined with the Wing Loss optimization strategy, significantly improves the localization accuracy of pig body keypoints and the detection robustness in occluded scenarios while maintaining the network's lightweight characteristics. The pig body keypoint detection network YOLO11-Pose is shown below. Figure 3As shown, it includes: a trunk feature extraction module, a neck feature fusion module, and a multi-branch prediction module.

[0044] YOLO11 Backbone: This module is used to extract multi-level features from the input image, gradually extracting the texture, edge, and semantic information of the target.

[0045] Neck Features module: Used to fuse feature information at different scales, enhancing the target's expressive power through multi-scale feature interaction.

[0046] The multi-branch prediction module includes bounding box prediction branch, category prediction branch, key point coordinate prediction branch, and visibility prediction branch.

[0047] Box Branch: Used to predict the location of the bounding box of the pig target.

[0048] Class prediction branch: Used to predict the target class of pigs.

[0049] Coordinate Branch: Used to regress the two-dimensional coordinates of key points on the pig.

[0050] Visibility Prediction Branch: This branch is used to predict the visibility state of each keypoint. It enhances the visibility feature representation of keypoints by introducing the ECA attention mechanism.

[0051] S3. Keypoint Mapping and Detection Box Segmentation: Based on the trained keypoint detection model, YOLO detection boxes are used to infer the depth map data of the remaining sows, obtaining the detection box for each pig target, the 2D coordinates of 6 keypoints, and the visibility markers corresponding to each keypoint. The 3D point cloud corresponding to each frame of depth map is mapped to the 2D image plane. Based on the detection box of the pig target, the mapped point cloud is initially segmented, retaining only the point cloud points whose projection positions fall within the pig target detection box, and removing the background area point cloud and non-target area point cloud. Based on keypoint constraints, the head and tail regions of the pig point cloud are automatically removed, and point cloud data where all keypoints are visible are selected to obtain the effective pig point cloud. The effective point cloud meets the conditions that all keypoints are visible, the target area is complete, and the head and tail interference areas have been removed, and can be used as high-quality input data for subsequent back point cloud feature extraction, body condition characterization, and backfat thickness prediction modeling.

[0052] Specifically, the depth map data for the remaining sows includes 139,373 images of 955 pigs.

[0053] Mapping the 3D point cloud corresponding to each frame's depth map to the 2D image plane specifically includes: establishing the mapping relationship between 3D point cloud points and 2D image pixels through coordinate transformation based on camera intrinsic parameters and the spatial correspondence between the depth map and the point cloud, and mapping the 3D point cloud to the 2D image plane through affine transformation.

[0054] Using the detection bounding box of the pig target output by the YOLO11-Pose model, the mapped point cloud is initially segmented. Only point cloud points whose projection positions fall within the detection bounding box of the pig target are retained, while background area point cloud and non-target area point cloud are removed, thus achieving the initial separation from the full scene point cloud to the point cloud of a single pig target.

[0055] For head region removal, a shoulder direction vector is constructed using the left and right shoulder keypoints, and a head segmentation line parallel to the shoulder direction vector is constructed using the neck keypoint as a reference point. The side of the pig's main body region is determined based on the position of the shoulder center point relative to this segmentation line, and only the point cloud data on the same side as the shoulder center is retained, thereby automatically removing the head region point cloud in front of the neck.

[0056] For tail region removal, the tail root key point is used as the reference point, and a hip direction vector is constructed by combining the left and right hip key points. The corresponding segmentation normal vector is calculated based on the hip direction vector, and the tail segmentation boundary is established with the tail root key point as the reference. Simultaneously, the neck key point is introduced as a direction discrimination criterion to determine the side where the main body region of the pig is located. Only the point cloud data located on one side of the main body region of the pig is retained, thereby automatically removing the tail region point cloud behind the tail root.

[0057] Figure 4 The green rectangle in the middle is the detection box. The six key points are: Neck, RS (right shoulder), RH (right hip), Tail (tail), LH (left hip), and LS (left shoulder). The blue line is the segmentation reference line, and the red line is the head and tail segmentation line.

[0058] To ensure the quality of point cloud segmentation and reduce errors caused by keypoint occlusion or missing points, this invention introduces a keypoint visibility constraint. Specifically, only point cloud samples where all six keypoints are determined to be visible are retained; samples where any keypoint is invisible, occluded, outside the field of view, or cannot be accurately located are discarded. Ultimately, 94,336 point clouds are retained, all with visible keypoints, and have undergone bounding box segmentation and keypoint-based head and tail removal.

[0059] S4 Adaptive segmentation of pig body point cloud based on coordinate axis projection histogram: The point cloud data obtained by S3 is used to automatically determine the segmentation boundary by combining the main peak detection and concave point localization through the statistical characteristics of the spatial distribution of pig body and restraint pen, and complete the extraction of pig body point cloud in restraint pen area.

[0060] In the preliminary point cloud of the pig body obtained in step S3, although some background, head, and tail regions have been removed through object detection boxes and keypoint constraints, a large number of gestation pen point clouds still exist above and on both sides of the pig body because the sow is in a gestation pen environment. If these point clouds are directly input into subsequent 3D feature extraction or backfat prediction models, significant noise interference will be introduced, reducing the model's prediction accuracy.

[0061] To achieve automatic extraction of pig body point clouds in a restraint pen environment, this step proposes a point cloud segmentation method based on coordinate axis projection histogram analysis. This method, based on the detection bounding boxes and keypoint segmentation results of the pig body targets output by the YOLO11-Pose model in the previous step, utilizes the statistical characteristics of the spatial distribution of the pig body and the restraint pen. By combining peak detection and concave point localization, it automatically determines the segmentation boundaries, thereby achieving accurate extraction of the pig body region.

[0062] Specifically, the following steps are included: S41. Point Cloud Preprocessing Read the point cloud data obtained from step S3, extract the three-dimensional coordinate information of each point, and perform preliminary range cropping in the height direction (Z-axis) based on prior scene knowledge to remove background areas that do not clearly belong to the target pig body.

[0063] Let the original point cloud be represented as: Where N is the total number of points in the point cloud, Let be the three-dimensional coordinates of the i-th point.

[0064] Based on the prior spatial position of the pig in the data collection scenario, for the height direction, i.e. Perform initial trimming along the axial direction. Set a preset height range: Only the points that meet the above height conditions are retained to obtain the pre-clipping point set. This is to reduce interference in subsequent statistical analysis.

[0065] S42. Constructing the Z-axis projection histogram Project the pre-cropped point cloud along the Z-axis, count the number of points in each height interval, and construct a one-dimensional histogram. Let the width of the histogram bins be Δz, and the k-th height interval be... Then the number of points H(k) in the k-th interval represents the number of points falling into the height interval. The number of point clouds within.

[0066] To reduce the impact of random noise on the statistical results, the original histogram was Gaussian smoothed to obtain the smoothed distribution curve Hs(k).

[0067] S43. Determination of the Main Peak Region Find the global maximum value Hmax in the smoothed histogram Hs(k). Use a certain proportion of this maximum value as the peak threshold. T = α × Hmax Where α is the peak value ratio coefficient.

[0068] Continuous intervals where the smoothed histogram value is higher than the threshold T are considered candidate peak regions. For the j-th candidate peak region, its area Aj is defined as the sum of all smoothed histogram values ​​within that peak region, i.e., from the starting position s of the peak region. j To the end position e j The accumulated value of Hs(k). Where s j and e j These represent the starting and ending positions of the j-th peak region, respectively. Since pig body point clouds typically form a continuous and dense main distribution in space, while restraint fences, discrete noise, or local background structures often appear as smaller peaks or narrow peak regions, selecting the candidate peak region with the largest area as the target main peak region can effectively avoid interference from local noise peaks or fence structures in determining the segmentation boundary.

[0069] S44. Concave Point Boundary Search After determining the main peak, the search starts from the center of the main peak and searches for local minima of the smooth curve to the left and right. A local minimum is considered a candidate local minimum point if it meets the following conditions.

[0070] The left and right local minima obtained by the search are respectively used as... The final dividing boundary in the axial direction is denoted as and .therefore, The target segmentation range in the axial direction is represented as follows: .

[0071] Compared with segmentation using a fixed height threshold, the boundary determination method based on concave point localization can adaptively adjust the segmentation range according to different pig body size, posture, point cloud density, and changes in the acquisition environment. It can more accurately reflect the density change trend between the pig body point cloud and the gestation pen point cloud, thereby improving the stability and robustness of point cloud segmentation.

[0072] Furthermore, to further improve the reliability of the segmentation results, the validity of the identified main peak is also determined. Specifically, this includes: First, when the position of the main peak is lower than the preset height threshold, it is considered that the current point cloud does not conform to the normal distribution characteristics of the target pig in space, and the subsequent processing of the sample is terminated. Second, the number of original points in the histogram interval where the main peak is located is counted. When the number of points in the interval is lower than the preset point threshold, it is determined that the main peak lacks sufficient point cloud support and is not considered as a valid pig body main peak. Third, the threshold boundary span corresponding to the main peak is constrained. When the width of the main peak region exceeds the preset range, it is considered that the current histogram may have abnormal expansion, multi-target interference, or severe residual limit bars, and the point cloud sample is discarded.

[0073] By using the above validity criteria, the probability of abnormal point clouds, occluded samples, and failed segmentation samples entering subsequent models can be further reduced.

[0074] S45. Adaptive Y-axis segmentation The point cloud is cropped using the Z-axis segmentation result obtained in S44 to obtain candidate point clouds of the pig's main body. Subsequently, a projection histogram is reconstructed along the Y-axis of this candidate point cloud, and the histogram smoothing, main peak detection, concave point boundary search, and validity determination processes in steps S42 to S44 are repeated to obtain the segmentation boundary along the Y-axis. The segmentation range along the Y-axis is... .

[0075] The final pig body candidate point cloud meets the following conditions: ; Only retain those that are simultaneously located Axis division range and Point cloud points within the axis segmentation range form candidate regions for the pig body. By performing adaptive segmentation in two spatial directions, this invention can effectively remove residual gestation pen point clouds above and on both sides of the pig body, improving the integrity and purity of the pig body point cloud region.

[0076] S46. Clustering Denoising Processing Density-based clustering analysis is performed on the candidate pig point cloud obtained in step S45 to divide spatially similar points into different clusters. Discrete points not belonging to any cluster are considered noise points and are removed. For valid clusters, the number of points in each cluster is counted, and only clusters with more than a preset threshold are retained. Small clusters with fewer points are identified as residual background points, stall fragments, or other noise interference and are deleted. Through clustering denoising, residual discrete noise points and local background points after histogram segmentation can be further eliminated, making the final pig point cloud more continuous and complete.

[0077] S47. Final Validity Screening The overall quality of the clustered pig point cloud is assessed, and the total number of points in the final retained point cloud is counted. If the total number of points in the point cloud is lower than a preset threshold, the current sample is considered to have severe occlusion, incomplete acquisition, or segmentation failure, and does not meet the requirements for subsequent analysis, and the sample is discarded. Only point clouds that meet the final point count requirements are retained as valid pig point clouds for output.

[0078] After the above steps, a total of 70,235 complete pig body point clouds with low noise were obtained, providing reliable input for subsequent backfat thickness regression prediction using the PointMamba network.

[0079] S5 builds and trains a backfat thickness regression prediction model based on the PointMamba network: A backfat thickness regression prediction model based on the PointMamba network was constructed. 70,235 pig point clouds extracted by S4 were divided into training, validation, and test sets in an 8:1:1 ratio. These sets were converted to .npy format and sampled at fps to 2048 points. The samples were then input into the PointMamba network backfat thickness regression prediction model to learn the mapping relationship between the 3D morphological features of the pig's back and overall body and backfat thickness, and to output the predicted backfat thickness value for each pig.

[0080] The following describes the basic structure of PointMamba. Figure 2 As shown, it includes: (1) Point cloud grouping module FPS+KNN Grouping For the input pig body point cloud, the point cloud grouping module first selects a fixed number of center points from the pig body point cloud using farthest point sampling (FPS) to ensure the uniform distribution of sampling points in the overall space. Then, using each center point as a reference, K-nearest neighbor search (KNN) is used to obtain the corresponding neighborhood point set, forming several local point cloud blocks. For each local point cloud block, the coordinates of the neighborhood points are finally converted into local coordinates relative to the center point, thus obtaining a point cloud block input with local geometric structure information, providing a foundation for subsequent feature encoding.

[0081] (2) Point Encoder After point cloud grouping, each local point cloud patch is input into a Point Encoder for feature encoding. This local feature encoder employs a point feature extraction network with shared parameters to learn the features of each point within the local point cloud patch. It then uses max pooling to aggregate the features of neighboring points, extracting a high-dimensional feature vector that characterizes the local region's geometry. After encoding, each local point cloud patch is converted into a fixed-dimensional local feature representation, thus forming the local feature sequence required for subsequent sequence modeling.

[0082] This process reduces the size of the original point cloud data while preserving important three-dimensional geometric information of local areas of the pig's body, which is beneficial for the subsequent network to learn the spatial relationships between different parts of the pig's body.

[0083] (3) Sequence modeling module Mamba Block The local feature sequence output by the Point Encoder is input into a sequence modeling module composed of multiple Mamba Blocks. In this invention, the sequence modeling module includes 6 Mamba Blocks, used to learn the long-range spatial relationships between different local regions of the pig.

[0084] Mamba Blocks are built on a State Space Model (SSM), enabling the modeling of long sequences of information with linear complexity. During feature propagation, each local block not only retains its own geometric features but also gradually integrates contextual information from other regions, thereby establishing global spatial relationships between regions such as the pig's back, shoulders, hips, and torso.

[0085] Each Mamba Block primarily consists of structures such as feature projection, state space modeling, residual connections, and normalization. The state space modeling module recursively updates the input feature sequence, enabling long-distance dependency transmission. Residual connections mitigate the vanishing gradient problem that may occur during deep network training, improving model training stability. The normalization structure stabilizes feature distribution and promotes model convergence. Within each Mamba Block, local point cloud features and their corresponding location encodings jointly participate in sequence modeling, allowing the model to retain spatial location information while learning local feature relationships. By stacking six Mamba Blocks consecutively, the model can progressively expand its feature receptive range, gradually fusing local geometric features into a three-dimensional morphological representation of the pig with global semantic information.

[0086] (4) Global Feature Aggregation Module (Max Pooling) After multi-layer Mamba Block modeling, the model outputs the feature representation of each local point cloud block. To obtain the global representation for the final prediction, max pooling is performed on all local features in the spatial dimension to extract the most responsive feature information and form a global feature vector.

[0087] This global feature vector integrates geometric and spatial context information from various local regions of the pig, effectively suppressing the effects of local noise, missing point clouds, and pose changes, thus providing a stable input for subsequent regression prediction.

[0088] (5) Backfat thickness regression prediction module After global feature aggregation, the obtained global feature vector is input into the regression prediction module. This regression prediction module includes a multi-layer fully connected network used to perform nonlinear mapping on the global three-dimensional morphological features, learning the correspondence between the three-dimensional point cloud features of the pig and the backfat thickness. Finally, the model outputs the predicted backfat thickness value corresponding to the current point cloud sample. Through end-to-end training, the PointMamba network can automatically extract three-dimensional morphological features related to the backfat thickness of sows, achieving non-contact backfat thickness prediction.

[0089] (6) Multi-frame prediction aggregation strategy based on ear tags Since each sow corresponds to multiple point cloud frames, a single point cloud frame may be affected by local occlusion, pose changes, missing points, or segmentation errors, leading to fluctuations in the prediction results. To improve the stability of individual backfat thickness prediction results, this invention further introduces a multi-frame prediction aggregation strategy based on ear tag numbers.

[0090] First, the ear tag numbers are used to classify multiple point cloud samples belonging to the same pig, and the prediction results for the same ear tag across multiple frames are obtained: Where n represents the number of point cloud frames corresponding to the same ear mark. Indicates the first Predicted backfat thickness corresponding to frame point cloud.

[0091] Subsequently, the median statistical method was used to aggregate the prediction results from multiple frames to obtain the final predicted backfat thickness of the pig: The median of all predictions under the same ear tag is taken as the final prediction value. Median aggregation can effectively suppress the influence of outlier predictions and reduce prediction fluctuations caused by missing point clouds, local occlusion, and posture changes, thereby improving the stability and reliability of the prediction results for individual pig backfat thickness.

[0092] Furthermore, in the pig backfat thickness dataset, the number of samples in different backfat thickness ranges is often unevenly distributed. When training with the traditional mean squared error (MSE) loss function, the model is easily affected by a large number of samples in the middle range, while paying insufficient attention to high and low backfat samples, thus reducing the prediction accuracy of extreme samples.

[0093] To address the above problems, this invention designs an exponentially weighted loss function based on label distribution. The loss weights are dynamically calculated based on the actual backfat thickness of the samples. w( ) = exp(0.5 × | |) And set a weight upper limit constraint: w( )≤4; in The actual label value. The mean of the training set labels. The standard deviation of the training set labels. Represents the standardized label value, | | represents the absolute value of the standardized label value.

[0094] To prevent excessively large weights from causing instability during training, an upper limit is set on the weights. The final loss function is defined as: L b = w( ) × ( - )² In the middle, L b The weighted loss value. These are the model's predicted values. w( is the actual label value) ) represents the dynamic weight of the corresponding sample.

[0095] This weighting mechanism gives higher training weights to samples with backfat thickness that deviate significantly from the overall mean. This allows the model to focus more on high and low backfat samples during parameter optimization, thereby alleviating the problem of unbalanced sample distribution and improving the model's ability to predict backfat thickness across the entire range.

[0096] Furthermore, the parameter settings and prediction results of the backfat thickness regression prediction model based on the PointMamba network are as follows: The PointMamba network parameters are set as follows: number of point cloud blocks (Num Group) is 128, group size is 32, feature dimension (Trans Dim) is 256, point encoder output dimension is 256, and the number of Mamba Block layers is 6. The model is trained using the AdamW optimizer with an initial learning rate of 0.0001 and a weight decay coefficient of 0.0001. Cosine annealing is used for learning rate adjustment, and the training epoch is set to 100 rounds. The batch size is set to 32, and the gradient threshold is set to 10.

[0097] The final model had a mean absolute error (MAE) of 1.5768 mm and a coefficient of determination (R²) of 0.7035 on the test set, indicating that the method can accurately predict backfat thickness using the three-dimensional point cloud information of sows.

[0098] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. An automatic measurement method for backfat thickness in sows based on depth maps and point clouds, characterized in that, Includes the following steps: S1. Image Acquisition: The camera captures an image of the sow directly above the restraint bar, obtains the depth image and 3D point cloud data of the sow's back, and measures and records the backfat thickness data; S2. Construction and training of key point detection model: Select several depth images of sows from S1, construct a key point detection model for the pig body based on the YOLO11n-Pose network, and train and validate the model. S3. Keypoint Mapping and Detection Box Segmentation: Based on the pig body keypoint detection model, YOLO detection boxes are used to infer the depth map data of the remaining sows to obtain the detection box, two-dimensional coordinates of key points, and visibility markers corresponding to each key point for each pig body target. The three-dimensional point cloud corresponding to each frame of depth map is mapped to the two-dimensional image plane. Based on the detection box of the pig body target, the mapped point cloud is initially segmented, retaining only the point cloud points whose projection positions fall within the range of the pig body detection box, and removing the background area point cloud and non-target area point cloud. Based on keypoint constraints, the head and tail areas of the pig body point cloud are automatically removed, and the point cloud data where all key points are visible are filtered to obtain the effective pig body point cloud. S4. Histogram segmentation: The point cloud data obtained from S3 is used to automatically determine the segmentation boundary by combining peak detection and concave point localization, thus completing the automatic extraction of pig body point cloud under the restraint area. S5. Backfat Regression Model Construction and Training: The pig body point cloud extracted in S4 is input into the trained backfat thickness regression prediction model based on the PointMamba network, and the predicted backfat thickness value of the corresponding pig is output. For multiple frames of prediction values ​​belonging to the same pig, the median of the ear mark is taken as the final output. During the training phase, the backfat thickness regression prediction model uses an exponentially weighted loss function to optimize the network and learn the mapping relationship between the three-dimensional morphological features of the pig's back and the whole body and the backfat thickness.

2. The method for automatically measuring backfat thickness in sows based on depth maps and point clouds according to claim 1, characterized in that, The method for constructing the pig body key point detection model in step S2 includes: S21. Construct a pig body key point detection dataset: Randomly select samples from the sow population, and divide their depth images into training, validation and test sets; Use annotation tools to annotate the detection boxes of pig body targets, and define 6 key points including the neck, left and right shoulders, left and right hips and tail root, and use triplet form containing two-dimensional coordinates and visibility labels for annotation; S22. Construct a lightweight YOLO11-Pose base network: Using YOLO11n-Pose as the base framework, set the input image size to 640×640 pixels, and adopt data augmentation strategies of random rotation, translation and horizontal flipping; S23. Construct a visibility-pose decoupled keypoint detection head: Based on the basic network, construct a detection head that includes an independent pose prediction branch and a visibility context branch; the pose prediction branch is used to regress the two-dimensional coordinates of keypoints, and the visibility prediction branch is used to classify the occlusion state of keypoints. The two branches share the main features but use independent convolution parameters for learning. S24. Wing Loss Optimization of Keypoint Localization: During model training, the Wing Loss function is used to replace the original keypoint location loss function. The formula for calculating Wing Loss is as follows: In the formula, x and y are the actual x and y coordinates of key points in the network input image, respectively. and Here, ω represents the x-coordinate and y-coordinate of the keypoints predicted by the network; ω and ε are user-defined values; and e represents the Euclidean distance of the keypoint prediction error. Loss due to key location; Final loss function L total =12L pose +2L vis +10L CIoU +1.5L DFL +0.2L class ; The loss at the key point location is L pose : in, For the first A key point is the Logit output in the classification branch. The Sigmoid activation function is used. For the first The true category labels of the key points and , The number of samples used in the calculation; The target bounding box loss is L CIoU : in, The intersection-union ratio (IU) of the predicted bounding box and the ground truth bounding box. and These represent the center coordinates of the predicted bounding box and the ground truth bounding box, respectively. This represents the Euclidean distance between the center point of the predicted bounding box and the center point of the ground truth bounding box. It is the length of the diagonal of the smallest bounding rectangle that simultaneously encloses the predicted bounding box and the ground truth bounding box. The difference in aspect ratio between the predicted bounding box and the ground truth bounding box. ,in , , , These represent the width and height of the predicted bounding box and the ground truth bounding box, respectively. These are the weighting coefficients. ; The distribution focus loss is L DFL : in , The predicted probabilities are the left and right adjacent discrete positions. , For the corresponding interpolation weights, satisfying + = 1; The classification loss is L class : in For the first Logit output from each category branch, The Sigmoid activation function is used. For true category labels and , The number of samples used in the calculation; S25. Model Training and Performance Validation: The network is iteratively trained using the labeled dataset, and the hyperparameters are adjusted based on the validation set metrics to finally obtain the trained pig body key point detection model.

3. The method for automatically measuring backfat thickness in sows based on depth maps and point clouds according to claim 1, characterized in that, In S3, the head and tail regions of the pig body point cloud are removed by constructing a shoulder direction vector using the key points of the left and right shoulders. Taking the key point of the neck as a reference, a dividing line parallel to the shoulder direction vector is constructed. The main body region is determined according to the side where the shoulder center is located, and only the point cloud data on the same side as the shoulder center is retained, thereby automatically removing the head region. Taking the key point of the tail root as a reference point, the hip direction vector is constructed in combination with the key points of the left and right hips. Similarly, the normal vector is calculated to divide the space. By introducing the key point of the neck as the basis for direction discrimination, the tail region is automatically removed.

4. The method for automatically measuring backfat thickness in sows based on depth maps and point clouds according to claim 1, characterized in that, The S4 histogram segmentation involves automatic extraction of pig body point clouds based on histogram peak analysis. The specific steps include: S41. Based on the point cloud data obtained by S3, extract the three-dimensional coordinate information of the point cloud, and perform preliminary cropping of the point cloud in the Z-axis height direction according to the prior knowledge of the scene to remove background areas that do not obviously belong to the target pig body. S42. Project the point cloud after initial cropping along the Z-axis height direction, count the number of points in each height interval and perform Gaussian smoothing to obtain a smoothed histogram. S43. Determine the global maximum value based on the smoothed histogram, use a certain proportion of this maximum value as a threshold to determine the candidate peak area, and select the candidate peak area with the largest area as the target main peak area; S44. Concave Point Boundary Search: Starting from the center of the main peak, search for local minima to the left and right as concave point boundaries to determine the Z-axis segmentation range; S45. Using the Z-axis segmentation results obtained in S44, the point cloud is cropped to obtain the main body region of the pig. The point cloud of this region is reconstructed along the Y-axis direction, and the segmentation boundary in the Y-axis direction is obtained according to the main peak detection and concave point search methods in steps S42 to S44. S46. Perform density-based clustering analysis to denoise the segmented point cloud; S47. Perform an overall quality assessment on the pig body point cloud after cluster analysis, and retain the point cloud that meets the final point count requirement as the valid pig body point cloud output.

5. The method for automatically measuring backfat thickness in sows based on depth maps and point clouds according to claim 1, characterized in that, Step S5 specifically includes: S51. Point cloud grouping: The center point is uniformly selected by sampling the farthest point and the local neighborhood is extracted by combining K-nearest neighbor search. The coordinates of the neighborhood points are converted into local representations relative to the center point, and a point cloud block input containing local geometric structure information is constructed. S52. Local Feature Encoding: Input local point cloud blocks into Point Encoder for feature encoding, converting them into a fixed-dimensional feature sequence to form the feature sequence required for subsequent sequence modeling; S53. Mamba Sequence Modeling: Input the feature sequence obtained in S52 into the sequence modeling module to gradually fuse local geometric features into local feature representations with global semantic information; S54. Global Feature Aggregation: Perform max pooling on all local feature representations in the spatial dimension to extract the feature information with the strongest response and form a global feature vector; S55. Backfat Thickness Regression Prediction: Input the obtained global feature vector into the regression prediction module and output the final backfat thickness prediction result; S56. Multi-frame prediction aggregation based on ear tags: The prediction results of multiple point cloud samples belonging to the same pig are classified by ear tag number, and the multi-frame prediction results under the same ear tag are aggregated by median statistics to obtain the final backfat thickness prediction value of the pig. S57. Model Training and Optimization: The network is trained using an exponentially weighted loss function based on label distribution.

6. The method for automatically measuring backfat thickness in sows based on depth maps and point clouds according to claim 5, characterized in that, The exponentially weighted loss function is: L b = w( ) × ( - )² w( ) = exp(0.5 × | |),w( )≤4 Among them, L b The weighted loss value. These are the model's predicted values. For the actual label value, w( ) represents the dynamic weight of the corresponding sample. Represents the standardized label value, | | represents the absolute value of the standardized label value.

7. The method for automatically measuring backfat thickness in sows based on depth maps and point clouds according to claim 5, characterized in that, The mean absolute error (MAE) of the backfat regression model on the test set was 1.5768 mm, and the coefficient of determination (R²) was 0.7035.

Citation Information

Patent Citations

  • Non-contact in-vivo pig backfat thickness measuring method based on point cloud and deep learning

    CN120747357A

  • Sow backfat thickness estimation method and system based on deep learning and image processing

    CN121545006A