Pig key point detection and body size automatic measurement method based on difference-driven bimodal fusion network

By using a difference-driven dual-modal fusion network and leveraging RGB-D cameras and feature enhancement technology, efficient and accurate automatic measurement of pig body size was achieved. This solved the problems of low efficiency and insufficient robustness of manual contact measurement and adapted to changes in body size during pig growth.

CN123182268APending Publication Date: 2026-11-27HUAZHONG AGRI UNIV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202611485187.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-22
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing methods for measuring the body size of pigs mainly rely on manual contact measurement, which is inefficient, has poor repeatability, and is prone to causing stress to animals. Existing non-contact methods lack robustness and accuracy in complex environments.

Method used

A difference-driven dual-modal fusion network is adopted, which simultaneously acquires images and depth information through an RGB-D camera. A dual-stream feature extraction network is used for target detection and key point localization. The difference between RGB and Depth features is explicitly calculated, and the features are enhanced by WKCA wavelet-KAN channel attention and BVM bidirectional visual Mamba module to calculate the body size parameters of pigs.

Benefits of technology

It achieves non-contact, high-precision pig body size measurement, reduces manual labor intensity, improves robustness and key point positioning ability in complex environments, and adapts to changes in pig body size during growth.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123182268A_ABST
    Figure CN123182268A_ABST
Patent Text Reader

Abstract

The application discloses a pig key point detection and automatic body size measurement method based on a difference-driven bimodal fusion network, and comprises the following steps: S1. image acquisition, obtaining pig RGB images and corresponding depth images; S2. constructing a double-flow feature extraction network of an RGB branch and a Depth branch, extracting multi-scale RGB features and multi-scale Depth features; S3. a D2F difference-driven bimodal fusion module is used to perform channel alignment through convolution, calculate the element-by-element difference between the RGB and Depth features and take the difference as fusion driving information, after WKCA channel attention enhancement and BVM global spatial modeling, the information is fed back to the original bimodal features in a residual manner, and the fusion features are obtained after projection; S4. the fusion features are input into a positioning network to obtain a pig target frame and key point two-dimensional position, and then the key point two-dimensional position is mapped to a three-dimensional space through a depth camera model to obtain three-dimensional world coordinates; and S5. according to the three-dimensional world coordinates of the key points, the body size parameters of the pig are calculated. The application can realize contactless measurement, improve environmental robustness and key point positioning capability, and has high measurement 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 a method for detecting key points and automatically measuring body size in pigs based on a difference-driven dual-modal fusion network. Background Technology

[0002] In large-scale pig farming, body size parameters (such as body length, body width, body height, rump width, and rump height) are crucial indicators for assessing pig growth, health, and economic performance. They also provide significant reference value for breeding selection, feed formulation optimization, and market timing decisions. Currently, pig body size measurement primarily relies on manual contact methods, where farmers use measuring tapes, measuring sticks, and other tools to directly measure each item on the pig's body. This method is inefficient and unsuitable for the rapid inspection needs of large-scale farms. The repeatability of measurement results is significantly affected by the experience, operating techniques, and subjective judgment of the measurement personnel, resulting in poor data consistency. Furthermore, direct contact can easily cause stress reactions in pigs, affecting animal welfare and potentially leading to distorted measurement data or even personnel injury. Therefore, there is an urgent need for a non-contact, automated method for measuring pig body size in large-scale farming environments.

[0003] With the development of computer vision and depth perception technologies, vision-based non-contact body size measurement methods have gradually become a research hotspot. Patent CN121810765A describes a method and system for measuring pig body size based on multimodal data fusion. This method uses multi-view synchronous acquisition of local point cloud and image data of the pig's body, utilizing image and 3D spatial information to measure the pig's body size and obtain key points. However, the multi-view 3D point cloud solution requires multiple complex steps such as precise synchronization of multiple devices, point cloud denoising, registration, and 3D reconstruction. The data processing chain is long, and the computational overhead is high. When the pig moves, changes posture, or experiences partial occlusion, point cloud loss and model distortion easily occur, resulting in insufficient robustness and limiting real-time deployment capabilities.

[0004] Patent CN114973321B describes a method for selecting and measuring feature points in visual measurement of pig body size. It uses the YOLO architecture model to perform target detection and key point localization on monocular RGB images and calculates body size parameters based on geometric constraints in the two-dimensional image. However, the monocular RGB scheme mainly relies on color, texture, and appearance information. When affected by changes in lighting, occlusion, background interference, or local texture loss, the discriminative features near the key points are weakened, and positioning drift is likely to occur, thus affecting the accuracy of body size measurement.

[0005] In recent years, RGB-D multimodal fusion methods have provided a new technical approach for non-contact body size measurement by simultaneously utilizing the texture semantic information of RGB images and the spatial geometric information of depth images. However, existing RGB-D fusion schemes typically integrate bimodal features by direct stitching or weighted summation, failing to fully consider the cross-modal differences between the two modes. This results in information redundancy in the fusion results and an inability to effectively utilize the complementary characteristics of modes in target boundaries, occluded regions, and failure regions, thus limiting the accuracy of key point detection in complex environments. Summary of the Invention

[0006] To address the shortcomings of existing technologies, the purpose of this invention is to provide a method for detecting key points and automatically measuring body size in pigs based on a difference-driven bimodal fusion network. This method uses cross-modal differences as the fusion driving information and achieves high-precision detection of key points and automatic body size measurement in pigs with a relatively small model size by explicitly calculating and specifically enhancing the differences between RGB and Depth features.

[0007] To achieve the above objectives, the technical solution of this invention is: a method for key point detection and automatic body size measurement of pigs based on a difference-driven dual-modal fusion network, comprising the following steps: S1. Image acquisition: Set the depth camera and RGB camera above the pig to acquire time-synchronized RGB images and corresponding depth images of the pig; S2. Input the RGB image and the corresponding depth image into the trained dual-stream feature extraction network to obtain the target bounding box of the pig and the two-dimensional pixel coordinates (u,v) of six key points; The dual-stream feature extraction network includes an RGB branch and a Depth branch constructed based on the YOLO11 algorithm. The RGB branch and the Depth branch are two backbone branches with identical structures and independent parameters, and the two branches maintain spatial resolution alignment at each downsampling scale. The dual-stream feature extraction network also includes a D²F fusion module deployed at each of the three intermediate scales P3, P4, and P5 of the backbone. The D²F fusion module is used to perform modal interaction between the multi-scale RGB features and the multi-scale Depth features at the corresponding scales and output fused features. The fused multi-scale features are sent to the Neck for multi-scale feature aggregation, and finally the Head outputs both the target detection box and the keypoint coordinates. The six key points include: key point F located at the junction of the pig's neck and torso, key point B located at the center of the base of the pig's tail, left edge point L1 and right edge point R1 at the widest part of the shoulder area, and left edge point L2 and right edge point R2 at the widest part of the rump area. S3. Using the intrinsic parameters of the RGB-D camera and the depth value d(u,v) of the corresponding pixel position, convert the two-dimensional pixel coordinates output in step S2 into three-dimensional coordinates (X,Y,Z) in the camera coordinate system according to the depth camera pinhole imaging model. S4. Calculate the body size parameters of the pig based on the three-dimensional coordinates of the key points. The body size parameters include at least one of body length BL, body width BW, hip width HW, body height BH, and hip height HH.

[0008] Preferably, the D²F fusion module includes a channel alignment unit, a difference extraction unit, a difference enhancement unit, a residual fusion unit, and a channel projection unit that are cascaded in sequence. The channel alignment unit includes a first convolutional layer, which has a 1×1 convolutional kernel and is used to align the Depth branch features F. D The channel dimension is mapped to the same channel dimension as the RGB branch feature, resulting in the alignment feature F. D′ ; The difference extraction unit is used to process the RGB branch feature F. R Alignment feature F D′ Perform element-wise difference operations to generate difference features, and then perform channel recombination and nonlinear transformation on them; The difference enhancement unit is used to enhance the difference features at both the channel and spatial levels to obtain globally enhanced difference features; The residual fusion unit is used to process the RGB branch feature F. R Alignment feature F D′ Perform a weighted summation operation on the global enhanced differential features; The channel projection unit uses a 1×1 convolution kernel to map the weighted summation result to the target number of channels that is compatible with the downstream feature aggregation network, and outputs fused features.

[0009] Preferably, the difference extraction unit includes a difference operation module, a second 1×1 convolutional layer, and a GELU activation layer; The difference operation module receives RGB branch features respectively. Alignment features Perform element-wise difference operations to generate an initial difference feature map: ; The initial differential feature map is sequentially processed through a second 1×1 convolutional layer for inter-channel linear transformation and recombination, and then through a GELU activation layer for nonlinear transformation to obtain the preprocessed differential feature D: .

[0010] Preferably, the difference enhancement unit includes a WKCA wavelet-KAN channel attention module and a bidirectional visual Mamba module (BVM). The WKCA wavelet-KAN channel attention module includes parallel global average pooling (GAP) and global maximum pooling (GMP) branches, a wavelet base layer (RWBL), and a sigmoid gated layer. The preprocessed difference feature D is input to the global average pooling and global maximum pooling branches, respectively. Each branch sequentially performs squeeze and transpose operations, 1×1 convolution, and inverse transpose and squeeze transformations to obtain average pooling and maximum pooling descriptors, respectively. The two descriptors are then fused element-wise to obtain a comprehensive channel descriptor. The wavelet base layer (RWBL) uses the Ricker wavelet function as the basis function and SiLU as the basic activation function to perform a nonlinear wavelet kernel function transformation on the comprehensive channel descriptor. Its output is normalized to the (0,1) interval by the sigmoid function to generate a channel weight vector. This channel weight vector is then multiplied element-wise with the preprocessed difference feature D to complete channel-level adaptive recalibration, outputting a channel-enhanced difference feature D′. The squeeze and transpose operations are used to transform convolutional features into a form suitable for 1×1 convolution for channel relationship modeling.

[0011] Preferably, the transformation calculation formula for the three-dimensional coordinates is: in , The coordinates of the image center point, , The horizontal and vertical focal lengths of the camera are given. This allows us to obtain the three-dimensional spatial positions of key points such as F, B, L1, R1, L2, and R2 in Table 1.

[0012] Preferably, the bidirectional visual Mamba module (BVM) includes a normalized convolutional layer, a serialized unrolling layer, a bidirectional scanning layer, and a residual output layer. The normalized convolutional layer performs GroupNorm normalization and 1×1 convolution on the channel enhancement differential feature D′ in sequence. The serialization unpacking layer performs flatten(2) and transpose operations on the convolutional features to unpack and transpose the spatial feature map into a one-dimensional token sequence S, where the sequence length L = H × W; The bidirectional scanning layer includes a forward scanning branch and a backward scanning branch. The forward scanning branch scans the state space of the sequence S in forward order, and the backward scanning branch scans the sequence S in reverse order and restores the order through a flip operation. The two scanning outputs are added element by element and fused to obtain the sequence representation Y. The residual output layer restores the sequence representation Y to a three-dimensional feature form of B×C×H×W through transpose and reshape operations, and then passes it through a third 1×1 convolutional layer and makes a skip connection with the channel enhancement differential feature D′ to output the global enhancement differential feature. The flatten(2), transpose, and reshape operations are all used to perform tensor dimension transformations between CNN feature maps and the one-dimensional sequences required by Mamba.

[0013] Preferably, the selective state space parameters of the state space scan are dynamically generated by linear mapping from the input sequence, so that regions with large differences in features generate stronger state updates and information propagation, while updates in regions with small differences are suppressed, forming a difference-driven dynamic gating effect.

[0014] Preferably, in step S4: Body length BL is defined as the length of the spine line along the curved surface of the pig's back between key points F and B. Specifically, a k-nearest neighbor graph based on Euclidean distance is constructed on the surface of the three-dimensional point cloud of the pig's body. The spine region of the pig's back is connected along the directions F, H1, H2, and B. The Dijkstra algorithm is used to solve the shortest path on the surface to obtain the geodesic path along the direction of the pig's back spine. Then, arc length parameterization, equal-interval resampling, and sliding window smoothing are performed to form a smooth spine curve. The body length is calculated from the arc length of the curve. Body width (BW) is defined as the three-dimensional Euclidean distance between the left and right key points L1 and R1 of the shoulder; hip width (HW) is defined as the three-dimensional Euclidean distance between the left and right key points L2 and R2 of the hip. Body height BH is defined as the height of point H1, obtained by projecting the midpoint of the line connecting L1 and R1 along the Z-axis onto the back surface of the pig, to the ground; hip height HH is defined as the height of point H2, obtained by projecting the midpoint of the line connecting L2 and R2 along the Z-axis onto the back surface of the pig, to the ground.

[0015] Beneficial effects: (1) Non-contact automatic measurement: RGB and Depth information are acquired synchronously by the camera, and the network automatically completes target detection, key point positioning, three-dimensional coordinate recovery and body size calculation. There is no need for direct contact between humans and pigs, so it can reduce the labor intensity of manual measurement and animal stress, and is suitable for large-scale breeding scenarios. (2) Make full use of cross-modal complementary information: This invention does not simply splice the two modes directly, but explicitly calculates the difference between them, so that the complementary information in the single-modal degradation region can be enhanced, thereby improving the robustness in complex environments; (3) Improve key point localization ability: WKCA uses Ricker wavelet basis to enhance local mutations and high frequency responses in differential features, and BVM uses bidirectional selective state space model to establish global spatial dependence. Therefore, it can enhance features related to key anatomical structures of pigs from both channel and spatial levels. (4) Balancing accuracy and model size: In the initial experiment, the D²F-Net parameter count was 5.96 M, achieving 95.0% APbox and 96.1% APkp among the compared methods. This invention can achieve better detection and key point localization performance with a smaller model size. (5) It has good adaptability to different growth stages: the body size error on different dates remains stable and can adapt to changes in body size during the growth of pigs. Attached Figure Description

[0016] Figure 1 This is a flowchart of the key point detection and automatic body size measurement process for pigs according to the present invention; Figure 2 This is a diagram of the RGB-D key point detection framework architecture of the present invention; Figure 3 D 2 F module structure diagram; Figure 4 Here is a diagram of the WKCA module structure; Figure 5 It uses a BVM module structure; Figure 6 Mapping two-dimensional pixel coordinates to three-dimensional world coordinates; Figure 7 This is a schematic diagram of the body scale measuring points and body scale parameters. Detailed Implementation

[0017] 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.

[0018] Example 1 like Figure 1 As shown, the method for key point detection and automatic body size measurement of pigs based on a difference-driven dual-modal fusion network includes the following steps: S1. Image acquisition: Obtain the RGB image and corresponding depth image of the pig.

[0019] A depth camera and an RGB camera were positioned above the pig, approximately 1700mm above the ground, so that the camera's field of view covered the back area of ​​a single pig. Synchronous RGB and depth images were acquired. The depth camera was an Azure Kinect depth camera, connected to the sync output port of the depth camera and the sync input port of the RGB camera using a sync cable. After the RGB camera started, it waited for the sync signal from the depth camera. Upon receiving the recording command, the depth camera output a sync signal, causing both cameras to begin acquiring image frames corresponding to the specified time. Thus, the depth image and RGB image corresponded frame-by-frame in time. The acquisition parameters were: WFOV depth mode, RGB resolution 1280×720, and RGB camera exposure set to -5. For each depth pixel in the depth image, the pixel coordinates and depth value were back-projected to the camera coordinate system based on the focal length and principal point parameters in the camera's intrinsic parameters, thereby obtaining the three-dimensional coordinate point. The camera intrinsic parameters can be read from the calibration interface of the Azure Kinect SDK. The regression model of this invention uses the three-dimensional coordinates of the point, without requiring the RGB color of the point as a necessary input.

[0020] Representative pose samples were selected from the videos to construct an RGB-D dataset containing 11,000 images and corresponding synchronized depth images. Target bounding boxes and the seven keypoints in Table 6 were manually annotated using Labelme, converted to YOLO format, and then verified a second time. Training, validation, and test sets were created based on individual pigs. The training set consisted of 7,000 images from 18 pigs out of 24 pigs in columns 2 and 3, and the validation set consisted of 2,900 images from 6 pigs, with a training-to-validation ratio of 7:3. The test set consisted of 1,000 images from 12 pigs in column 1.

[0021] S2. Input the RGB image and the corresponding depth image into the trained dual-stream feature extraction network to obtain the target bounding box of the pig and the two-dimensional pixel coordinates (u,v) of six key points.

[0022] The dual-stream feature extraction network includes an RGB branch and a Depth branch constructed based on the YOLO11 algorithm, which extract multi-scale RGB features and multi-scale Depth features from the RGB image and the depth image, respectively. In this embodiment, the RGB branch feature is F. R The feature of the Depth branch is F D The RGB branch and the Depth branch are two backbone branches with the same structure but independent parameters.

[0023] The RGB image and the depth image are fed into two separate backbone branches (both with a four-stage downsampling structure). The RGB branch takes the RGB image as input and extracts texture, color, and semantic features, while the Depth branch takes the depth image as input and extracts spatial structure, distance, and geometric boundary features. Both branches maintain spatial resolution alignment (B×C×H×W) at each downsampling scale. Figure 2 As shown, a D²F fusion module is deployed at each of the three intermediate scales P3, P4, and P5 of the Backbone to allow the two modalities to interact at the corresponding scales. The fused multi-scale features are fed into the Neck for multi-scale feature aggregation. Finally, the Head outputs both the target detection bounding box and the keypoint coordinates, realizing joint inference between detection and keypoints. The six keypoints are shown in Table 1.

[0024] Table 1 F and B are used to describe the pig's body length, L1 and R1 are used to calculate the body width, L2 and R2 are used to calculate the hip width, and the body height and hip height are calculated in combination with the Depth information.

[0025] Among them, such as Figure 3 As shown, D 2 Module F includes a channel alignment unit, a difference extraction unit, a difference enhancement unit, a residual fusion unit, and a channel projection unit. These units are cascaded sequentially.

[0026] The channel alignment unit includes a first convolutional layer; wherein the first convolutional layer has a 1×1 convolutional kernel, used to process the Depth branch features F. D The channel dimension is mapped to the same channel dimension as the RGB branch features, and the RGB feature map input to the fusion module is F. R ∈B×C1×H×W, the depth feature map is F D ∈B×C2×H×W, where B represents the batch size, H and W represent the spatial height and width of the feature map, respectively, and C1 and C2 represent the channel dimensions of the two modalities. Since C1 and C2 are usually not equal, the channel alignment unit performs channel projection operation on the Depth branch. Using a convolutional layer with a kernel size of 1×1 (denoted as Conv1×1), F... D Mapped to the same channel space as the RGB features: F D =Conv1×1(F D ) After this operation, F D The dimensional transformation of F' is B×C1×H×W, thus achieving strict alignment of the bimodal features in the channel dimension. Meanwhile, the RGB feature F... RThe original dimensions are directly transmitted to the difference extraction unit.

[0027] The difference extraction unit includes a difference operation module, a 1×1 convolutional layer (1x1 Conv), and a GELU activation layer. The difference operation module receives RGB branch features F respectively. R Alignment feature F output by the channel alignment unit D ′, used for RGB branch features F R Alignment feature F D Perform element-wise difference operations to generate an initial difference feature map F. diff This invention uses differential features as the primary information interaction carrier to reduce information redundancy caused by modal common representation and to highlight the complementary region between RGB texture and Depth geometric boundary.

[0028] F diff =F R - F D ′ F diff ∈R B×C1×H×W The difference feature map is then passed through a 1×1 convolutional layer (1x1 Conv) and a GELU activation layer. This convolutional layer performs linear transformation and recombination between channels on the difference features without changing the spatial resolution (H×W). It is used to integrate the difference responses on each channel, compress or adjust the channel representation, and initially filter out redundant noise introduced during the difference process.

[0029] The output of the 1×1 convolution undergoes a nonlinear transformation using the GELU activation function to integrate and enhance the original difference signal, yielding a preliminary refined difference feature, denoted as D. GELU possesses smooth, non-monotonic gating characteristics, and compared to ReLU, it can more gently preserve and suppress small positive and negative deviations in the difference response, preventing the premature loss of difference information in the nonlinear stage.

[0030] F diff =GELU(Conv1×1(F diff )) The difference enhancement unit is used to enhance difference features at both the channel and spatial levels, including the WKCA wavelet-KAN channel attention module and the bidirectional visual Mamba module (BVM). The WKCA wavelet-KAN channel attention module includes parallel global average pooling (GAP) and global maximum pooling (GMP) branches, a wavelet base layer (RWBL), and a sigmoid gated layer, such as... Figure 4As shown, the activated differential feature map D is input into the global average pooling branch GAP and the global max pooling branch GMP, respectively. Each branch sequentially performs squeeze and transpose operations, 1×1 convolution, and inverse transpose and squeeze transformations to obtain the average pooling descriptor and the max pooling descriptor, respectively. The two descriptors are then fused element-wise to obtain the comprehensive channel descriptor. The squeeze and transpose operations are tensor dimension adjustment operations used to transform the convolutional features into a form suitable for 1×1 convolution for channel relationship modeling. The inverse squeeze and transpose transformations are used to restore the original dimensions.

[0031] The wavelet base layer RWBL uses Ricker wavelet functions as basis functions and SiLU as the basic activation function to perform nonlinear wavelet kernel function transformation on the comprehensive channel descriptor, enabling the network to model local abrupt changes, edges, and high-frequency responses in the differential features. Compared with the traditional multilayer perceptron structure, the learnable transformation based on wavelet basis functions can fit the high-frequency and low-frequency dependencies between channels with fewer parameters. The output of the wavelet base layer RWBL is normalized to the (0,1) interval by the Sigmoid function to generate channel weight vectors, realizing the adaptive generation of channel weights. Since the difference between RGB and Depth is usually more obvious at target boundaries, occlusion boundaries, and modal failure regions, the localization and multi-scale response characteristics of Ricker wavelets can be used to enhance the discriminative channels related to key point localization. The channel weight vector is then multiplied element-wise with the preprocessed differential feature D to complete the channel-level adaptive recalibration and output the channel-enhanced differential feature D'.

[0032] The mathematical expression for Ricker wavelet is as follows: z represents the univariate feature input to the wavelet basis function, obtained by scaling and translation transformations of the network features. This function serves as a learnable nonlinear activation function on the KAN network connection for feature transformation.

[0033] like Figure 5As shown, the bidirectional visual Mamba module BVM includes a normalized convolutional layer (Group Norm), a serialization unrolling layer, a bidirectional scanning layer, and a residual output layer. Its specific operation is as follows: The normalized convolutional layer receives the channel-enhanced differential features D', normalizes them, and processes them with a 1×1 convolutional layer to stabilize the feature distribution and adjust the channel representation; the serialization unrolling layer performs flatten(2) and transpose operations on the channel-enhanced differential features D' after convolution processing, unrolling and transposing the spatial feature map into a one-dimensional token sequence S; the bidirectional scanning layer includes a forward scanning branch and a backward scanning branch, with the sequence S input to both branches respectively; the forward scanning branch scans the state space of the sequence S in forward order, and the backward scanning branch scans the sequence S in reverse order and restores the order through a flip operation; the two scan outputs are fused element-wise to obtain the sequence representation Y. Through bidirectional scanning, the bidirectional vision Mamba module can capture long-range spatial structure dependencies with computational complexity linear to the sequence length, overcoming the directional bias problem of unidirectional scanning. Because Mamba's selective state-space parameters change with the input, regions with larger differences can generate stronger state updates and information propagation, while updates in regions with smaller differences are suppressed. Therefore, BVM can achieve a difference-driven dynamic gating effect, enabling local key structural responses to propagate and correct within the overall spatial structure of the pig, and improving the stability of keypoint localization under conditions of occlusion, low light, and lack of local information. The residual output layer restores the sequence representation Y to a three-dimensional feature form of B×C×H×W through transpose and reshape operations, then passes it through a third 1×1 convolutional layer, and performs a skip connection (residual addition) with the channel-enhanced difference feature D' output by the WKCA wavelet-KAN channel attention module, outputting a global enhanced difference feature. This is then multiplied by a magnification factor (…). Figure 3 The value is shown as ×2, which is an empirical scaling factor used to calibrate the amplitude of the fused differential enhancement features, compensate for the feature response attenuation that may occur during normalization and state space propagation, and improve the expression intensity of differential information in key structural regions), thus obtaining the final channel enhancement differential feature D'' of the differential enhancement unit. flatten(2), transpose, and reshape are all tensor dimension transformation operations used to convert between CNN feature maps and the one-dimensional sequence required by Mamba, without including parameter learning.

[0034] In the BVM module, the serialized differential feature sequences are... Input selective state-space units.

[0035] For each space token The input-related state-space parameters are generated through a linear mapping layer: in: : Controls the state update step size, used to adjust the fusion ratio of historical information and current input; : Control the impact of the current input features on the state space; : Control status information output mapping.

[0036] Then, the state is updated based on the generated dynamic parameters: And output: By using the above methods, the differences in spatial location characteristics are assigned different information propagation weights.

[0037] The residual fusion unit receives the final channel enhancement difference feature D'' and alignment feature F, respectively. D ′ and RGB branch features F R Perform a weighted summation operation to obtain the merged intermediate features: Fmid=FR+FD′+α⋅D'' Where α is the differential feature reinjection intensity coefficient.

[0038] The channel projection unit, using a 1×1 convolutional kernel (Proj, representing the output channel projection operation), maps the fused intermediate features to a target number of channels that matches the downstream feature aggregation network, outputting the fused features: Ffuse =Proj( FR + FD ′+ α ⋅ Dg ), Ffuse ∈R B×C×H×W To ensure the fairness and reproducibility of the experimental results, all models in this paper were trained and tested on the same hardware platform and software environment. The experimental platform used Ubuntu 24.04 as the operating system, and the hardware configuration included an AMD Ryzen 9 9950X3D CPU (16 cores, 32 threads, base frequency 4.3 GHz), a 32 GB NVIDIA GeForce RTX 5090 GPU, 128 GB of RAM, and 18 TB of storage space. Python 3.10 was used as the programming language, PyTorch 2.9 as the deep learning framework, CUDA 12.8 for acceleration, and PyCharm as the programming platform.

[0039] During training, the batch size was set to 16, the stochastic gradient descent (SGD) optimizer momentum was set to 0.937, and the weight decay was set to 0.001. The input image size was 640×640, the training epochs were set to 100, and the initial learning rate was 0.01. The weight coefficients of each loss term were set to the model's default settings during training. All model training parameters remained consistent.

[0040] The model training adopts a joint learning approach for object detection and keypoint detection. The performance of object detection is evaluated by the average accuracy APbox within the IoU threshold range of 0.50:0.05:0.95, and the performance of keypoint detection is evaluated by the average accuracy APkp within the OKS threshold range of 0.50:0.05:0.95.

[0041] To verify the effectiveness of the WKCA wavelet-KAN channel attention module and the bidirectional visual Mamba module BVM in the D²F module, an ablation experiment was conducted on the test set using the D²F baseline network without both modules as a reference. The results are shown in Table 2.

[0042] Table 2 Ablation Experiment Results The D²F-Net has 5.96 M parameters, an APbox of 95.0%, and an APkp of 96.1%. Ablation experiments show that the APkp is 89.3% without WKCA and BVM, but increases to 96.1% with both, an improvement of 6.8 percentage points.

[0043] S3. For example Figure 6 As shown, using the intrinsic parameters of the RGB-D camera and the depth value d(u,v) of the corresponding pixel position, the two-dimensional coordinates output in step S2 are converted into three-dimensional coordinates (X,Y,Z) in the camera coordinate system according to the depth camera pinhole imaging model.

[0044] Formula for calculating world coordinate (X,Y,Z) transformation: in , The coordinates of the image center point, , The horizontal and vertical focal lengths of the camera are given. This allows us to obtain the three-dimensional spatial positions of key points such as F, B, L1, R1, L2, and R2 in Table 1.

[0045] S4. Calculate the body size parameters of the pig based on the three-dimensional world coordinates of the key points.

[0046] like Figure 7 As shown, body length BL is defined as the length of the spine along the curved surface of the pig's back, from the midpoint F of the neck to the base B of the tail. Specifically, a k-nearest neighbor graph based on Euclidean distance is constructed on the surface of the pig's 3D point cloud (derived from a depth map acquired by a depth camera). The spine regions of the pig are connected along the directions F, H1, H2, and B. Dijkstra's algorithm is used to solve for the shortest path on the surface in the graph structure to obtain the geodesic path along the spine of the pig. Subsequently, arc length parameterization, equal-interval resampling, and sliding window smoothing are performed to form a smooth spine curve, and the body length is calculated from the curve arc length. Body width BW is defined as the 3D Euclidean distance between the left and right shoulder keypoints L1 and R1; hip width HW is defined as the 3D Euclidean distance between the left and right hip keypoints L2 and R2. Body height BH is defined as the height of point H1, obtained by projecting the midpoint of the line connecting L1 and R1 along the Z-axis onto the dorsal surface of the pig, to the ground; hip height HH is defined as the height of point H2, obtained by projecting the midpoint of the line connecting L2 and R2 along the Z-axis onto the dorsal surface of the pig, to the ground (175cm). The present invention uses manual measurement results as a reference for body size measurement, and evaluates the automatic measurement results using mean absolute error (MAE) and mean absolute percentage error (MAPE).

[0047] Body size measurements included five indicators: body length (BL), body width (BW), hip width (HW), body height (BH), and hip height (HH). Twelve healthy fattening pigs were selected for the experiment, and manual body size measurements were performed on February 6th, March 10th, April 2nd, and April 16th, covering the growth stage of the pigs from approximately 35 kg to 105 kg. Each measurement simultaneously acquired RGB images, depth images, and corresponding manual measurements. Manual measurements were performed using a flexible measuring tape and a measuring stick, with two people independently measuring and averaging the results as the true value reference. The measurement indicators included body length (BL), body width (BW), hip width (HW), body height (BH), and hip height (HH). For automated measurements, the RGB and depth images acquired at the same time were input into a trained D²F-Net to obtain bounding boxes and the coordinates of six key points. These were then combined with the depth information to calculate the body size indicators. For each pig, x frames were repeatedly collected, and the average value was used as the result for that measurement.

[0048] Table 3 Body size measurement results Over the four data collection dates, the average MAE for body length was 3.22 cm, with a corresponding average MAE of 3.94%; the average MAE for body width was 0.96 cm, with a corresponding average MAE of 3.50%; the average MAE for hip width was 0.93 cm, with a corresponding average MAE of 3.41%; the average MAE for body height was 1.58 cm, with a corresponding average MAE of 2.88%; and the average MAE for hip height was 1.33 cm, with a corresponding average MAE of 2.24%. Overall, this method achieved low measurement errors across the four measurement dates and five body size indicators, with a maximum MAE not exceeding 5%, indicating that this method can accurately obtain body size information for pigs at different growth stages.

[0049] This invention constructs a dual-branch feature extraction network for RGB and Depth based on the YOLO framework, and sets a D²F difference-driven dual-modal fusion module in the multi-scale feature layer of the backbone network. First, dual-stream channel alignment is performed, and then the difference between RGB and Depth features is explicitly calculated. After WKCA channel attention and BVM bidirectional visual Mamba enhancement, the original modal features are reinjected in a residual manner. Then, the Neck and Pose Head are used to complete target detection and localization of six key points, and the two-dimensional key points are mapped to three-dimensional coordinates. The body size parameters are calculated based on geometric distance and back geodesic path. This invention solves the problems of low efficiency, high labor cost, repeatedness affected by the experience of the measurement personnel, and easy to cause animal stress in the process of obtaining body size parameters of pigs under large-scale farming conditions. At the same time, it solves the problem that existing key point detection methods based on RGB images are sensitive to illumination, occlusion, texture loss, and changes in pig posture.

[0050] 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. A method for key point detection and automatic body size measurement of pigs based on a difference-driven dual-modal fusion network, characterized in that, Includes the following steps: S1. Image acquisition: Set the depth camera and RGB camera above the pig to acquire time-synchronized RGB images and corresponding depth images of the pig; S2. Input the RGB image and the corresponding depth image into the trained dual-stream feature extraction network to obtain the target bounding box of the pig and the two-dimensional pixel coordinates (u,v) of six key points; The dual-stream feature extraction network includes an RGB branch and a Depth branch constructed based on the YOLO11 algorithm. The RGB branch and the Depth branch are two backbone branches with identical structures and independent parameters. The two branches maintain spatial resolution alignment at each downsampling scale. The dual-stream feature extraction network also includes a D²F fusion module deployed at each of the three intermediate scales P3, P4, and P5 of the backbone. The D²F fusion module is used to perform modal interaction between multi-scale RGB features and multi-scale Depth features at the corresponding scales and output fused features. The fused multi-scale features are fed into the Neck for multi-scale feature aggregation, and finally the Head outputs both the target detection box and the key point coordinates. The six key points include: key point F located at the junction of the pig's neck and torso, key point B located at the center of the base of the pig's tail, left edge point L1 and right edge point R1 at the widest part of the shoulder area, and left edge point L2 and right edge point R2 at the widest part of the rump area. S3. Using the intrinsic parameters of the RGB-D camera and the depth value d(u,v) of the corresponding pixel position, convert the two-dimensional pixel coordinates output in step S2 into three-dimensional coordinates (X,Y,Z) in the camera coordinate system according to the depth camera pinhole imaging model. S4. Calculate the body size parameters of the pig based on the three-dimensional coordinates of the key points. The body size parameters include at least one of body length BL, body width BW, hip width HW, body height BH, and hip height HH.

2. The method for key point detection and automatic body size measurement of pigs based on a difference-driven dual-modal fusion network according to claim 1, characterized in that, The D²F fusion module includes a channel alignment unit, a difference extraction unit, a difference enhancement unit, a residual fusion unit, and a channel projection unit, which are cascaded in sequence. The channel alignment unit includes a first convolutional layer, which has a 1×1 convolutional kernel and is used to align the Depth branch features F. D The channel dimension is mapped to the same channel dimension as the RGB branch feature, resulting in the alignment feature F. D′ ; The difference extraction unit is used to process the RGB branch feature F. R Alignment feature F D′ Perform element-wise difference operations to generate difference features, and then perform channel recombination and nonlinear transformation on them; The difference enhancement unit is used to enhance the difference features at both the channel and spatial levels to obtain globally enhanced difference features; The residual fusion unit is used to process the RGB branch feature F. R Alignment feature F D′ Perform a weighted summation operation on the global enhanced differential features; The channel projection unit uses a 1×1 convolution kernel to map the weighted summation result to the target number of channels that is compatible with the downstream feature aggregation network, and outputs fused features.

3. The method for key point detection and automatic body size measurement of pigs based on a difference-driven dual-modal fusion network according to claim 2, characterized in that, The difference extraction unit includes a difference operation module, a second 1×1 convolutional layer, and a GELU activation layer; The difference operation module receives RGB branch features respectively. Alignment features Perform element-wise difference operations to generate an initial difference feature map: ; The initial differential feature map is sequentially processed through a second 1×1 convolutional layer for inter-channel linear transformation and recombination, and then through a GELU activation layer for nonlinear transformation to obtain the preprocessed differential feature D: .

4. The method for key point detection and automatic body size measurement of pigs based on a difference-driven dual-modal fusion network according to claim 2, characterized in that, The differential enhancement unit includes a WKCA wavelet-KAN channel attention module and a bidirectional visual Mamba module (BVM). The WKCA wavelet-KAN channel attention module includes parallel global average pooling (GAP) and global max pooling (GMP) branches, a wavelet base layer (RWBL), and a sigmoid gated layer. The preprocessed differential features D are input to the global average pooling and global max pooling branches, respectively. Each branch sequentially performs squeeze and transpose operations, 1×1 convolution, and inverse transpose and squeeze transformations to obtain average pooling and max pooling descriptors, respectively. The two descriptors are fused element-wise to obtain a comprehensive channel descriptor. The wavelet base layer (RWBL) uses the Ricker wavelet function as the basis function and SiLU as the basic activation function to perform a nonlinear wavelet kernel function transformation on the comprehensive channel descriptor. Its output is normalized to the (0,1) interval by the Sigmoid function to generate a channel weight vector. The channel weight vector is multiplied element-wise with the preprocessed difference feature D to complete the channel-level adaptive recalibration and output the channel enhancement difference feature D′. The squeeze and transpose operations are used to transform convolutional features into a form suitable for 1×1 convolution for channel relationship modeling.

5. The method for key point detection and automatic body size measurement of pigs based on a difference-driven dual-modal fusion network according to claim 1, characterized in that, The transformation calculation formula for the three-dimensional coordinates is as follows: in , The coordinates of the image center point, , The horizontal and vertical focal lengths of the camera are given. This allows us to obtain the three-dimensional spatial positions of key points such as F, B, L1, R1, L2, and R2 in Table 1.

6. The method for key point detection and automatic body size measurement of pigs based on a difference-driven dual-modal fusion network according to claim 1, characterized in that, The bidirectional vision Mamba module (BVM) includes a normalized convolutional layer, a serialized unrolling layer, a bidirectional scanning layer, and a residual output layer. The normalized convolutional layer performs GroupNorm normalization and 1×1 convolution on the channel enhancement differential feature D′ in sequence. The serialization unpacking layer performs flatten(2) and transpose operations on the convolutional features to unpack and transpose the spatial feature map into a one-dimensional token sequence S, where the sequence length L = H × W; The bidirectional scanning layer includes a forward scanning branch and a backward scanning branch. The forward scanning branch scans the state space of the sequence S in forward order, and the backward scanning branch scans the sequence S in reverse order and restores the order through a flip operation. The two scanning outputs are added element by element and fused to obtain the sequence representation Y. The residual output layer restores the sequence representation Y to a three-dimensional feature form of B×C×H×W through transpose and reshape operations, and then passes it through a third 1×1 convolutional layer and makes a skip connection with the channel enhancement differential feature D′ to output the global enhancement differential feature. The flatten(2), transpose, and reshape operations are all used to perform tensor dimension transformations between CNN feature maps and the one-dimensional sequences required by Mamba.

7. The method for key point detection and automatic body size measurement of pigs based on a difference-driven dual-modal fusion network according to claim 6, characterized in that, The selective state space parameters of the state space scan are dynamically generated by linear mapping from the input sequence, which makes regions with large differences generate stronger state updates and information propagation, while the updates of regions with small differences are suppressed, forming a difference-driven dynamic gating effect.

8. The method for key point detection and automatic body size measurement of pigs based on a difference-driven dual-modal fusion network according to claim 1, characterized in that, In step S4: Body length BL is defined as the length of the spine line along the curved surface of the pig's back between key points F and B. Specifically, a k-nearest neighbor graph based on Euclidean distance is constructed on the surface of the three-dimensional point cloud of the pig's body. The spine region of the pig's back is connected along the directions F, H1, H2, and B. The Dijkstra algorithm is used to solve the shortest path on the surface to obtain the geodesic path along the direction of the pig's back spine. Then, arc length parameterization, equal-interval resampling, and sliding window smoothing are performed to form a smooth spine curve. The body length is calculated from the arc length of the curve. Body width (BW) is defined as the three-dimensional Euclidean distance between the left and right key points L1 and R1 of the shoulder; hip width (HW) is defined as the three-dimensional Euclidean distance between the left and right key points L2 and R2 of the hip. Body height BH is defined as the height of point H1, obtained by projecting the midpoint of the line connecting L1 and R1 along the Z-axis onto the back surface of the pig, to the ground; hip height HH is defined as the height of point H2, obtained by projecting the midpoint of the line connecting L2 and R2 along the Z-axis onto the back surface of the pig, to the ground.

Citation Information

Patent Citations

  • Pig body size measuring method and system based on multi-modal data fusion

    CN121810765A