A visual measurement method for pig body size
By using the reliability of single-view RGB-D images to guide the segmentation model and geometric constraints, the problems of high hardware cost and low accuracy in measuring the body size of pigs in pig houses are solved. Automatic and accurate measurement of body length, width and height is achieved, reducing computational complexity and avoiding animal stress.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ANHUI AGRICULTURAL UNIVERSITY
- Filing Date
- 2026-07-01
- Publication Date
- 2026-07-31
AI Technical Summary
Existing technologies struggle to reliably and accurately measure the length, width, and height of pigs in a pigsty environment, especially under monocular RGB-D image conditions. This results in high hardware costs, computational complexity, and measurement accuracy affected by changes in lighting and posture.
Using single-view RGB-D images, a reliability-guided RGB-D pig segmentation model is employed, combined with skeletal topology and principal axis modeling, adaptive tail root correction, normal section search, and RANSAC ground plane fitting, to achieve automatic measurement of pig body length, width, and height.
It reduces hardware costs and computational complexity, improves measurement stability and accuracy, avoids animal stress, and is suitable for ordinary pigsty environments.
Smart Images

Figure CN122492765A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of pig body size measurement technology, and in particular to a visual measurement method for pig body size. Background Technology
[0002] Pig body size parameters (such as body length, body width, and body height) are important phenotypic indicators for evaluating pig growth and development, body structure, and feeding management level. They have significant application value in precision feeding, weight estimation, breeding selection, and health monitoring. Traditional pig body size measurement mainly relies on manual contact measurement using measuring tapes, measuring sticks, or measuring cages. This method is labor-intensive, inefficient, and the measurement results are greatly affected by the operator's experience and the pig's posture. It is also prone to causing stress reactions in pigs, which is detrimental to animal welfare.
[0003] In recent years, non-contact measurement methods based on machine vision have been extensively studied. Existing technologies are mainly divided into two categories: measurement methods based on two-dimensional images and measurement methods based on multi-view point cloud reconstruction.
[0004] Two-dimensional image methods typically rely on target contours or key points, making them susceptible to variations in lighting, background interference, fence occlusion, pig body contour adhesion, and non-standard poses, resulting in poor measurement stability. While multi-view point cloud reconstruction methods can obtain relatively complete three-dimensional structures of pigs, they usually require multiple depth cameras, fixed acquisition channels, synchronous acquisition, point cloud registration, and noise reduction, leading to high hardware costs and complex computational processes, making them unsuitable for low-cost deployment in ordinary pig houses.
[0005] The following relevant patent documents were found through searching:
[0006] Prior art 1 (CN120628254A) discloses a method for measuring pig weight based on depth estimation and multimodal feature fusion. This method uses a monocular camera to acquire RGB images, generates a pseudo-depth map through a depth estimation algorithm, extracts RGB features and depth features, performs cross-attention fusion, and finally predicts weight using an MLP regression model. This approach only targets weight prediction and does not directly measure linear body size parameters such as body length, width, and height; its depth information comes from a monocular depth estimation network rather than a real depth sensor, and depth estimation errors directly affect the reliability of subsequent feature fusion; furthermore, this method does not involve segmentation and mask constraints of the pig's body region, making feature extraction susceptible to interference under conditions of pig posture changes, occlusion, or complex backgrounds, leading to decreased weight prediction accuracy.
[0007] Prior art 2 (CN120612362A) discloses a method for measuring the body size and weight of pigs based on RGB-D. This method requires three RGB-D cameras positioned directly above, to the left, and to the right of the area to be acquired. It obtains top-down, left-side, and right-side RGB-D images through multi-view acquisition, then performs point cloud registration to obtain a complete pig point cloud. Finally, a key point detection model is used to extract key points for body size measurement, and the body length, width, height, and abdominal circumference are calculated. This scheme relies on three depth cameras, resulting in high hardware costs and complex system deployment. It requires multi-view point cloud registration, which involves a large computational load, and registration errors accumulate, affecting the accuracy of body size measurement. Furthermore, the key points for body size measurement are directly predicted using a key point detection model of the RGB images, which can easily lead to positioning errors when the pig's head is lowered, back is bent, tail is bent, or obstructed, resulting in increased errors in body length and width measurement. In addition, this method does not utilize depth reliability information to guide the segmentation or measurement process, making it insufficiently robust when the depth map contains holes or noise.
[0008] Therefore, how to stably extract the pig body area using single-view RGB-D images in a real pigsty environment, and automatically and accurately calculate the pig's body length, width, and height without relying on multi-camera point cloud reconstruction and manual measurement point positioning, is a technical problem that urgently needs to be solved in the current smart pig farming body size measurement. Summary of the Invention
[0009] To address the technical problems mentioned in the background section, this invention provides a method for visually measuring the body size of pigs.
[0010] This invention is achieved using the following technical solution: A method for visually measuring the body size of pigs, comprising the following steps:
[0011] Step S1: Acquire a single-view RGB-D image of the pig to be tested. The RGB-D image includes a synchronized RGB image and a depth image. Perform spatial registration and invalid depth removal on the RGB image and the depth image. Perform scale normalization and pixel value normalization on the registered RGB image and perform effective depth range normalization on the registered depth image to obtain a standardized RGB-D input tensor.
[0012] Step S2: Input the standardized RGB-D input tensor into the pre-built reliability-guided RGB-D pig body segmentation model to obtain a binary mask of the pig body;
[0013] Step S3: Extract the skeleton from the binary mask of the pig body to obtain the central skeleton of the pig body and construct the skeleton map; perform principal axis modeling on the binary mask of the pig body to obtain the principal axis direction of the pig body; divide the skeleton endpoints into head and neck side endpoints and tail side endpoints according to the projection values of the skeleton endpoints on the principal axis direction; locate the neck feature points in the head and neck side region and select the initial rear end candidate points in the tail side endpoints; then perform adaptive tail root correction on the initial rear end candidate points to obtain the corrected rear end feature points;
[0014] Step S4: Extract the shortest skeleton path between the neck feature points and the corrected back end feature points as the body length path, back-project the pixels on the body length path into three-dimensional points, compensate for the path points with missing depth by interpolation or local neighborhood median depth, and accumulate the Euclidean distance between adjacent three-dimensional points to obtain the pig body length.
[0015] Step S5: Select multiple body width sampling points along the body length path, estimate the local normal direction for each sampling point, search the binary mask boundary of the pig body along the normal direction to obtain the boundary points on both sides, calculate the local width based on the three-dimensional back projection coordinates of the boundary points on both sides, and select the maximum effective width among all local widths as the pig body width;
[0016] Step S6: Backproject the effective depth pixels within the binary mask of the pig body into a point cloud of the pig body. Extract the candidate ground point cloud from the candidate ground region outside the binary mask of the pig body, fit the ground plane from the candidate ground point cloud, calculate the distance from the pig body point cloud to the ground plane, and obtain the height of the pig body.
[0017] Furthermore, in step S2, the reliability-guided RGB-D pig segmentation model includes: an RGB encoding module, a deep encoding module, an RGB-D fusion module, a deep quality estimation module, a deep-guided cross-modal attention module, a decoder, and an adaptive gated inference module.
[0018] The RGB encoding module is used to extract the appearance, color, texture and contour continuity features of the pig from the RGB image, and output multi-scale RGB feature maps;
[0019] The depth encoding module is used to extract the undulations, spatial distances, and geometric boundary features of the pig's back from the depth image, and outputs a multi-scale depth feature map;
[0020] The RGB-D fusion module is used to perform cross-modal fusion of RGB feature maps and depth feature maps at multiple feature scales to generate a fused feature map;
[0021] The depth quality estimation module is used to generate a depth reliability map; the depth reliability map is used to characterize the reliability of the depth information of each pixel in the depth image.
[0022] Furthermore, the deep-guided cross-modal attention module is used for:
[0023] At multiple selected feature scales, the RGB feature map output by the RGB encoding module is mapped to query features, and the deep feature map output by the deep encoding module is mapped to key features and value features.
[0024] Then, the attention weights are calculated based on the similarity between the query features and the key features. The value features are then weighted and summed using the attention weights to obtain the deep enhancement features.
[0025] The depth enhancement features are projected to the same channel dimension as the RGB feature map and multiplied element-wise with the depth reliability map adjusted to the same scale to obtain the reliability-gated depth enhancement features;
[0026] The reliability-gated depth enhancement features are injected into the RGB feature map as residuals.
[0027] Furthermore, the adaptive gated inference module is used for:
[0028] The absolute difference between the first segmentation probability map output by the decoder corresponding to the RGB encoding module and the second segmentation probability map output by the decoder corresponding to the RGB-D fusion module is used as the prediction difference map. The reliable prior of the prediction layer depth output by the decoder and the prediction difference map are adjusted to the same resolution and then stitched together.
[0029] The concatenated features are input into a gating network, which outputs an adaptive gating graph.
[0030] The first and second segmentation probability maps are weighted and fused pixel by pixel based on the adaptive gating map to output the final segmentation probability map. The final segmentation probability map is then thresholded and connected component filtered to obtain a pig body binary mask.
[0031] Specifically, when the gate value is large, the weight of the second segmentation probability map is increased; when the gate value is small, the weight of the first segmentation probability map is increased.
[0032] Furthermore, in step S3, the skeleton extraction includes: retaining the largest connected component of the pig body binary mask, performing morphological smoothing, and then skeletonizing to obtain a single-pixel-width pig body central axis skeleton; constructing an undirected skeleton graph and identifying skeleton endpoints and branch points based on node degree; and principal axis modeling by performing principal component analysis or ellipse fitting on the pig body binary mask to obtain the mask centroid and principal axis direction.
[0033] Furthermore, in step S3, the neck feature point is located as follows: in the head and neck side region, the skeleton branch point closest to the mask centroid is selected as the neck feature point; the initial rear end candidate point is the endpoint farthest from the mask centroid among the tail side endpoints.
[0034] Furthermore, in step S3, the adaptive tail root correction specifically includes:
[0035] Extract the shortest skeleton path between the initial back-end candidate points and the neck feature points;
[0036] The tail expansion radius is adaptively determined based on the pig body mask area, and expansion is only performed on the local tail path that is close to the initial rear candidate point.
[0037] Detect whether the bloated area exceeds the boundary of the pig's binary mask. If it does, the corresponding tail skeleton node is determined to be an unreliable node and deleted from the skeleton graph.
[0038] After deletion, the tail side endpoints are re-identified to obtain the corrected rear end feature points;
[0039] The tail-end expansion radius is determined as follows: ,in, This indicates the area of the refined pig carcass mask. Indicates the tail-end expansion coefficient. For the minimum expansion radius, This represents the maximum expansion radius.
[0040] Furthermore, in step S5, estimating the local normal direction includes:
[0041] Principal component analysis is performed within a local window composed of adjacent skeleton path points at each body width sampling point to obtain the local tangential and normal directions.
[0042] The body length path is divided into multiple body segments. Within each body segment, outliers in the local width are removed using either the interquartile range rule or the median absolute deviation rule. Then, the maximum effective width is selected as the pig's body width.
[0043] Furthermore, in step S6, the candidate ground region includes the outer ring region at a preset pixel distance from the boundary of the pig body binary mask and / or the far depth region at the bottom of the image; the extraction conditions for the ground candidate point cloud are: the depth value is within the effective depth range, the reliability value in the depth reliability map is not less than the preset reliability threshold, the local effective depth integrity rate is not less than the preset integrity rate threshold, and the depth gradient magnitude does not exceed the preset gradient threshold; the ground plane is fitted using the RANSAC algorithm; the pig body height is the upper quantile height statistic within the stable center region of the pig body.
[0044] Furthermore, step S7 is included: performing steps S2 to S6 on multiple valid RGB-D images of the same pig, calculating weights based on the average depth reliability, effective depth integrity rate, and depth variation coefficient of the mask region of each image, performing weighted fusion, and obtaining the final measurement results of body length, body width, and body height.
[0045] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0046] This invention requires only a single RGB-D depth camera to automatically measure the length, width, and height of pigs, eliminating the need for multi-camera synchronization, fixed measurement channels, and point cloud registration. This significantly reduces hardware costs and deployment complexity, making it suitable for ordinary pigsty environments. By generating a depth reliability map through a depth quality estimation module and employing a reliability-gated cross-modal attention mechanism, it can selectively enhance reliable depth geometry and suppress unreliable depth noise when the depth map contains holes, reflection noise, or local missing information. This allows the segmentation model to obtain high-quality pig body masks even under conditions of fence occlusion, lighting changes, and complex backgrounds.
[0047] This invention extracts the skeleton and models the principal axis under the constraint of a pig's body mask. It locates neck feature points through skeleton topology and projection analysis, avoiding the direct use of unstable contour extrema or local key points, thus improving the robustness of body size measurement reference point localization. An adaptive tail root correction strategy detects expansion and overflow areas in the local path of the tail end, removing unreliable skeleton nodes caused by tail bending or boundary adhesion. This allows body length measurements to accumulate along the corrected 3D skeleton path, more closely approximating the true trunk length and effectively reducing the impact of tail bending and posture changes on body length. A local PCA normal section search method is used to calculate body width, adaptively determining the measurement section based on the actual trunk direction of the pig. Body segmentation and outlier removal effectively reduce interference from leg protrusions, fence obstructions, and boundary burrs on body width measurement. The RANSAC algorithm is used to fit the ground plane, combined with the upper quantile height statistics of the stable center region of the pig to calculate body height, effectively suppressing the influence of local depth noise, ground unevenness, and isolated outliers on body height estimation.
[0048] This invention performs weighted fusion of multiple valid RGB-D images of the same pig, dynamically assigning weights based on mask reliability, depth integrity, and depth variation coefficient to reduce measurement fluctuations caused by single-frame pose changes, skeletal jitter, and depth noise, thereby improving measurement repeatability. This invention achieves fully automated non-contact body size measurement, eliminating the need for human contact with the pig, avoiding animal stress, reducing the safety risks of human-animal contact, and providing reliable data support for precision feeding, growth monitoring, weight estimation, and intelligent farming management. Attached Figure Description
[0049] Figure 1 The overall flowchart of the non-contact measurement method for pig body size provided in the embodiments of the present invention is shown.
[0050] Figure 2 This is a schematic diagram of the Pig-D3Net pig segmentation model structure based on reliability guidance provided in an embodiment of the present invention.
[0051] Figure 3This is a schematic diagram of a segmentation network structure based on an RGB-D fusion module provided in an embodiment of the present invention.
[0052] Figure 4 A schematic diagram of a segmentation network structure based on RGB branch and Depth branch provided for an embodiment of the present invention.
[0053] Figure 5 This is a schematic diagram of the adaptive tail root correction process provided in an embodiment of the present invention; wherein, Figure 5 Part (a) is a schematic diagram of the skeletal path from the tail to the neck before correction. Figure 5 Part (b) is a schematic diagram of boundary compensation based on tail expansion. Figure 5 Part (c) is a schematic diagram showing the superposition of the expansion region and the overflow region. Figure 5 Part (d) is a schematic diagram of the overflow region induced by tail expansion. Figure 5 Part (e) is a schematic diagram of the morphological closing operation processing of the overflow region. Figure 5 Part (f) is a schematic diagram of the tail endpoint update after skeleton correction.
[0054] Figure 6 The diagram illustrates body length measurement based on a corrected skeleton path and body width measurement based on a normal section, as provided in embodiments of the present invention; wherein, Figure 6 Part (a) is a schematic diagram of extracting body width sampling points along the length path of the pig's body. Figure 6 Part (b) is a schematic diagram of tangent and normal estimation based on local principal component analysis. Figure 6 Part (c) is a schematic diagram of normal outlier removal within eight pig body segments. Figure 6 Part (d) is a schematic diagram for determining the final body length broken line and the maximum body width line.
[0055] Figure 7 This is a schematic diagram of pig body height measurement based on RANSAC ground plane fitting, provided as an embodiment of the present invention. Detailed Implementation
[0056] The present invention will now be described in further detail with reference to the accompanying drawings. It should be understood that the following embodiments are for illustrative purposes only and are not intended to limit the scope of protection of the present invention. Where there is no conflict, the embodiments and technical features in the embodiments of the present invention can be combined with each other. This embodiment uses non-contact measurement of the body length, body width, and body height of Large White pigs in the fattening stage as an example for illustration.
[0057] Reference Figure 1 - Figure 7This invention proposes a visual measurement method for pig body size based on reliability-guided RGB-D segmentation and geometric constraints. This method utilizes appearance and depth geometric information from single-view RGB-D images to obtain a high-quality pig body mask through a reliability-guided RGB-D pig body segmentation model. Then, under mask constraints, it combines skeletal topology, principal axis modeling, adaptive tail root correction, normal section width search, and RANSAC ground plane fitting to achieve automatic measurement of pig body length, width, and height. Figure 1 The overall flow of this method is shown. Figure 2 This diagram illustrates the structure of the Pig-D3Net pig segmentation model based on reliability guidance. Figure 3 A schematic diagram of a segmentation network structure based on an RGB-D module is shown. Figure 4 The diagram shows the segmentation network structure for the RGB encoding branch and the Depth encoding branch. Figure 5 The adaptive tail root correction process is shown. Figure 6 The process of calculating body length and body width is shown. Figure 7 The process of body height measurement based on point cloud denoising and RANSAC ground plane fitting is shown. The detailed implementation process is as follows.
[0058] I. Image Acquisition and Preprocessing
[0059] In this scheme, a single-view RGB-D image acquisition system is first established. Specifically, an RGB-D depth camera is placed above the pig, so that the camera's field of view covers the back area of a single pig, acquiring simultaneous RGB and depth images. During the acquisition process, only one pig is imaged at a time to avoid interference from multiple targets. In this preferred embodiment, the experimental subjects are large white pigs in the fattening stage, and an Orbbec Femto Bolt RGB-D depth camera is used. The operator places the camera above the pig using an extension bracket, ensuring that the pig's back and torso are fully within the field of view, and observes the RGB image, depth image, and pig segmentation results in real time using computing equipment. The acquisition scenario is an actual pigsty environment, which contains interference such as fences, the ground, feed lines, pigpen boundaries, and background noise.
[0060] Next, the acquired RGB and depth images are preprocessed. Specifically, the RGB and depth images are spatially registered, zero values, holes, and abnormal depth values in the depth image are removed, the RGB images are scaled and pixel normalized, and the depth images are normalized according to the effective depth range to obtain RGB-D image pairs, which serve as input data for the subsequent Pig-D3Net segmentation model. In this embodiment, the effective depth pixel set is determined according to equation (1) and a normalized depth map is generated.
[0061] (1)
[0062] p is the pixel coordinate, and D(p) is the depth map corresponding to the pixel. For the effective depth pixel set, For normalized depth maps, and These are the preset lower and upper limits of the effective depth, respectively. This indicates that the input depth value is limited to [ to Within the range; ε is a constant to prevent the denominator from being zero. It should be noted that the typical value of ε is 1 × 10⁻⁶. -6 The adjustable range is 1×10 -7 Up to 1×10 -5 When depth values are uniformly converted to meters, ε is preferably 1×10⁻⁶. -6 The acceptable range is 1×10 -7 Up to 1×10 -5 .
[0063] II. Construction and Training of the Pig-D3Net Segmentation Model
[0064] In this embodiment, a pig segmentation model guided by Pig-D3Net reliability needs to be constructed. Specifically, as follows... Figure 2 As shown, the Pig-D3Net pig segmentation model includes: an RGB encoding module, a deep encoding module, an RGB-D fusion module, a deep quality estimation network, a deep guided cross-modal attention module, a decoder, and an adaptive gated inference module.
[0065] In this embodiment, the encoding and fusion module performs the following:
[0066] The RGB encoding module is used to extract information on the pig's appearance, color, texture, and contour continuity; the depth encoding module is used to extract information on the undulations, spatial distance, and geometric boundaries of the pig's back; the RGB-D fusion module is used to perform cross-modal fusion of RGB features and depth features at multi-scale feature layers. In this embodiment, the encoding backbone network adopts VGG16, which contains five progressively downsampled encoding stages, with the number of output channels in each stage preferably being 64, 128, 256, 512, and 512; the input RGB image and depth image are spatially registered, uniformly scaled, and padded to a 384×384 pixel input network. The cross-modal fusion method preferably adopts channel attention or multi-head attention, with the number of attention heads ranging from 1 to 8, preferably 4; when using channel attention, it is equivalent to single-head channel weight fusion.
[0067] In this embodiment, the depth quality estimation module performs the following:
[0068] A depth reliability map is predicted or generated using a depth quality estimation module. The depth reliability map can be calculated from one or more of depth validity, local depth integrity, and depth gradient. Specifically, Sobel gradient calculation is first performed on the depth image to obtain the horizontal gradient, vertical gradient, and gradient magnitude map; then, the depth image, gradient magnitude map, and valid depth indicator map are stitched together and input into the depth quality estimation network. After Sigmoid activation, a depth reliability map with values ranging from 0 to 1 is output.
[0069] More specifically, the depth quality estimation module includes an input concatenation layer, a first convolutional block, a second convolutional block, a third convolutional block, and an output convolutional layer. The input concatenation layer concatenates the normalized depth map, the depth gradient magnitude map, and the effective depth indicator map along the channel dimension to form a three-channel input feature. The first convolutional block includes a convolutional layer with a kernel size of 3×3, a stride of 1, and padding of 1, a batch normalization layer, and a ReLU activation layer, with 16 output channels. The second convolutional block includes a convolutional layer with a kernel size of 3×3, a stride of 1, and padding of 1, a batch normalization layer, and a ReLU activation layer, with 32 output channels. The third convolutional block includes a convolutional layer with a kernel size of 3×3, a stride of 1, and padding of 1, a batch normalization layer, and a ReLU activation layer, with 16 output channels. The output convolutional layer is a 1×1 convolutional layer with 1 output channel, and is activated by a Sigmoid function to obtain a depth reliability map with values ranging from 0 to 1. Each of the above convolutional blocks does not change the spatial resolution of the input features. The depth reliability map is adjusted to the feature scale required by the cross-modal attention module through bilinear interpolation or average pooling.
[0070] As another preferred implementation, it can also be determined whether the normalized depth value is greater than ε, and 3×3 average pooling is used to calculate the effective depth ratio within the neighborhood as a depth reliability map. ε is used to avoid numerical instability caused by zero-value depth and zero denominator, and is preferably taken as 1×10. -6 The above process is implemented according to equations (2), (3) and (4).
[0071] (2)
[0072] (3)
[0073] (4)
[0074] in, and These are represented as Sobel horizontal and vertical operators, respectively; and These represent the horizontal and vertical depth gradients of the depth map, respectively. This is a depth gradient magnitude map; R is the effective depth indicator map, which is set to 1 when the corresponding pixel depth value is valid, and 0 otherwise; R is the depth reliability map, which ranges from 0 to 1. The larger the value, the more reliable the depth information of the corresponding area. This is a reliability graph after adjusting to the feature size at the S-th scale. For the Sigmoid function; and These represent the height and width of the S-th feature scale, respectively; This indicates a scale adjustment operation.
[0075] and These are the features of the RGB module and the depth module at the S-th scale, respectively; This represents query features in the attention mechanism; Indicates key features; Indicates value characteristics; , , , These represent learnable linear transformation weights or convolutional mapping weights, respectively. This indicates the feature pooling operation.
[0076] In this embodiment, the deep-guided cross-modal attention module performs the following:
[0077] The depth-guided cross-modal attention module employs a spatial cross-attention mechanism. At the s-th feature scale, the RGB features output by the RGB encoding module are mapped to query features, and the depth features output by the depth encoding module are mapped to key and value features. Attention weights are obtained based on the similarity between the query and key features, and then the value features are weighted and summed using these attention weights to obtain the depth-enhanced features. Subsequently, the depth-enhanced features are projected to the same channel dimension as the RGB features and multiplied element-wise with a depth reliability map adjusted to the same scale to obtain the reliability-gated depth-enhanced features. Finally, the reliability-gated depth-enhanced features are injected into the RGB features as residuals. This approach enhances depth geometry when the depth map is locally complete and has continuous boundaries, and suppresses unreliable depth responses when holes, noise, or occlusions exist in the depth map. As an optional implementation, cross-modal attention can also employ a channel attention mechanism, generating channel weights from depth features and recalibrating the RGB features.
[0078] In this embodiment, the adaptive gated inference module performs the following:
[0079] In one implementation, the adaptive gating inference module includes a spatial alignment unit, a feature stitching unit, a gating network, and a probabilistic fusion unit. The spatial alignment unit adjusts the prediction difference map and the reliable prior for prediction layer depth to the same spatial resolution as the segmentation probability map. The feature stitching unit stitches the adjusted prediction difference map and the reliable prior for prediction layer depth along the channel dimension. The gating network includes a 3×3 convolutional layer, a ReLU activation layer, a 1×1 convolutional layer, and a Sigmoid activation function, outputting an adaptive gating map with values ranging from 0 to 1. The probabilistic fusion unit performs pixel-wise weighted fusion of the RGB-D fusion module prediction and the RGB module prediction based on the adaptive gating map. When the gating value is large, the weight of the RGB-D fusion module prediction is increased; when the gating value is small, the weight of the RGB module prediction is increased, thereby reducing the impact of unreliable depth information on the final pig mask.
[0080] In this embodiment, the multi-module collaborative training and loss function execution are as follows:
[0081] During the training phase, each module is supervised using manually labeled pig body masks. The segmentation loss is preferably a combination of binary cross-entropy loss and Dice loss. The total loss includes RGB module loss, Depth module loss, RGB-D fusion module loss, consistency loss, and gating loss. The core parameters are selected within the following ranges: the typical value of the segmentation binarization threshold τ is 0.5, and the adjustable range is 0.4 to 0.6; τ is increased when there are many false positives in the background and decreased when there are many missed detections at the pig body edges.
[0082] In this embodiment, the consistency loss weight is set to 0.2 (range 0.05 to 0.5), and the gating loss weight is set to 0.5 (range 0.1 to 1.0). Training parameters are selected within the following ranges: input size can be 320×320 to 640×640 pixels, preferably 384×384 pixels; training batch size can be 2 to 8, preferably 4; the optimizer uses Adam (AdamW or SGD can also be used); the initial learning rate can be 1×10⁻⁶. -5 Up to 1×10 -4 Preferably 1×10 -4 The number of training rounds can be between 100 and 300, with 150 being the preferred number; the weight decay coefficient can be 1×10. -6 Up to 1×10 -4 Preferably 1×10 -4 The preferred learning rate scheduling method is cosine annealing, and the preferred minimum learning rate is 1×10⁻⁶. -6 .
[0083] During training, geometric enhancements are performed simultaneously on RGB images, depth images, and manually labeled masks, including random horizontal flipping (probability 0.5), random vertical flipping (probability 0.2), random rotation (angle range ±20°), and random scaling (range 0.80 to 1.25). Color and noise enhancements are performed separately on the RGB images, including brightness perturbation (amplitude 0.25), contrast perturbation (amplitude 0.25), saturation perturbation (amplitude 0.20), hue perturbation (amplitude 12), Gaussian blur (probability 0.20), and Gaussian noise (probability 0.20, standard deviation range 3.0 to 10.0). After each training epoch, the Intersection over Union (IoU), mean IoU (mIoU), Dice coefficient, precision, recall, F1 score, and accuracy are calculated on the validation set, and the model parameters are saved using IoU as the optimal model selection metric.
[0084] As a preferred embodiment of the Pig-D3Net network training and inference parameters, this scheme is implemented using the PyTorch deep learning framework. The original RGB and depth images are 1280×800 pixels in size, which are converted to a network input size of 384×384 by proportional scaling and boundary padding before training and inference. The RGB images are normalized using ImageNet mean and standard deviation, with a mean of [0.485, 0.456, 0.406] and a standard deviation of [0.229, 0.224, 0.225]. The depth image is spatially registered with the RGB image, and depth validity is determined and normalized. The depth reliability map is obtained from the valid depth indicator map through 3×3 average pooling, with an average pooling stride of 1 and padding of 1.
[0085] It should be noted that during the inference phase, a pig body segmentation probability map is output, and a binary mask for the pig body is obtained through thresholding and connected component filtering. Specifically, the inference phase fuses RGB prediction and RGB-D prediction using a quality-difference joint gating strategy: the gating network takes the depth reliability map and the prediction difference map as input and outputs an adaptive gating map; when the gating value is large, RGB-D fusion prediction is used more, and when the gating value is small, RGB prediction is used more. The binarization threshold τ is preferably 0.5, but can also be adjusted within the range of 0.4 to 0.6 based on the segmentation effect on the validation set. The gating network input includes the depth reliability map and the prediction difference map, where the prediction difference map is the absolute difference between the predictions of the RGB-D fusion module and the RGB module. The gating network outputs an adaptive gating map, which is constrained to maintain consistency with the depth reliability map through binary cross-entropy.
[0086] The specific calculations for the above process are performed according to equations (5), (6) and (7).
[0087] (5)
[0088] (6)
[0089] (7)
[0090] in, To deeply guide cross-modal attention output, Here, ⊙ represents the learnable scale coefficient, and Y represents the manually labeled mask. This represents the probability map of pig segmentation output by the model. Indicates the segmentation loss; This represents the binary cross-entropy loss; This represents the summation of the predicted probability map and the manually labeled mask pixel by pixel; and These represent the pixel-wise summation of the predicted probability map and the manually labeled mask, respectively; and These are the predictions from the RGB module and the RGB-D fusion module, respectively. A is the prediction difference map, which is preferably obtained from the absolute difference between the predictions from the RGB-D fusion module and the RGB module. To provide a reliable prior for predicting layer depth, For adaptive gating graphs, This is the binarization threshold.
[0091] III. Mask Refinement and Skeleton Modeling
[0092] This scheme requires mask refinement and skeleton extraction of the pig body binary mask. Specifically, the largest connected component is retained to remove small false detection areas, morphological smoothing is performed to weaken boundary burrs and local holes, and the refined pig body mask is skeletonized to obtain a pig body midline skeleton with a single pixel width. This process is implemented according to equation (8).
[0093] (8)
[0094] In equation (8), MaxCC represents maximum connectivity preservation, and Open and Close represent morphological opening and closing operations, respectively. Let S be a structuring element with radius r, and S be a skeleton of single-pixel width. Morphological opening and closing operation structuring element. The radius r can be taken as 1 to 5 pixels, with a typical value of 3 pixels; it can be appropriately increased when the image resolution is high or there are many edge burrs.
[0095] Next, a pig skeleton graph is constructed and principal axis modeling is performed. Specifically, an undirected skeleton graph is constructed using skeleton pixels as nodes and eight-neighbor connections as edges. The endpoints and branch points of the skeleton are identified based on the node degree, and ellipse fitting or principal component analysis is performed on the pig mask to obtain the centroid and principal axis direction of the pig mask. Specifically, skeleton nodes with a node degree of 1 can be used as endpoints, and skeleton nodes with a node degree greater than 2 can be used as branch points. This process is implemented according to equations (9) and (10).
[0096] (9)
[0097] (10)
[0098] In the above formula, This is a skeleton graph, where V is the set of skeleton pixel nodes, E is the set of eight-neighbor edges, and c is the mask centroid. The mask pixel covariance matrix, This refers to the direction of the pig's main axis.
[0099] Furthermore, the neck and posterior feature points are located. Specifically, based on the projection values of the skeleton endpoints along the principal axis, the skeleton endpoints are divided into head-neck side endpoints and tail-side endpoints. In the head-neck side region, the skeleton branch point closest to the mask centroid is selected as the neck feature point to avoid interference from local branches of the head, ears, or anterior end on the body length starting point. In the tail-side endpoints, the endpoint farthest from the mask centroid is selected as the initial posterior candidate point. This process is implemented according to Equation (11).
[0100] (11)
[0101] Where ρ(v) is the projection of the skeleton point onto the principal axis. Represents the skeleton nodes in the skeleton diagram; For the set of points on the head and neck side modules, For the set of tail lateral endpoints, For neck feature points, These are the initial backend candidate points.
[0102] IV. Adaptive Tail Root Correction
[0103] This scheme also requires adaptive tail root correction. Specifically, such as... Figure 5 As shown, the shortest skeleton path between the initial back end candidate points and the neck feature points is first extracted to form the tail-to-neck skeleton path before correction, as follows. Figure 5 As shown in part (a). Subsequently, the tail expansion radius is adaptively determined based on the pig's body mask area, and expansion is performed only on the local tail path near the initial rear candidate point, as shown in... Figure 5 As shown in part (b), the expansion radius is determined according to equation (12).
[0104] (12)
[0105] in, The tail expansion radius adapts to the pig's body area. This represents the area of the refined pig body mask, i.e., the number of pig body pixels in the mask; The value represents the tail-end expansion coefficient, which can be from 0.003 to 0.008, preferably 0.005; The minimum expansion radius can be 3 to 8 pixels, with 5 pixels being the preferred value; The maximum expansion radius can be 15 to 35 pixels, preferably 25 pixels. The local path length at the tail end is γ times the body length path length, where γ can be 0.05 to 0.15, preferably 0.10, to limit expansion detection to local skeleton paths near the tail end and avoid accidentally deleting normal torso skeletons.
[0106] After expanding the local path at the tail end, it is further detected whether the expanded area exceeds the boundary of the refined pig body mask. Specifically, the superposition of the expanded area and the overflow area is displayed as follows: Figure 5 As shown in section (c), the overflow region induced by tail expansion is as follows Figure 5 As shown in part (d), the result of the overflow region after morphological closing operation is as follows: Figure 5 As shown in section (e). If a significant overflow area exists, the corresponding tail-tip skeletal nodes, tail-bend nodes, or boundary-adhesive skeletal nodes are identified as unreliable nodes and removed from the skeleton graph; if no significant overflow area exists, the original initial rear-end candidate points are retained. After deleting unreliable nodes, the tail-side endpoints are re-identified, and the skeleton-corrected rear-end feature points are obtained, as shown in section (e). Figure 5 The process described above is carried out according to equations (13) and (14).
[0107] (13)
[0108] (14)
[0109] in, This is the tail-end path expansion region. To go beyond the overflow area of the refinement mask, These are unreliable tail skeleton nodes to be deleted. To correct the back-end feature points; This represents the projection value of the candidate endpoint on the tail side along the main axis of the pig's body. If the overflow area... If the area or length of a connected component exceeds a preset threshold, the corresponding tail skeleton node will be determined as an unreliable node and deleted.
[0110] V. Calculation of Body Length, Width, and Height
[0111] In this embodiment, the effective depth pixels within the refined mask are back-projected into a 3D point cloud based on camera intrinsic parameters. The pig's body length, width, and height are then calculated using a corrected skeleton path, normal section search, and ground plane constraints. In this embodiment, the focal length and principal point coordinates used for camera calibration are: , , , .
[0112] In this embodiment, the body length calculation process is as follows:
[0113] The body length of the pig is calculated based on the corrected skeleton path. The shortest skeleton path between the neck feature points and the corrected rear feature points is extracted and used as the body length path of the pig's torso. For each pixel on the path, it is back-projected into a 3D point based on the camera intrinsic matrix and the corresponding depth value; for a small number of path points with missing depth, interpolation of adjacent valid path points or local neighborhood median depth is used for compensation.
[0114] Specifically, the depth values of each path point are sequentially detected along the body length path. When the depth value of a path point is zero, exceeds the effective depth range, or the corresponding depth reliability is lower than a preset reliability threshold, the path point is identified as a path point with missing depth. For missing segments with 3 or fewer consecutive missing path points, if there are effective path points before and after the missing segment, linear interpolation compensation is performed based on the depth values of the effective path points before and after the missing segment; if there are effective path points on only one side of the missing segment, the depth value of the nearest neighbor effective path point is used for compensation. For missing segments with more than 3 consecutive missing path points, effective depth pixels are searched within the 5×5 neighborhood of the missing path point, and the median of the effective depth pixels is used as the compensation depth; when the number of effective depth pixels in the 5×5 neighborhood is insufficient, the search window is expanded to 7×7 or 11×11. If sufficient effective depth pixels cannot be obtained after expanding the window, the frame is marked as a low-reliability frame, or the measurement weight of the frame is reduced during multi-frame fusion.
[0115] Finally, the Euclidean distances between adjacent three-dimensional path points are summed to obtain the pig's body length. This body length is not a simple two-dimensional contour distance, but is obtained by summing along the corrected three-dimensional skeleton path, which can reduce measurement errors caused by back bending, slight posture changes, and tail interference. This process is implemented according to equation (15).
[0116] (15)
[0117] Where K is the camera intrinsic parameter matrix; K is the camera intrinsic parameter matrix; These are the camera focal lengths, Principal point coordinates; is a 3D point after pixel backprojection; L is the volume length.
[0118] In this embodiment, the body width calculation process is as follows:
[0119] The body width of a pig is calculated based on a local PCA normal section search. For example... Figure 6 As shown in part (a), multiple body width sampling points are uniformly selected along the corrected body length path. For each sampling point, principal component analysis is performed within a local window composed of its adjacent skeleton path points to estimate the local tangential and normal directions at that location, as shown in part (a). Figure 6 As shown in part (b). In the local PCA normal estimation, the skeleton neighborhood window radius k can be 3 to 10 skeleton sampling points, preferably 5. Then, with this sampling point as the center, the refined pig body mask boundary is searched along the positive and negative normal directions to obtain the boundary points on both sides of the normal, and the local width is calculated based on the three-dimensional back projection coordinates of the boundary points on both sides. To improve the robustness of body width measurement, this embodiment preferably divides the body length path into 6 to 12 body segments, preferably 8 body segments, and outliers in the local width are removed within each body segment, such as... Figure 6 As shown in section (c). After removing abnormal widths caused by fence obstruction, boundary burrs, local leg protrusions, or segmentation errors, the maximum effective width is selected as the pig's body width from the effective width set.
[0120] In one implementation, outlier removal employs the interquartile range (IQR) rule. For a set of local widths obtained within the same body segment, the first quartile Q1, the third quartile Q3, and the IQR are calculated, where IQR = Q3 - Q1. Local width values less than Q1 - 1.5 × IQR or greater than Q3 + 1.5 × IQR are identified as outliers and removed. Alternatively, the median absolute deviation rule can be used for outlier removal; when the deviation between a local width value and the median local width of the body segment exceeds a preset multiple of the median absolute deviation, it is identified as an outlier. After outlier removal, the maximum value among the remaining effective local widths of all body segments is selected as the pig's body width. The final body length line and the maximum body width line are shown below. Figure 6 The process is shown in part (d). The process is carried out according to equation (16).
[0121] (16)
[0122] in, This represents the projection matrix parallel to the ground plane. and These are the local tangential and normal directions of the skeleton, respectively. and These represent the boundary points of the pig body mask obtained by searching along the positive and negative local normal directions, respectively.
[0123] In this embodiment, the body height calculation process is as follows:
[0124] Pig body height was calculated based on point cloud denoising and RANSAC ground plane fitting. For example... Figure 7 As shown, firstly, the effective depth pixels within the pig body binary mask are back-projected into a pig body point cloud based on camera intrinsic parameters. Then, outliers in the pig body point cloud are statistically removed to reduce the impact of isolated depth noise on body height calculation. Subsequently, candidate ground regions are extracted outside the pig body binary mask. These candidate ground regions include an outer ring region at a preset pixel distance from the boundary of the pig body binary mask and / or a far-depth region at the bottom of the image. The outer ring region can be obtained by performing a distance transformation on the pig body binary mask; the preset pixel distance can be 10 to 80 pixels, preferably 15 to 60 pixels. For pixels within the candidate ground regions, pixels whose depth values are within the effective depth range, whose reliability values in the depth reliability map are not less than a preset reliability threshold, whose local effective depth integrity rate is not less than a preset integrity rate threshold, and whose depth gradient magnitude does not exceed a preset gradient threshold are retained as ground candidate pixels. The preset reliability threshold can be 0.5 to 0.8, preferably 0.6, and the preset integrity rate threshold can be 0.6 to 0.9, preferably 0.7. Ground candidate pixels are back-projected into 3D points to obtain a ground candidate point cloud, and the RANSAC algorithm is used to fit the ground plane. Finally, the vertical distance from each point in the pig body point cloud to the ground plane is calculated, and the upper quantile height statistic is selected as the pig body height within the stable center region of the pig body. For example, the height statistics between the 90th and 98th percentiles are taken, where the upper quantile statistic... The value of q can be between 0.90 and 0.98, with 0.95 being preferred. The body height measurement line is the vertical distance from the stable height point of the pig's body to the fitted ground plane. This process is carried out according to equation (17).
[0125] (17)
[0126] in, and Here are the ground plane parameters obtained from RANSAC fitting, where H is the body height. This is the upper quantile statistic.
[0127] Furthermore, this scheme can also perform multi-frame weighted fusion and output. Specifically, the above operations are performed on multiple effective RGB-D images of the same pig, and weighted fusion is performed based on mask reliability, depth integrity rate, and single-frame measurement stability to obtain the final body size measurement result. For the same pig to be tested, multiple effective RGB-D images are continuously acquired, and the aforementioned steps are performed respectively to obtain the body length, body width, and body height corresponding to each frame. For each frame, the average depth reliability, effective depth integrity rate, and depth variation coefficient of the mask area are calculated, and the weight of the frame is determined according to equation (18).
[0128] (18)
[0129] Frames with high mask reliability, high effective depth integrity, and small depth fluctuations are assigned higher weights; frames with severe depth loss, large changes in pig posture, or significant fluctuations in measurement results are assigned lower weights or are discarded. In equation (18), Let the weight be the weight of the j-th frame. The average depth reliability within the pig body mask area of this frame; For effective depth integrity, This is the depth variation coefficient for that frame. The body size measurement value for the j-th frame. The image shows the body size results after multi-frame fusion. Finally, the body length, body width, and body height were weighted and fused separately to obtain the final body size measurement results for the pig.
[0130] Effect verification:
[0131] In some embodiments, multiple sets of RGB-D images were acquired. After screening, 203 valid RGB-D image pairs were used for training and testing the pig body segmentation model, including 182 sets for training and 21 sets for testing. An additional 350 sets of automatic body size measurement records were used to evaluate the accuracy of body size measurement. During training, manually labeled pig body masks were used as supervisory information; during inference, single-frame or consecutive multi-frame RGB-D images were directly input, eliminating the need for multi-camera synchronization, fixed measurement channels, or manually specified measurement points.
[0132] During implementation, the segmentation model was able to obtain a relatively stable pig body mask under conditions of pigpen fence obstruction, ground noise, and localized depth loss. During body size measurement, the automatic measurement results of body length, width, and height showed minimal error compared to manual reference measurements, indicating that the present invention can achieve non-contact automatic measurement of pig body size under actual pigpen conditions. The above experimental data and equipment model are only used to illustrate the feasible implementation methods and technical effects of the present invention and do not constitute a limitation on the scope of protection of the present invention.
[0133] Those skilled in the art will understand that although the above embodiments are illustrated using the measurement of pig body length, width, and height as examples, the reliability-guided RGB-D segmentation, skeleton path measurement, normal section search, and ground plane constraint method of the present invention can also be extended to non-contact measurement of other livestock or other linear body size parameters.
[0134] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for visual measurement of live pig body dimensions, characterized by, Includes the following steps: Step S1: Acquire a single-view RGB-D image of the pig to be tested. The RGB-D image includes a synchronized RGB image and a depth image. Spatial registration and invalid depth removal are performed on the RGB image and the depth image; scale normalization and pixel value normalization are performed on the registered RGB image, and effective depth range normalization is performed on the registered depth image to obtain a standardized RGB-D input tensor. Step S2: Input the standardized RGB-D input tensor into the pre-built reliability-guided RGB-D pig body segmentation model to obtain a binary mask of the pig body; Step S3: Extract the skeleton from the binary mask of the pig body to obtain the central skeleton of the pig body and construct the skeleton map; perform principal axis modeling on the binary mask of the pig body to obtain the principal axis direction of the pig body; divide the skeleton endpoints into head and neck side endpoints and tail side endpoints according to the projection values of the skeleton endpoints on the principal axis direction; locate the neck feature points in the head and neck side region and select the initial rear end candidate points in the tail side endpoints; then perform adaptive tail root correction on the initial rear end candidate points to obtain the corrected rear end feature points; Step S4: Extract the shortest skeleton path between the neck feature points and the corrected back end feature points as the body length path, back-project the pixels on the body length path into three-dimensional points, compensate for the path points with missing depth by interpolation or local neighborhood median depth, and accumulate the Euclidean distance between adjacent three-dimensional points to obtain the pig body length. Step S5: Select multiple body width sampling points along the body length path, estimate the local normal direction for each sampling point, search the binary mask boundary of the pig body along the normal direction to obtain the boundary points on both sides, calculate the local width based on the three-dimensional back projection coordinates of the boundary points on both sides, and select the maximum effective width among all local widths as the pig body width; Step S6: Backproject the effective depth pixels within the binary mask of the pig body into a point cloud of the pig body. Extract the candidate ground point cloud from the candidate ground region outside the binary mask of the pig body, fit the ground plane from the candidate ground point cloud, calculate the distance from the pig body point cloud to the ground plane, and take the upper quantile statistic as the height of the pig body.
2. The method of claim 1, wherein, In step S2, the reliability-guided RGB-D pig segmentation model includes: an RGB encoding module, a deep encoding module, an RGB-D fusion module, a deep quality estimation module, a deep-guided cross-modal attention module, a decoder, and an adaptive gated inference module; The RGB encoding module is used to extract the appearance, color, texture and contour continuity features of the pig from the RGB image, and output multi-scale RGB feature maps; The depth encoding module is used to extract the undulations, spatial distances, and geometric boundary features of the pig's back from the depth image, and outputs a multi-scale depth feature map; The RGB-D fusion module is used to perform cross-modal fusion of RGB feature maps and depth feature maps at multiple feature scales to generate a fused feature map; The depth quality estimation module is used to generate a depth reliability map; the depth reliability map is used to characterize the reliability of the depth information of each pixel in the depth image.
3. The method according to claim 2, characterized in that, The deep-guided cross-modal attention module is used for: At multiple selected feature scales, the RGB feature map output by the RGB encoding module is mapped to query features, and the deep feature map output by the deep encoding module is mapped to key features and value features. Then, the attention weights are calculated based on the similarity between the query features and the key features. The value features are then weighted and summed using the attention weights to obtain the deep enhancement features. The depth enhancement features are projected to the same channel dimension as the RGB feature map and multiplied element-wise with the depth reliability map adjusted to the same scale to obtain the reliability-gated depth enhancement features; The reliability-gated depth enhancement features are injected into the RGB feature map as residuals.
4. The method according to claim 2, characterized in that, The adaptive gated inference module is used for: The absolute difference between the first segmentation probability map output by the decoder corresponding to the RGB encoding module and the second segmentation probability map output by the decoder corresponding to the RGB-D fusion module is used as the prediction difference map. The reliable prior of the prediction layer depth output by the decoder and the prediction difference map are adjusted to the same resolution and then stitched together. The concatenated features are input into a gating network, which outputs an adaptive gating graph. The first and second segmentation probability maps are weighted and fused pixel by pixel based on the adaptive gating map to output the final segmentation probability map. The final segmentation probability map is then thresholded and connected component filtered to obtain a pig body binary mask. Specifically, when the gate value is large, the weight of the second segmentation probability map is increased; when the gate value is small, the weight of the first segmentation probability map is increased.
5. The method according to claim 1, characterized in that, In step S3, skeleton extraction includes: retaining the largest connected component of the pig body binary mask, performing morphological smoothing, and then skeletonizing to obtain a single-pixel-width pig body midline skeleton; constructing an undirected skeleton graph and identifying skeleton endpoints and branch points based on node degree; principal axis modeling is performed by principal component analysis or ellipse fitting on the pig body binary mask to obtain the mask centroid and principal axis direction.
6. The method according to claim 5, characterized in that, In step S3, the neck feature points are located as follows: in the head and neck side region, the skeleton branch point closest to the mask centroid is selected as the neck feature point; the initial rear end candidate point is the endpoint farthest from the mask centroid among the tail side endpoints.
7. The method according to claim 6, characterized in that, In step S3, the adaptive tail root correction specifically includes: Extract the shortest skeleton path between the initial back-end candidate points and the neck feature points; The tail expansion radius is adaptively determined based on the pig body mask area, and expansion is only performed on the local tail path that is close to the initial rear candidate point. Detect whether the bloated area exceeds the boundary of the pig's binary mask. If it does, the corresponding tail skeleton node is determined to be an unreliable node and deleted from the skeleton graph. After deletion, the tail side endpoints are re-identified to obtain the corrected rear end feature points; The tail-end expansion radius is determined as follows: ,in, This indicates the area of the refined pig carcass mask. Indicates the tail-end expansion coefficient. For the minimum expansion radius, This represents the maximum expansion radius.
8. The method according to claim 1, characterized in that, In step S5, estimating the local normal direction includes: Principal component analysis is performed within a local window composed of adjacent skeleton path points at each body width sampling point to obtain the local tangential and normal directions. The body length path is divided into multiple body segments. Within each body segment, outliers in the local width are removed using either the interquartile range rule or the median absolute deviation rule. Then, the maximum effective width is selected as the pig's body width.
9. The method according to claim 1, characterized in that, In step S6, the candidate ground region includes the outer ring region at a preset pixel distance from the boundary of the pig body binary mask and / or the far depth region at the bottom of the image; the extraction conditions for the ground candidate point cloud are: the depth value is within the effective depth range, the reliability value in the depth reliability map is not less than the preset reliability threshold, the local effective depth integrity rate is not less than the preset integrity rate threshold, and the depth gradient magnitude does not exceed the preset gradient threshold. The ground plane was fitted using the RANSAC algorithm.
10. The method according to claim 1, characterized in that, The method also includes step S7: performing steps S2 to S6 on multiple effective RGB-D images of the same pig, calculating weights based on the average depth reliability, effective depth integrity rate and depth variation coefficient of the mask region of each image, performing weighted fusion, and obtaining the final measurement results of body length, body width and body height.