Group health-preserving pig individual body temperature detection method based on temperature texture identity recognition
By using thermal infrared imaging and an improved YOLOv11 model, combined with CLAHE and Gamma correction, we have achieved individual pig identification and body temperature measurement, solving the problems of high identification costs, light interference and occlusion, and providing individualized continuous monitoring and early warning functions.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-26
- Publication Date
- 2026-03-13
AI Technical Summary
Existing technologies suffer from problems such as high cost of individual pig identification, susceptibility to interference from light and shading, stress-prone contact temperature measurement, and lack of individualized continuous monitoring.
A temperature texture identification method based on thermal infrared imaging is adopted. By improving YOLOv11 individual identification and YOLOv11-OBB ear root detection, combined with CLAHE and Gamma correction, identification and temperature measurement area localization are achieved, and reliable body temperature values are obtained by linear mapping. The results are archived with individual identity and time.
It achieves robust identification of individual pigs and non-contact accurate body temperature measurement in a group-housed environment, avoiding interference from changes in lighting and shading, and provides individualized continuous monitoring and abnormal body temperature early warning functions.
Smart Images

Figure CN121661559A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of pig identification and pig temperature measurement technology, specifically to a method for detecting the body temperature of individual pigs in group-raised pigs based on temperature texture identification. Background Technology
[0002] Individual-level health monitoring in group farming scenarios requires addressing two key challenges: "stable identification" and "reliable body temperature extraction." Existing solutions relying on electronic ear tags or RFID are costly to implement and require extensive maintenance, making them uneconomical for large-scale farming. Non-contact identification solutions based on visible light conditions are susceptible to changes in lighting, similar pig sizes, dirt on the pig's body, and partial obstruction of the view, leading to decreased identification stability.
[0003] Traditional body temperature measurement methods, such as rectal temperature measurement, are accurate but are contact-based, which can easily induce stress responses and are not suitable for continuous and large-scale monitoring. Some non-contact infrared temperature measurement methods are often limited to group detection and lack continuous tracking and traceable records of individuals.
[0004] In comparison, the temperature texture of pigs under thermal infrared imaging is not sensitive to changes in ambient visible light and can stably reflect the surface temperature distribution of individuals under day and night and complex lighting conditions. The differences in temperature texture among different individuals make the differentiation between individual pigs higher, and it can also maintain better separation between individuals with similar coat color and pattern. In addition, it is not sensitive to visible light appearance disturbances such as surface mud and dirt, which can effectively reduce the interference of the breeding environment on the identification and temperature measurement process.
[0005] Therefore, there is an urgent need for a technical solution that uses thermal infrared imaging data as the core input and can achieve robust identity recognition, key temperature measurement location, individual body temperature calculation, and result archiving in a unified process. Summary of the Invention
[0006] This invention aims to provide a method for detecting individual body temperature in group-raised pigs based on temperature texture identification, addressing the problems of high identification costs, susceptibility to interference from light and occlusion, stress-prone contact temperature measurement, and lack of individualized continuous monitoring in existing technologies. The method utilizes improved YOLOv11 individual identification in conjunction with YOLOv11-OBB ear root detection to complete identification and temperature measurement area localization within a single frame, obtaining reliable body temperature values through linear mapping. Simultaneously, the results are archived along with individual identity and time to support traceability and early warning.
[0007] To achieve the above objectives, the present invention provides the following technical solution: a method for detecting the body temperature of individual pigs in a herd-raised pig population based on temperature texture identification, comprising the following steps:
[0008] S01: Video data acquisition. Visible light and thermal infrared video data of the herd of pigs are acquired by a dual-spectrum camera installed on the top of the breeding room. The video is then subjected to time-lapse frame extraction, and several frames are selected as image samples.
[0009] S02: Temperature texture validity verification. The visible light image (RGB) is converted to grayscale to eliminate color interference, while maintaining the TIR single-channel format of the thermal infrared image. Both types of images are uniformly scaled to 128×128 pixels and stretched to an 8-bit grayscale range (0–255), with the grayscale level set to L = 256. This is done within the pixel spacing set ∈ {1,2,4,8} and the direction set... Next, the gray-level co-occurrence matrix is calculated to extract four types of texture features: contrast, correlation, energy, and homogeneity. The obtained feature vectors are then z-score normalized, and the intra-class scatter matrix S is calculated. W and the inter-class scatter matrix S B The modal discrimination is evaluated based on the Fisher discriminant criterion. The discriminant values of RGB and TIR are compared to determine the effectiveness of the thermal infrared modality in texture representation for individual identification. A higher discriminant value indicates greater inter-class differences and smaller intra-class differences, meaning the texture features have stronger individual discrimination capabilities. After confirmation of effectiveness, proceed to step S03.
[0010] Preferably, the temperature texture validity verification step includes the following specific processes:
[0011] First, image preprocessing and quantization are performed, converting RGB images to grayscale to eliminate color information interference; TIR images retain their single-channel format. Both types of images are scaled proportionally to 128×128 and linearly stretched to 8-bit (0–255), with a uniform grayscale level L=256.
[0012] Subsequently, four classic texture features were extracted using the gray-level co-occurrence matrix: contrast, correlation, energy, and homogeneity. Given a set of pixel spacing d∈{1,2,4,8} and a set of orientations... The gray-level co-occurrence matrix is defined as follows: P(i,j;d,θ)={(x,y)|I(x,y)=i,(x+Δx,y+Δy)=j},
[0013] Where (Δx, Δy) is determined by d and θ, i, j ∈ {0, ..., L-1}, and to obtain a more stable texture representation in terms of direction and scale, a normalized average is taken for all 16 sets of Q = |d| × |θ|:
[0014] Let the marginal distribution P be...x (i)=∑ j P(i,j),P y (j)=∑ i P(i,j), with mean and standard deviation μ respectively. x =∑ i IP x (i), μ y =∑ j p y (j), σ x ,σ y The corresponding standard deviation;
[0015] Calculate four characteristics for an isotropic P(i,j):
[0016] This yields the four-dimensional feature vector of a single image: g=[Contrast,Correlation,Energy,Homogeneity] T ∈R 4 ,
[0017] To eliminate dimensional differences, z-score standardization is applied to the four-dimensional features. Assume there are K classes in total, and the number of samples in the k-th class is n. k The feature of the t-th sample is denoted as g. k,t The class mean is μ k The global mean is μ, and the total number of samples is μ.
[0018] To fairly measure the discriminative power of various features across different categories, this paper examines the intra-class divergence S in Fisher's discriminant criterion. W Inter-class divergence S B An equal-weight estimation method is used. Specifically, S W S is the weighted average of the covariances within all categories. B This is an equally weighted sum of the covariances of the deviations of each category center from the overall center. This design avoids the problem of large category dominance caused by differences in sample size, ensuring that small sample categories have equal weight in discriminant analysis;
[0019] Within-class divergence is defined as:
[0020] The inter-class divergence is defined as:
[0021] Modality discrimination is measured using the Fisher discriminant criterion, and the Fisher discriminant value is defined as:
[0022] Where tr() is the matrix trace, and to improve numerical stability, S is calculated... W Add minimal diagonal regularization εI (ε=10) -8 ), that is, using tr(S) W Calculate the denominator using +εI).
[0023] S03: Construct a foreground region recognition model M1 for pigs. Input the thermal infrared image dataset obtained in step S01 into the YOLOv11-segment model for training to obtain the parameters of the optimal model M1 for foreground segmentation of pigs in group rearing scenarios.
[0024] S04: The extracted frame images are segmented using the trained YOLOv11-segment model M1. Non-foreground regions are set to zero to form a mask image. Then, CLAHE and Gamma correction are used for preprocessing to enhance the texture details and contrast of the thermal infrared images, thereby obtaining a thermal infrared image dataset for subsequent recognition.
[0025] Preferably, the image preprocessing steps include the following specific procedures:
[0026] First, a contrast-limited adaptive histogram equalization (CLAHE) operation is performed on the segmented image. For a given grayscale histogram H(i) of the image, a mapping transformation is performed on the pixel values of each local window:
[0027] Where M×N is the number of pixels in the local window, and P(i) represents the cumulative distribution function of pixel value i, which is used to remap the pixel grayscale value. To prevent excessive contrast enhancement, CLAHE introduces the contrast clipping parameter clipLimit to limit the maximum number of pixels at each grayscale level, ensuring the balance of the enhancement effect.
[0028] Then, gamma correction is applied to the CLAHE-enhanced image to adjust the overall brightness response, enhance shadow details, or suppress overexposure in highlights. The mathematical expression is:
[0029] Where I in and I out These represent the input and output pixel values, respectively, with γ being the gamma value. If γ < 1, the image brightness is enhanced, and details in dark areas are more apparent; if γ > 1, the image becomes darker overall, suppressing abrupt changes in brightness.
[0030] S05: Construct an improved YOLOv11 pig identification model M2. Introduce a self-integrated attention mechanism (SEAM) module in the high semantic feature layer of the model backbone network to improve the discriminativeness of multi-scale target features. Introduce a local feature embedding global feature (LEGM) module between the backbone and the head to achieve complementary enhancement of fine-grained texture and global semantics. In the head upsampling stage, introduce a dynamic upsampling (DySample) module to adaptively restore spatial details and improve detection accuracy under complex occlusion.
[0031] The preferred and improved YOLOv11 pig identification steps include the following specific processes:
[0032] First, a self-integrated attention mechanism (SEAM) module is introduced into the high semantic feature layer of the Backbone network. This module establishes channel attention, spatial attention, and cross-scale attention branches on multi-scale and multi-channel features, respectively. Each branch learns weight parameters independently and generates the final attention weight map through an integration and fusion strategy. This highlights the effective texture of the foreground region and suppresses background noise and occlusion interference, thereby improving the robustness of recognition in complex scenes such as water troughs and railings.
[0033] Then, a Local Feature Embedding Global Feature Extraction (LEGM) module is introduced at the multi-scale feature fusion point of the Backbone and Head. This module utilizes local branches to extract high-resolution, fine-grained texture information, while simultaneously obtaining the overall semantic structure through global branches. During the fusion stage, local features are embedded into global features, achieving complementary enhancement of local details and global semantics. In this way, even when the key target region is partially occluded or the edges are blurred, the category attributes of the missing region can be inferred based on the global context, while maintaining the integrity of detailed features.
[0034] Finally, a dynamic upsampling (DySample) module is introduced in the upsampling stage of the Head. This module uses a lightweight prediction network to adaptively generate interpolation weights based on the local content of the input features and uses these weights to perform spatial resolution magnification, replacing the fixed interpolation method. DySample can effectively improve the contour clarity and detail restoration of high-resolution feature maps in scenarios with blurred boundaries or local missing features, thereby improving the model's spatial information recovery capability.
[0035] Through the above steps, the improved YOLOv11 pig identification model has been optimized in terms of feature extraction, feature fusion and spatial detail restoration, and can maintain high recognition accuracy and robustness in breeding scenarios such as partial occlusion of pig body parts.
[0036] S06: Model training; The image dataset obtained in step S04 after CLAHE and Gamma enhancement is input into the improved YOLOv11 model M2 for training to obtain the optimal individual recognition model parameters in the group rearing scenario.
[0037] S07: Ear root region recognition model construction. Based on the preprocessed dataset, a YOLOv11-OBB ear root region detection model M3 was established. Rotated bounding boxes were labeled on the left and right ear roots in the training set to achieve accurate ear root localization under complex posture and tilt conditions.
[0038] S08: Model Inference and Ear Root Detection; In the inference stage, the improved YOLOv11 individual recognition model M2 is first used to detect and distinguish each individual pig; then the YOLOv11-OBB ear root detection model M3 is called to identify and classify the left and right ear root regions of each pig and output the corresponding prediction box coordinates.
[0039] S09: Temperature matrix construction, optimal ear root selection, and result archiving. For each pig, the pixel grayscale values of the left and right ear root prediction boxes are extracted and mapped to temperature using linear interpolation. The specific formula is as follows:
[0040] Then, the standard deviation of the temperature matrices on both sides is calculated, and the side with the smaller standard deviation is selected as the optimal ear root detection box. Within the optimal ear root detection box, the maximum value of the temperature matrix is taken as the body temperature result of the pig. The individual body temperature detection results of each pig in the group-housed environment are output, and the results are archived together with the individual identification and detection time to form a traceable body temperature time series record and provide the query and export functions for abnormal body temperatures.
[0041] Where T is the predicted body temperature value; P is the pixel grayscale value; T max T min These represent the maximum and minimum temperature values in the thermal image, respectively. Attached Figure Description
[0042] Figure 1 This is a flowchart of the present invention;
[0043] Figure 2 This is a schematic diagram of the data acquisition system of the present invention;
[0044] Figure 3 This is a structural diagram of the YOLOv11-segment model;
[0045] Figure 4 This is a structural diagram of the improved YOLOv11 model of the present invention;
[0046] Figure 5 Here is a diagram of the LEGM module structure;
[0047] Figure 6 Here is a diagram of the SEAM module structure;
[0048] Figure 7 Here is a structural diagram of the DySample dynamic upsampling module;
[0049] Figure 8 This is a structural diagram of the YOLOv11-OBB model;
[0050] Figure 9 A visual diagram illustrating the body temperature detection at the base of the ear of an individual pig. Detailed Implementation
[0051] The specific technical solution of the present invention will be further described in detail below with reference to specific examples.
[0052] S01. Video Data Acquisition:
[0053] This embodiment provides a feasible data collection environment and configuration to illustrate the feasible conditions for implementing the present invention in a group rearing scenario. The content does not constitute a limitation on the method of the present invention.
[0054] Breeding and filming environment: The drinking area of a closed rearing room was selected as the filming location, and the site was kept well-ventilated and clean. The camera was installed above the water trough, using a top-down angle to ensure that the pigs in the drinking area were fully covered in the image.
[0055] Imaging equipment: A dual-spectrum camera is used to achieve simultaneous acquisition of visible light (RGB) and thermal infrared (TIR) to meet the data source setting of claim S01. In an optional embodiment, the dual-spectrum camera is a Hikvision DS-2TD2636B-13 / P, installed approximately 2.2m directly above the drinking trough, with a working distance of approximately 2.1m, covering the drinking area from above, so that individuals can be clearly imaged when they bend down to drink. The acquisition system is as follows: Figure 2 As shown.
[0056] Acquisition method: The video stream is acquired at a fixed frame rate and frames are extracted at intervals to reduce redundancy and retain key pose samples; the frame extraction interval can be set according to the population density and behavior frequency. Data is written to a storage device (such as an NVR or workstation local disk) via Ethernet, and the name includes a timestamp and channel identifier (RGB / TIR).
[0057] The data collection site was a breeding room at a certain technology ranch, and the subjects were ten fattening Landrace pigs. The dual-spectrum acquisition system consisted of front-end acquisition equipment, transmission links, and back-end storage: the front end used a simultaneous visible light and thermal infrared acquisition mode, and the back end used a fiber optic switch to write data to a hard disk video recorder in real time. The entire acquisition process was non-contact, avoiding interference with the pigs' behavior.
[0058] S02. Temperature Texture Validation:
[0059] First, the validity of the temperature texture was verified. Image preprocessing and quantization were performed, converting RGB images to grayscale to eliminate color interference; TIR images retained their single-channel format. Both types of images were scaled proportionally to 128×128 and linearly stretched to 8-bit (0–255), with a uniform grayscale level L=256.
[0060] Subsequently, four classic texture features were extracted using the gray-level co-occurrence matrix: contrast, correlation, energy, and homogeneity. Given a set of pixel spacing d∈{1,2,4,8} and a set of orientations... The gray-level co-occurrence matrix is defined as follows: P(i,j;d,θ)={(x,y)|I(x,y)=i,(x+Δx,y+Δy)=j},
[0061] Take the normalized average of all 16 sets of matrices Q = |d|×|θ|:
[0062] Calculate four characteristics for an isotropic P(i,j):
[0063] This yields the four-dimensional feature vector of a single image: g=[Contrast,Correlation,Energy,Homogeneity] T ∈R 4 ,
[0064] To eliminate dimensional differences, z-score standardization is applied to the four-dimensional features. Assume there are K classes in total, and the number of samples in the k-th class is n. k The feature of the t-th sample is denoted as g. k,t The class mean is μ k The global mean is μ, and the total number of samples is μ.
[0065] After the four-dimensional features are standardized by z-score, the within-class scatter matrix S is defined. W and the inter-class scatter matrix S B :
[0066] And calculate the discrimination index according to Fisher's discrimination criterion:
[0067] Experimental design: 4938 images were sampled from both TIR and RGB dual-modal samples over three consecutive days within the same time period, representing ten identity categories. Results showed that the Fisher discriminant value J of TIR was... TIR =2.049, significantly higher than J for RGB. RGB =0.917. The experimental results show that the Fisher discriminant value of the TIR image is greater than that of the RGB image. Therefore, the thermal infrared mode is confirmed as the main mode for subsequent individual pig identification and body temperature measurement.
[0068] S03. Constructing a foreground region recognition model M1 for pigs:
[0069] One frame of image is extracted every second from a continuous video stream. The obtained thermal infrared image dataset is input into the YOLOv11-segment model for training. The network structure of the pig foreground region recognition model M1 is as follows. Figure 3 As shown, in one implementation, the training parameters include: Epoch = 200 iterations; BatchSize = 32; LearningRate = 0.001; SGD is used as the optimizer; the loss function includes pixel-level cross-entropy loss and Dice loss, and the optimal weight parameter file best.pt is obtained after training.
[0070] S04. Use the trained YOLOv11-segment model to perform foreground segmentation on the extracted frame images, and perform preprocessing using CLAHE and Gamma correction:
[0071] Input the extracted frame image into the offline-trained YOLOv11-segment model, and the model outputs a "pig foreground mask"; apply the foreground mask output by the model to the input image; set the pixel values outside the mask to zero to remove the background area.
[0072] Given the gray-level histogram H(i) of an image, CLAHE performs gray-level histogram equalization mapping on each local window of the image, performing gray-level distribution equalization on each local window (8×8 pixels), and setting the clip limit parameter clipLimit = 2.0 to prevent over-enhancement. Its mathematical expression is as follows:
[0073] Gamma correction is used to adjust the overall brightness response of an image, enhancing details in dark areas or suppressing overexposure in bright areas; its mathematical expression is:
[0074] γ = 1.2 is used to moderately enhance the contrast of temperature difference areas in infrared images.
[0075] After the above steps, a high-quality infrared thermal image dataset is generated for subsequent individual identification and body temperature detection.
[0076] S05. Construct an improved YOLOv11 pig identification model M2:
[0077] The SEAM (Self-Integrated Attention Mechanism) module introduces a multi-branch attention mechanism into the high semantic layer of the backbone, including channel attention, spatial attention, and cross-scale attention. Each branch independently calculates its weight graph before integration and fusion, used to generate a weight graph for channel, spatial, and scale information, such as... Figure 5 As shown.
[0078] The LEGM (Local Feature Embedding Global Feature) module: This module is added to the feature fusion stage between the Backbone and Head. It utilizes local branches to extract high-resolution details and global branches to capture the overall semantic structure. Through embedding operations, it achieves complementarity between the two types of features, thus maintaining stable recognition even under occlusion or partial loss. Figure 6 As shown.
[0079] The DySample (Dynamic Upsampling) module generates adaptive interpolation weights through a lightweight prediction network during the head upsampling stage, replacing the fixed interpolation method. This achieves high-resolution feature recovery with clear boundaries and faithful contour details, such as... Figure 7 As shown.
[0080] S06. Training of the M2 model for individual pig identification:
[0081] The image dataset enhanced with CLAHE and Gamma in step S04 is used as input for training. The network structure of the pig individual identification model M2 is as follows: Figure 4 As shown, the training parameters are set as follows: Epoch = 200; Batch Size = 32; Initial Learning Rate = 0.001; SGD optimizer is used; Loss functions include detection loss, classification loss, and confidence loss. After training, the optimal weight parameter file best.pt is obtained, which is used for individual pig identification inference in a group-raising scenario.
[0082] The results of the improved M2 ablation experiment for pig individual identification are shown in the table below:
[0083] Table 1 shows the ablation experimental results of visible light images, unprocessed thermal infrared images, and preprocessed thermal infrared images:
[0084]
[0085] Ablation experiments based on different network structures and three input modalities (RGB, unprocessed TIR, and preprocessed TIR) show that preprocessed TIR images achieve superior performance across various detection metrics. Taking the YOLOv11n baseline model as an example, its mAP under RGB input... 0.5 The mAP of YOLOv11n-LEGM was 0.754, while the mAP of the unpreprocessed TIR input was 0.917, and further improved to 0.928 after preprocessing. This indicates that thermal infrared modality and preprocessing strategies can effectively improve detection performance. Similarly, Precision increased from 0.687 for RGB input to 0.894 for unpreprocessed image input, and reached 0.880 after preprocessing; Recall increased from 0.741 to 0.828, and then to 0.873. The overall performance of the model was further improved after introducing different structural modules. Specifically, the mAP of YOLOv11n-LEGM under preprocessed TIR input was significantly improved. 0.5 The mAP reached 0.953, an improvement of approximately 0.025 compared to the baseline model; YOLOv11n-SEAM reached 0.950; and YOLOv11n-DySample reached 0.947. The multi-module combined model showed even more outstanding performance, with YOLOv11n-LEGM-SEAM-DySample achieving a higher mAP in preprocessed TIR modes. 0.5 The accuracy was improved to 0.960, Precision to 0.892, and Recall to 0.922, showing varying degrees of improvement in all three metrics compared to the single-module structure. Overall results show that, under the same network structure, preprocessed TIR images outperform unprocessed TIR images, and significantly outperform the RGB modality. Under the same modality, introducing LEGM, SEAM, and DySample modules all improve detection accuracy, while the combination of multiple modules achieves the highest detection accuracy. The results indicate that preprocessing thermal infrared images enhances temperature texture features, and the complementary effects of different modules on high-resolution details, cross-scale semantics, and dynamic upsampling synergistically enhance the model's detection capabilities in swarm-based scenarios.
[0086] S07. Construct ear root region recognition model M3:
[0087] The image dataset enhanced with CLAHE and Gamma obtained in step S04 is input into the YOLOv11-OBB model for training. The network structure of the ear root region recognition model M3 is as follows: Figure 8 As shown, the training parameters are set as follows: Epoch = 200; Batch Size = 32; Learning Rate = 0.001; SGD is used as the optimizer; the loss function includes image detection loss, angle loss and confidence loss. After training, the optimal weight parameter file best.pt is obtained, which is used for detection of the ear root region of pigs.
[0088] S08. Model Inference and Ear Root Detection:
[0089] During the inference phase, the thermal infrared images of the group-housed environment are sequentially input into the individual identification model M2 obtained in step S06 and the ear root detection model M3 obtained in step S07; M2 outputs the identity label and location box of each individual, and M3 identifies the left and right ear root regions of each pig and their corresponding prediction boxes based on these.
[0090] S09. Temperature matrix construction, optimal ear root selection, and result archiving:
[0091] First, based on the ear root prediction box coordinates, extract the corresponding region pixel grayscale values from the infrared frame image and then use linear interpolation to map the grayscale values to temperature values:
[0092] Where P is the pixel grayscale value, T max T min These represent the upper and lower limits of temperature for infrared images, respectively.
[0093] Then, temperature matrices Temp for the left and right ears were constructed respectively. L Temp R Calculate the temperature standard deviations σ_L and σ_R of the two matrices, compare the standard deviations of the left and right ear temperature matrices, and select the one with the smaller standard deviation as the side with more stable temperature.
[0094] Within the optimal ear root detection frame, the highest temperature is selected as the individual's body temperature output. The system can automatically display the detection results as an image overlay: rectangles represent the detection frame, and numerical labels display the detected individual's ID and current body temperature. A body temperature threshold can be set; if the detected temperature exceeds the preset threshold, an anomaly marker is generated. The system writes the individual ID, body temperature, and timestamp of each detection into an individual body temperature time-series record, ultimately outputting a CSV file for archiving. It also supports searching by identity and time range, and anomaly export functions. The individual pig ear root body temperature detection system is as follows: Figure 9 As shown.
[0095] The beneficial effects of this invention are as follows: By using thermal infrared video as the input data source, it avoids the problems of visible light imaging being greatly affected by day and night and lighting conditions, and the similarity of pig textures and the tendency to be dirty in visible light images. Thermal infrared imaging can stably acquire pig temperature texture information in environments with drastic changes in lighting, thereby obtaining accurate individual pig identification information. On this basis, the SEAM, LEGM, and DySample modules are introduced into the YOLOv11 model, which significantly improves the model's recognition ability and robustness in drinking trough obstruction scenarios. Through ear root detection and body temperature extraction, non-contact and accurate body temperature measurement of individual pigs is achieved, avoiding the stress response caused to individual pigs by traditional contact methods. At the same time, this method can accurately associate body temperature data with individual identity, breaking through the limitation of existing technologies that can only statistically monitor the body temperature of a group of pigs and cannot achieve continuous monitoring of individual pig body temperature, thus realizing true individual body temperature detection and continuous monitoring of pigs in a group-housed environment. In summary, the body temperature detection method for group-raised pigs based on temperature texture identification involved in this invention has the advantages of low cost, non-invasiveness, high adaptability, environmental robustness, personalization and accuracy. It is suitable for accurate monitoring and management of individual pig health in large-scale breeding scenarios and facilitates timely early warning of pig diseases.
Claims
1. A method for detecting individual body temperature in group-raised pigs based on temperature texture identification, characterized in that, Includes the following steps: Step S01: Video data acquisition. Visible light and thermal infrared video data of the herd of pigs are acquired simultaneously by a dual-spectrum camera set on the top of the breeding room, and frames are extracted at intervals to extract representative image frames as sample data. Step S02: Verify the validity of the temperature texture. Convert the visible light image (RGB) to grayscale to eliminate color interference, while maintaining the TIR single-channel format of the thermal infrared image. Scale both types of images to 128×128 pixels and stretch them to an 8-bit grayscale range (0–255). Set the grayscale level to L = 256, within the pixel spacing set ∈ {1,2,4,8} and the direction set... The gray-level co-occurrence matrix is calculated to extract four types of texture features: contrast, correlation, energy, and homogeneity. The obtained eigenvectors are standardized using z-score, and the within-class scatter matrix S is calculated. W and the inter-class scatter matrix S B The modal discrimination is evaluated according to Fisher's discrimination criterion, and the discrimination values of RGB and TIR are compared to determine the effectiveness of thermal infrared modality in texture representation in individual identification. The higher the discrimination value, the greater the inter-class difference and the smaller the intra-class difference, that is, the texture feature has a stronger individual discrimination ability. After confirming its effectiveness, proceed to step S03. Step S03: Construct a foreground region recognition model M1 for pigs. Input the thermal infrared image dataset obtained in step S01 into the YOLOv11-segment model for training to obtain the parameters of the optimal model M1 for foreground segmentation of pigs in group rearing scenarios. Step S04: Use the trained YOLOv11-segment model to perform foreground segmentation on the extracted frame images, set the non-foreground regions to zero to form a mask image, and then use CLAHE and Gamma correction for preprocessing to enhance the texture details and contrast of the thermal infrared images, thereby obtaining a thermal infrared image dataset for subsequent recognition. Step S05: Construct an improved YOLOv11 pig identification model M2, and introduce a self-integrated attention mechanism (SEAM) module into the high semantic feature layer of the backbone to enhance the expression of salient features; A Local Feature Embedding Global Feature (LEGM) module is added at the multi-scale feature fusion point of Backbone and Head to improve global semantic consistency; a Dynamic Upsampling (DySample) module is introduced in the Head upsampling stage to adaptively recover feature information of occluded areas, thereby improving recognition accuracy and stability. Step S06: Model training. The preprocessed thermal infrared image dataset obtained in step S03 is input into the improved YOLOv11 model described in step S05 for training, so as to obtain the optimal parameters for the individual pig identification model M2 in the group-raising scenario. Step S07: Construct ear root region recognition model M3. Based on the sample data obtained in step S03, construct the YOLOv11-OBB pig ear root region detection model, and label the rotated bounding boxes (OBB) of the left and right ear roots in the training set to obtain the optimal parameters of pig ear root region recognition model M3 for group rearing scenarios. Step S08: Model inference and ear root detection. In the inference stage, the thermal infrared images of the group rearing environment are sequentially input into the individual identification model M2 obtained in step S06 and the ear root detection model M3 obtained in step S07. M2 outputs the identity label and location box of each individual, and M3 identifies the left and right ear root regions of each pig and their corresponding prediction boxes based on this. Step S09: Temperature matrix construction, optimal ear root selection and result archiving. Extract pixel grayscale values from the left and right ear root prediction boxes of each pig and map them to temperature using linear interpolation. Calculate the standard deviation of the temperature matrices on both sides and select the side with the smaller standard deviation as the optimal ear root detection box. Within the optimal ear root detection box, the maximum value of the temperature matrix is taken as the body temperature result of the pig. Output the individual body temperature test results for each pig in a group-housed environment, and archive the results along with the individual identification and test time to form a traceable body temperature time-series record and provide functions for querying and exporting abnormal body temperatures.
2. The method for detecting individual body temperature in group-raised pigs based on temperature texture identification according to claim 1, characterized in that, The specific content of the temperature texture validity verification in step 2 is as follows: First, perform image preprocessing and quantization, convert the RGB image to grayscale to eliminate color information interference; keep the TIR image in its single-channel form; scale both types of images proportionally to 128×128 and linearly stretch them to 8-bit (0–255), and uniformly set the grayscale level L=256. Subsequently, four classic texture features were extracted using the gray-level co-occurrence matrix: contrast, correlation, energy, and homogeneity; given a set of pixel spacing d∈{1,2,4,8} and a set of orientations... The gray-level co-occurrence matrix is defined as follows: P(i,j;d,θ)={(x,y)∣I(x,y)=i,(x+Δx,y+Δy)=j}, Where (Δx,Δy) is determined by d and θ; i,j∈{0,...,L-1}, to obtain a more stable texture representation in terms of direction and scale, the normalized average is taken for all 16 sets of matrices Q=∣d∣×∣θ∣: Let the marginal distribution P be... x (i)=∑ j P(i,j),P y (j)=∑ i P(i,j); the mean and standard deviation are μ and μ, respectively. x =∑ i IP x (i), μ y =∑ j jp y (j); σ x ,σ y The corresponding standard deviation; Calculate four characteristics for an isotropic P(i,j): This yields the four-dimensional feature vector of a single image: g=[Contrast,Correlation,Enerrgy,Homogeneity] T ∈R 4 To eliminate dimensional differences, z-score standardization is applied to the four-dimensional features; assuming there are K categories in total, and the number of samples in the k-th category is n. k The feature of the t-th sample is denoted as g. k,t The class mean is μ k The global mean is μ, and the total number of samples is μ. To fairly measure the discriminative power of various features across different categories, the intra-class divergence S in the Fisher discriminant criterion is analyzed. W Inter-class divergence S B Equal weight estimation is used; specifically, S W S is the weighted average of the covariances within all categories. B The design uses an equally weighted sum of the covariances of the deviations of each category center from the overall center; this design avoids the problem of large category dominance caused by differences in sample size, and gives equal weight to small sample categories in discriminant analysis. Within-class divergence is defined as: The inter-class divergence is defined as: Modality discrimination is measured using the Fisher discriminant criterion, and the Fisher discriminant value is defined as follows: Where tr() is the matrix trace, and to improve numerical stability, S is calculated... W Add minimal diagonal regularization εI (ε=10) -8 ), that is, using tr(S) W Calculate the denominator using +εI).
3. The method for detecting individual body temperature in group-raised pigs based on temperature texture identification according to claim 1, characterized in that, The specific content of CLAHE mentioned in step S04 is as follows: Given the gray-level histogram H(i) of an image, CLAHE performs gray-level histogram equalization mapping on each local window of the image; its mathematical expression is: Where M×N is the number of pixels in the local window, P(i) represents the cumulative distribution function of pixel value i, which is used to remap the pixel grayscale value; CLAHE introduces the contrast clipping parameter clipLimit to limit the maximum number of pixels at each grayscale level in order to ensure the balance of the enhancement effect.
4. The method for detecting individual body temperature in group-raised pigs based on temperature texture identification according to claim 1, characterized in that, The specific content of Gamma correction in step S04 is: adjusting the overall brightness response of the image, enhancing details in dark areas or suppressing overexposure in bright areas; its mathematical expression is: Where I in and I out These represent the input and output pixel values, respectively. γ is the gamma value. When γ < 1, it enhances shadow details, and when γ > 1, it suppresses overexposure in highlights.
5. The method for detecting individual body temperature in group-raised pigs based on temperature texture identification according to claim 1, characterized in that, The specific content of the self-integrated attention mechanism (SEAM) mentioned in step S05 is as follows: attention sub-branches are established on multi-scale and multi-channel feature maps respectively. The branch types include channel attention, spatial attention and cross-scale attention. Each branch independently learns weights to enhance the feature representation at different levels. The attention results of each branch are integrated and fused to generate the final weight map, and the input features are weighted and modulated to highlight the effective texture of the foreground region and suppress the interference of the background and occlusions.
6. The method for detecting individual body temperature in group-raised pigs based on temperature texture identification according to claim 1, characterized in that, The specific content of the Local Feature Embedding Global Feature Extraction Module (LEGM) mentioned in step S05 is as follows: it uses local branches to extract fine-grained, high-resolution local texture features, while obtaining the semantic structure information of the target as a whole through global branches; in the feature fusion stage, local features are embedded into global features to achieve complementary enhancement of local details and global semantics; when the key area of the target is partially occluded, this module can use the global context to infer the category attributes of the missing area and preserve the detailed information.
7. The method for detecting individual body temperature in group-raised pigs based on temperature texture identification according to claim 1, characterized in that, The specific content of the dynamic upsampling (DySample) module mentioned in step S05 is as follows: The DySample module generates adaptive spatial interpolation weights through a lightweight prediction network based on the local context information of the input features; it uses these dynamic weights to perform spatial resolution magnification operations to replace the fixed interpolation method and achieve accurate restoration of spatial details; this module can effectively improve the contour clarity and detail restoration of high-resolution feature maps in scenarios with blurred boundaries or local missing features.
8. The method for detecting individual body temperature of group-raised pigs based on temperature texture identification according to claim 1, characterized in that, The temperature mapping calculation formula in step S09 is as follows: The temperature value is calculated linearly from the pixel grayscale value and can be used for temperature mapping in different types of infrared thermal imagers; P is the pixel grayscale value, P max P min These are the maximum and minimum pixel values of the grayscale image, respectively; T max T min These represent the corresponding maximum and minimum temperature values.