Pig movement amount detection method based on posture recognition

CN122990750APending Publication Date: 2026-10-27CHINA AGRI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

随着计算机视觉和人工智能技术在智慧畜牧领域的深度应用,无接触式生猪运动监测已逐步替代传统人工监测方式,但现有技术多聚焦于生猪姿态、行为的定性识别,缺乏对运动量的精准量化统计,无法区分有效运动与无效微动,检测误差大、量化精度低,难以满足规模化养殖的精细化监测需求

Benefits of technology

1. 本发明创新性构建"姿态先验约束+运动特征校验"的双通道融合机制:先以REViT-Net高精度姿态分类区分躺卧/非躺卧状态,再以帧间运动速度和位移的匹配度评分生成运动先验行为,当运动证据强烈时允许覆盖姿态误判,最终仅将"非躺卧且速度超过阈值"的帧判定为有效行走运动。该机制从源头过滤站立微动和躺卧抖动,使运动量统计纯度大幅提升,为生猪健康评估和养殖福利监测提供可信的量化数据基础。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122990750A_ABST
    Figure CN122990750A_ABST
Patent Text Reader

Abstract

The application discloses a live pig motion amount detection method based on posture recognition, which comprises the following steps: detecting and tracking a live pig target in a video stream to generate a single-target cropped image sequence; inputting a current frame image in the single-target cropped image sequence into a posture classification model to obtain an initial posture classification result of the live pig; tracking the position of the live pig target in continuous multiple frames of images to extract interframe motion features of the live pig target; adopting a posture-motion fusion decision strategy to determine the effective motion state of the live pig target in the current frame according to the initial posture classification result and the interframe motion features; and quantitatively counting the motion amount of the live pig target based on the effective motion state to generate a motion amount quantitative index. The application is based on posture recognition, combined with motion feature screening, invalid data filtering, multi-dimensional quantitative statistics and credibility evaluation to accurately detect the live pig motion amount, and solves the industry pain points of low quantitative precision, poor anti-interference ability and data distortion in the prior art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of intelligent pig farming technology, specifically relating to a method for detecting pig activity based on posture recognition. Background Technology

[0002] The amount of exercise in pigs is a core quantitative indicator reflecting their health status, growth and development level, activity level, and welfare. Accurately detecting parameters such as movement distance, duration, and frequency is crucial for achieving refined pig farming, early disease warning, and optimized farming environment. With the deep application of computer vision and artificial intelligence technologies in smart animal husbandry, contactless pig movement monitoring has gradually replaced traditional manual monitoring methods. However, existing technologies mostly focus on qualitative identification of pig posture and behavior, lacking precise quantitative statistics of movement volume. They cannot distinguish between effective and ineffective micro-movements, resulting in large detection errors and low quantitative accuracy, making it difficult to meet the refined monitoring needs of large-scale farming.

[0003] However, existing pig movement detection technologies have significant drawbacks: the complex environment inside pig farms, dense pig populations causing obstruction, and severe light interference make traditional methods insufficient for posture recognition, directly leading to large errors in movement statistics; most solutions simply count target displacement, failing to differentiate between effective walking movement, standing micro-movements, and lying still states by combining pig posture, resulting in a large amount of invalid shaking and image noise being included in the movement data, distorting the quantitative results; at the same time, existing technologies can only achieve qualitative judgment of behavior, lacking a systematic posture-movement fusion error correction mechanism and movement quantification model, and cannot output standardized, traceable movement indicators, making it difficult to support pig health assessment and breeding data analysis applications.

[0004] Therefore, there is an urgent need for a precise method for detecting the activity level of pigs, based on accurate posture recognition and combined with motion feature screening, invalid data filtering, and multi-dimensional quantitative statistics, to solve the industry pain points of low quantitative accuracy, poor anti-interference ability, and data distortion in existing technologies. Summary of the Invention

[0005] In view of this, the present invention proposes a method for detecting the activity level of pigs based on posture recognition. The present invention is based on accurate posture recognition and combines motion feature screening, invalid data filtering, multi-dimensional quantitative statistics and credibility assessment to accurately detect the activity level of pigs, which solves the industry pain points of low quantitative accuracy, poor anti-interference ability and data distortion of existing technologies.

[0006] To achieve the above objectives, the present invention provides the following technical solution: This invention provides a method for detecting the activity level of pigs based on posture recognition, comprising: Step S1: Acquire live pig video stream, detect and track live pig targets in the video stream, and generate a single-target cropped image sequence; Step S2: Input the current frame image from the single-target cropped image sequence into the pose classification model to obtain the initial pose classification result of the pig; the initial pose classification result includes lying posture and non-lying posture; Step S3: Track the position of the pig target in multiple consecutive frames of images and extract the inter-frame motion features of the pig target; the inter-frame motion features include inter-frame displacement and inter-frame motion velocity; Step S4: Using a pose-motion fusion decision strategy, determine the effective motion state of the pig target in the current frame based on the initial pose classification results and inter-frame motion features; whereby the effective motion state includes the effective walking motion state. Step S5: Based on the effective movement status, quantify and statistically analyze the movement amount of the target pig to generate a quantitative index of movement amount.

[0007] Preferably, the attitude-motion fusion decision strategy in step S4 includes: Based on inter-frame motion features, a matching score is calculated for preset behavior categories to obtain prior motion behaviors and corresponding prior motion confidence scores. The matching score is calculated based on the degree of conformity between the current inter-frame motion speed, inter-frame motion distance and the ideal feature range of each preset behavior category. Compare the prior motion behavior with the initial pose classification results; When the motion prior confidence score exceeds the preset confidence threshold and is inconsistent with the initial pose classification result, the motion prior behavior is used to cover the initial pose classification result to obtain the corrected pose classification result. Based on the corrected pose classification results and inter-frame motion characteristics, the effective motion state of the pig target in the current frame is determined.

[0008] Preferably, a matching score is performed on a preset behavior category based on inter-frame motion features, including: For each preset behavior category, set the ideal feature range for inter-frame motion speed and the ideal feature range for motion distance; The comprehensive matching score for each preset behavior category is calculated based on the degree of match between the current inter-frame motion speed and its ideal feature range, and the degree of match between the current inter-frame motion distance and its ideal feature range. The preset behavior category with the highest comprehensive matching score is selected as the prior behavior of the movement, and the highest comprehensive matching score is used as the prior confidence score of the movement.

[0009] Preferably, the specific steps for extracting inter-frame motion features in step S3 include: Calculate the coordinates of the center point of the pig target based on the coordinates of the body detection box. Calculate the inter-frame displacement distance and inter-frame motion speed based on the center point coordinates of the current frame and the preset number of frames before and after it; Set a speed smoothing window, perform mean smoothing on the inter-frame motion speed of multiple consecutive frames, and obtain the smoothed motion speed as the inter-frame motion speed in the inter-frame motion features. The inter-frame displacement distance is calculated based on pixel coordinates and mapped to the actual displacement distance by combining the pixel-to-actual-space scaling factor.

[0010] Preferably, the pose classification model in step S2 is the REViT-Net ensemble classification network; the REViT-Net ensemble classification network integrates the feature extraction results of three sub-networks, ResNet50, EfficientNet-B0 and ViT-B / 16, and improves the pose classification accuracy through multi-scale feature complementarity, providing a priori basis for pose quantification in the subsequent motion. The ResNet50 subnetwork is used to extract local convolutional features, the EfficientNet-B0 subnetwork is used to extract lightweight and efficient features, and the ViT-B / 16 subnetwork is used to extract global context features. The REViT-Net ensemble classification network fuses the output probabilities of the three subnetworks by arithmetic averaging to obtain the final initial pose classification result.

[0011] Preferably, the detection and tracking of pig targets in step S1 also includes a dedicated processing mechanism for occlusion scenarios in group-housed pigs: When the confidence score of the detection box for the pig target continuously falls below the preset low score threshold due to occlusion, the trajectory preservation mode is triggered: the target position is continuously predicted through Kalman filtering, and the update of appearance features is paused. When the target reappears after the occlusion is removed, ID recovery matching is performed: the IOU between the predicted trajectory box and the actual detection box of the reappearing target is calculated, and the historical appearance features of the reappearing target are extracted and compared with the current appearance features using cosine similarity; when the IOU is greater than the first matching threshold and the cosine similarity is greater than the second matching threshold, the reappearing target is associated with the historical trajectory, and its original tracking ID is restored. When the original ID cannot be recovered, the ID inheritance mechanism is executed: a tracking trajectory is created for the new ID, but the motion statistics sequence of the original ID is merged and marked with the motion statistics sequence of the new ID to avoid interruption or duplicate counting of motion statistics due to ID switching.

[0012] Preferably, the generation of quantitative indicators of exercise volume adopts an anti-interference statistical method based on posture-motion joint methods, specifically including: Establish a three-state motion volume statistics buffer, corresponding to the effective walking motion state, standing still state, and lying still state, respectively; Secondary verification of the standing still state: When multiple consecutive frames are determined to be in a standing still state, but the average motion speed of the preceding and following frames exceeds the effective walking speed threshold, the motion state of these frames is backtracked and corrected to an effective walking motion state, and the inter-frame displacement is added to the total motion distance. Filtering out brief jitters in a lying-down, stationary state: When an abnormally high inter-frame motion speed occurs in a lying-down state, but the preceding and following frames are both in a lying-down, stationary state, the motion data of that frame is identified as noise and removed from the motion statistics. Output the motion quantity indicators after interference suppression, including the original motion quantity, the corrected motion quantity, and the noise removal ratio.

[0013] Preferably, the training process of the pose classification model adopts a domain-adaptive training strategy tailored to the pig farming scenario: Construct a multi-scenario training dataset by collecting video data from different pig houses, under different lighting conditions, and with different pig densities, and label the data for each scenario. Scene-adaptive batch normalization is adopted: In the batch normalization layer of REViT-Net, independent mean and variance statistics are maintained for different aquaculture scenarios. During inference, the corresponding statistics are dynamically selected for normalization based on the scene recognition results of the current frame. Introducing a pose difficulty example mining mechanism: During training, samples whose model prediction confidence is within a preset fuzzy range are marked and accumulated, and the sampling weight of difficulty example samples is increased in the next training round. Temporal consistency constraints are adopted: the pose classification results of consecutive frames are added to the loss function as temporal smoothing constraints to reduce the impact of misclassification in a single frame on the overall pose sequence.

[0014] Preferably, it also includes a group behavior correlation analysis step based on the spatiotemporal distribution of exercise volume: Using a preset time window as a unit, the quantitative indicators of individual exercise volume of multiple pigs in the pigsty are aggregated in time and space to construct a heat map of group exercise volume; Identifying abnormal patterns of group movement: When the effective movement time of multiple pigs in a local area decreases in the same step and the posture classification results change to lying posture simultaneously, it is determined that there is an environmental stress event or abnormal group health in that area. Individual pigs within abnormal areas are ranked by their degree of activity deviation. Individuals whose deviation from the group mean exceeds a preset multiple are marked as key targets for attention, and a group health early warning report is generated.

[0015] Preferably, it also includes a reliability assessment and adaptive correction step for exercise volume statistics: The confidence score of the pig's exercise volume quantitative index is generated by calculating the mean confidence score of posture classification, tracking ID switching frequency, and the proportion of frames identified as invalid motion data for a single pig in a complete video period. When the confidence score is lower than the preset confidence threshold, data augmentation reanalysis is triggered: the target detection confidence threshold of the original video frames within the corresponding time window of the pig is increased and single target screening, posture classification and motion statistics are re-executed so that the high confidence results cover the original statistical values ​​of the low confidence period. Output a quantitative report of exercise volume including a credibility score, and mark and prompt periods with low credibility.

[0016] The present invention has achieved at least the following beneficial effects: 1. This invention innovatively constructs a dual-channel fusion mechanism of "posture prior constraints + motion feature verification": First, REViT-Net high-precision posture classification distinguishes between lying and non-lying states. Then, the matching degree score of inter-frame motion speed and displacement generates motion prior behavior. When the motion evidence is strong, it allows overriding posture misjudgments. Finally, only frames that are "non-lying and have a speed exceeding a threshold" are judged as valid walking motion. This mechanism filters out standing micro-movements and lying jitters from the source, significantly improving the purity of motion statistics and providing a reliable quantitative data foundation for pig health assessment and breeding welfare monitoring.

[0017] 2. This invention constructs a three-layer anti-interference mechanism: In the tracking layer, the movement statistics sequence before and after occlusion is merged and marked through an ID inheritance mechanism to avoid duplicate counting or statistical interruption of the same pig due to ID switching; in the state determination layer, backtracking correction and noise filtering through a three-state buffer are used to add walking frames that are mistakenly judged as standing still to the statistics and to remove single-frame jitter in the lying state; in the data quality layer, data augmentation reanalysis is triggered by confidence scoring to cover low-quality periods with high confidence. The three-layer mechanism works synergistically to ensure that the system can maintain the continuity and stability of movement statistics even in complex scenarios such as pig house occlusion, changes in lighting, and dense interference.

[0018] 3. This invention breaks through the limitations of traditional solutions that only output the movement parameters of a single pig. It constructs a spatiotemporal heat map of group movement, and by identifying abnormal patterns such as "multiple pigs synchronously decreasing movement and lying down in localized areas," it achieves early warning of environmental stress events or group health abnormalities. Simultaneously, it combines individual deviation ranking to locate abnormal individuals and establishes a correlation feedback model between movement volume and environmental parameters, providing data-driven decision-making support for livestock environment regulation and refined group management. This leap upgrades the invention from a simple "movement measurement tool" to a "livestock intelligent decision support system," significantly enhancing the industrial application value of the technical solution.

[0019] Other advantages, objectives, and features of the invention will be set forth in the following description and will be apparent to those skilled in the art in some respects, or may be learned by practice of the invention. The objectives and other advantages of the invention can be realized and obtained through the following description. Attached Figure Description

[0020] To make the objectives, technical solutions, and beneficial effects of this invention clearer, the following figures are provided for illustration: Figure 1 This is a flowchart illustrating the steps of a method for detecting the activity level of pigs based on posture recognition in an embodiment of the present invention. Figure 2 This is a schematic diagram illustrating the effect of the YOLOv26-based target detection model on identifying pig targets in an embodiment of the present invention; Figure 3 This is a spatiotemporal aggregation diagram of the activity of a group of fattening pigs in an embodiment of the present invention. Detailed Implementation

[0021] The preferred embodiments of the present invention will be described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.

[0022] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0023] To address the problems of low posture recognition accuracy, inability to filter invalid movements, large quantification errors in movement volume, lack of standardized statistical systems, and poor reliability of results in existing methods for detecting pig movement, this invention provides a posture recognition-based method for detecting pig movement volume. This invention, based on accurate posture recognition, combines movement feature screening, invalid data filtering, and multi-dimensional quantitative statistics to achieve accurate detection of pig movement volume.

[0024] Exemplary embodiments of the invention will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the invention are shown in the drawings, it should be understood that the invention can be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of the invention and to fully convey the scope of the invention to those skilled in the art.

[0025] To achieve the above objectives, the present invention provides the following technical solution: Example 1 like Figure 1As shown in this embodiment, the method for accurate detection of pig activity based on the collaborative action recognition of YOLOv26 and REViT-Net includes: S1. Video Acquisition and Preprocessing for Pig Target Detection and Tracking In this embodiment, video streams of the pigs are first acquired using camera equipment deployed above the pigsty. The camera equipment is installed at the center of the pigsty's roof, using a top-down angle to ensure coverage of the entire pigsty's activity area. The video stream's frame rate is set to a preset acquisition frame rate, as per [reference needed]. Figure 2 The image resolution is configured according to the actual needs of the aquaculture scenario.

[0026] The system automatically extracts frames from the acquired video stream to obtain a continuous image sequence. Pig target detection is performed on each frame, using a YOLOv26-based target detection model to identify and locate the pig targets in the image. The YOLOv26 detection model outputs the target detection bounding boxes for the pig's head and body, detection confidence scores, and target localization information.

[0027] In this embodiment, the YOLOv26 target detection model's network structure includes a backbone network, a neck network, and a detection head. The backbone network adopts a CSPDarknet structure, using a multi-scale feature extraction module to extract features from the input image, enhancing the feature discrimination between the pig's head and body at different scales. The feature maps output from the backbone network are fed into the neck network, which performs multi-scale feature fusion using an FPN (Feature Pyramid Network) and PAN (Path Aggregation Network) structure, combining shallow and deep features to improve the detection accuracy of small targets (pig heads). The feature maps output from the neck network are then fed into the detection head, which employs a decoupled structure, including a classification head and a regression head. The classification head outputs the pig target category (head / body) and detection confidence, while the regression head outputs the target detection box coordinates.

[0028] In this embodiment, non-maximum suppression (NMS) is performed on the detection results output by the detection head to remove redundant detection boxes and retain the detection boxes with the highest confidence. Further, a single-target screening strategy is executed based on the detection confidence: a pre-set confidence threshold is used to filter out detection boxes with confidence levels below the threshold, retaining valid detection boxes; valid detection boxes in a single image are sorted from highest to lowest confidence, and the detection box with the highest confidence is selected as the only valid detection box for that image; if there are no valid detection boxes in a single image (all detection boxes have confidence levels below the threshold), a default detection box (all coordinates are 0) and a confidence level of 0 are output, marking it as invalid localization.

[0029] In this embodiment, a single-target cropped image sequence is generated through the above detection and screening process. The effective detection box regions obtained are cropped from the original image, scaled and filled according to a preset size to obtain a standardized single-target cropped image, which is used for subsequent pose classification processing.

[0030] In this embodiment, a dedicated processing mechanism is adopted for the occlusion scenario of group-raised pigs. When the confidence score of the detection box continuously falls below a preset low score threshold due to occlusion of the pig target, the trajectory preservation mode is triggered: the target position is continuously predicted through Kalman filtering, and the update of appearance features is paused to avoid erroneous appearance features under occlusion conditions from polluting the historical feature database.

[0031] In this embodiment, when the target reappears after the occlusion is removed, ID recovery matching is performed: the Intersection over Union (IOU) between the predicted bounding box and the actual detection box of the reappearing target is calculated, and the historical appearance features of the reappearing target are extracted and compared with the current appearance features using cosine similarity. Let the predicted bounding box be... The actual detection box is The historical appearance feature vector is The current appearance feature vector is The IOU matching condition is:

[0032] The cosine similarity matching criteria are:

[0033] When both of the above conditions are met, the target will be re-associated with its historical trajectory, and its original tracking ID will be restored.

[0034] In this embodiment, when the original ID cannot be recovered, an ID inheritance mechanism is executed: a tracking trajectory is created for the new ID, but the motion statistics sequence of the original ID is merged and marked with the motion statistics sequence of the new ID. Let the original ID be... The new ID is The original ID's exercise statistics sequence is as follows Then, establish an ID mapping index:

[0035] In the subsequent stages of exercise volume statistics and report generation, based on the mapping index Will Exercise data and Historical exercise data is aggregated in chronological order and treated as a continuous exercise statistical sequence of the same entity, avoiding interruption or duplicate counting of exercise statistics due to ID switching.

[0036] S2. REViT-Net Pose Classification and Initial Pose Acquisition In this embodiment, the current frame image from the preprocessed single-target cropped image sequence is input into the REViT-Net ensemble classification network to obtain the initial posture classification results for the pigs. The initial posture classification results include lying postures and non-lying postures, where non-lying postures encompass standing and walking postures.

[0037] In this embodiment, the REViT-Net ensemble classification network integrates the feature extraction results of three sub-networks: ResNet50, EfficientNet-B0, and ViT-B / 16. It improves pose classification accuracy through multi-scale feature complementarity, providing prior knowledge of pose for subsequent motion quantification. The ResNet50 sub-network is used to extract local convolutional features, capturing local texture and edge information of pig images; the EfficientNet-B0 sub-network is used to extract lightweight and efficient features, reducing computational complexity while maintaining high feature representation capabilities; and the ViT-B / 16 sub-network is used to extract global contextual features, modeling the overall morphology of pigs and long-range dependencies.

[0038] In this embodiment, the workflow of the REViT-Net ensemble classification network is as follows: The preprocessed cropped pig image is input into three sub-networks, each performing forward inference independently and outputting its own classification probability distribution; the output probabilities of the three sub-networks are fused at the output layer using an arithmetic average to obtain the final initial pose classification probability.

[0039] in, For the merged category The final probability, For the first Category of subnetwork output The probability, These correspond to ResNet50, EfficientNet-B0, and ViT-B / 16, respectively.

[0040] In this embodiment, the category corresponding to the highest probability after fusion is selected as the initial pose classification result. Let the probability distribution after fusion be... ,in The probability of lying down posture. If the probability is a non-reclining posture, then the initial posture classification result is... Determined by the following formula:

[0041] In this embodiment, the REViT-Net ensemble classification network adopts a domain-adaptive training strategy tailored to the pig farming scenario during the training phase. A multi-scenario training dataset is constructed, collecting video data from different pigsties, under different lighting conditions, and with different pig densities. Scene labels are then applied to each scene's data. Scene-adaptive batch normalization is employed: in the REViT-Net batch normalization layer, independent mean and variance statistics are maintained for different farming scenarios. During inference, the corresponding statistics are dynamically selected for normalization based on the scene recognition result of the current frame.

[0042] In this embodiment, a pose difficulty example mining mechanism is introduced: during training, samples whose model prediction confidence falls within a preset ambiguity range are labeled and accumulated, and the sampling weight of difficulty example samples is increased in the next training round. Temporal consistency constraints are adopted: the pose classification results of consecutive frames are added to the loss function as a temporal smoothing constraint term to reduce the impact of single-frame misclassification on the overall pose sequence. The total loss function is expressed as:

[0043] in, Cross-entropy classification loss, For timing consistency constraints, These are the weighting coefficients for time-series constraints.

[0044] S3, Inter-frame motion feature extraction In this embodiment, the position of the pig target is tracked in multiple consecutive frames of images, and the inter-frame motion features of the pig target are extracted. The inter-frame motion features include inter-frame displacement and inter-frame motion velocity.

[0045] In this embodiment, the coordinates of the pig body detection frame are used. Calculate the center coordinates of the detection box :

[0046] In this embodiment, the inter-frame displacement distance is calculated based on the center point coordinates of the current frame and a preset number of frames before and after it. Let the current frame be the [number]th frame. Frames, select the preceding and following frames Frames (total) (Frame) participates in the calculation, the first Frame and the Inter-frame displacement distance for:

[0047] in, , For the first The coordinates of the center point of the frame.

[0048] In this embodiment, the inter-frame motion speed is calculated. This is the ratio of inter-frame displacement distance to inter-frame time interval:

[0049] in, The time interval between adjacent frames (determined by the video frame rate). For the first Frame and the The time interval between frames.

[0050] In this embodiment, a speed smoothing window is set to perform mean smoothing on the original inter-frame motion speeds of multiple consecutive frames to obtain smoothed motion speeds. :

[0051] in, The size of the speed smoothing window, For the first Frame and the Inter-frame motion speed.

[0052] In this embodiment, the inter-frame displacement distance is calculated based on pixel coordinates and mapped to the actual displacement distance using a pixel-to-actual-space scaling factor. Let the pixel-to-actual-space scaling factor be... (Unit: meters / pixel), then the actual displacement distance for:

[0053] S4. Attitude-Motion Fusion Decision and Effective Motion State Determination In this embodiment, a posture-motion fusion decision strategy is adopted to determine the effective motion state of the pig target in the current frame based on the initial posture classification results and inter-frame motion features. Effective motion states include effective walking motion states. Inter-frame motion data in ineffective walking motion states are identified as invalid motion data and are not included in subsequent motion quantity statistics.

[0054] In this embodiment, the attitude-motion fusion decision strategy includes the following steps: First, based on inter-frame motion features, a matching score is calculated for preset behavior categories to obtain prior motion behaviors and their corresponding prior motion confidence scores. The preset behavior categories include walking, standing, and lying down.

[0055] In this embodiment, for each preset behavior category, ideal feature ranges for inter-frame motion speed and motion distance are set respectively. Let the ideal speed range for walking behavior be... The ideal distance range is The ideal speed range for standing behavior is The ideal distance range is The ideal speed range for lying down is The ideal distance range is .

[0056] In this embodiment, a comprehensive matching score for each preset behavior category is calculated based on the degree of matching between the current inter-frame motion speed and its ideal feature range, and the degree of matching between the current inter-frame motion distance and its ideal feature range. For behavior categories... Its speed matching and distance matching They are respectively:

[0057]

[0058] in, For behavior categories Ideal velocity center value, For behavior categories Ideal distance from the center value, This represents the actual distance traveled in the current frame.

[0059] In this embodiment, the overall matching score is used. The weighted sum of speed matching and distance matching:

[0060] in, and These are the weighting coefficients for speed matching and distance matching, respectively. .

[0061] In this embodiment, the preset behavior category with the highest comprehensive matching score is selected as the prior behavior of the motion. The highest overall matching score will be used as the prior confidence score for the motion. :

[0062] In this embodiment, the prior behavior of motion is... Compared with the initial pose classification results Compare the results. When the prior confidence score of the motion... Exceeding the preset threshold Furthermore, if the initial pose classification result is inconsistent with the previous one, the motion prior behavior is used to overwrite the initial pose classification result to obtain a corrected pose classification result. :

[0063] In this embodiment, based on the corrected pose classification result and smoothed inter-frame motion speed The effective motion state of the pig target in the current frame is determined. The determination rules are as follows: when and When this occurs, it is determined to be a valid walking motion state; when and At that time, it is determined to be a standing still state; when At that time, it was determined to be a lying still state; in, The speed threshold for effective walking motion.

[0064] S5. Anti-interference motion statistics based on posture-motion combination In this embodiment, based on frame data determined to be in a valid walking motion state, the movement amount of the pig target is quantified and statistically analyzed to generate a quantitative index of movement amount. An anti-interference statistical method based on posture-motion joint methods is employed to improve the accuracy and robustness of movement amount statistics.

[0065] In this embodiment, a three-state motion statistics buffer is established, corresponding to the effective walking motion state, the standing still state, and the lying still state, respectively. Each buffer stores the inter-frame displacement distance, inter-frame motion speed, and timestamp information of each frame in the corresponding state.

[0066] In this embodiment, a secondary verification is performed on the standing still state. When multiple consecutive frames are determined to be in a standing still state, but the average motion speed of the preceding and following frames exceeds the effective walking speed threshold, the motion state of these frames is retrospectively corrected to an effective walking motion state, and the inter-frame displacement is added to the total motion distance. Let the sequence of consecutive standing still frames be... , before Frame and after The average motion speed of the frames are respectively and :

[0067] when and At that time, the frame sequence The motion state is backtracked and corrected to a valid walking motion state, and the inter-frame displacement distance of each frame in the sequence is accumulated into the total motion distance.

[0068] In this embodiment, brief jitters in a lying-down, stationary state are filtered out. When an abnormally high inter-frame motion speed occurs while the frame before and after the frame is in a lying-down, stationary state, the motion data of that frame is identified as noise and removed from the motion statistics. Let the first... The frame is judged to be in a lying, stationary state, but its inter-frame motion speed... And the first Frame and the All frames were judged to be in a lying, still state and , Then the first The inter-frame displacement distance is removed from the total motion distance.

[0069] In this embodiment, the output of the interference-resistant motion volume index includes the original motion volume. Correcting exercise volume and noise removal ratio :

[0070] S6. Group behavior correlation analysis based on the spatiotemporal distribution of exercise volume In this embodiment, the quantitative indicators of individual exercise volume of multiple pigs in the pigsty are spatiotemporally aggregated using a preset time window as a unit to construct a heat map of group exercise volume.

[0071] In this embodiment, the pigsty floor area is divided into spatial grids of a preset size. Within each time window, the sum of the effective movement time of all pigs in each grid is counted to generate a heat map of the group's movement. :

[0072] in, Spatial grid coordinates, For time window indexing, In the time window Located inside the grid The collection of live pigs in the middle, For live pigs In the time window Effective exercise duration within the body.

[0073] In this embodiment, abnormal patterns of group movement are identified. When the effective movement time of multiple pigs in a local area decreases synchronously and their posture classification results simultaneously change to a lying posture, it is determined that there is an environmental stress event or abnormal group health in that area. Let the local area be... In the time window and The average effective exercise duration within the time limit is as follows: and The average proportions of lying postures are as follows: and An exception is triggered when the following conditions are met:

[0074] in, The threshold for the percentage decrease in exercise duration. The threshold for the proportion of lying down posture.

[0075] In this embodiment, individual pigs within the abnormal area are ranked according to their degree of activity deviation, and individuals whose deviation from the group mean exceeds a preset multiple are marked as key targets for attention. Let the abnormal area be... Endogenous pigs The effective exercise duration is The regional mean is The standard deviation is Then the deviation for:

[0076] when ( When the threshold value is set to a preset multiple, the pig is marked as a key focus and a herd health early warning report is generated.

[0077] S7. Reliability Assessment and Adaptive Correction of Exercise Volume Statistics In this embodiment, the average confidence score of the pig's posture classification, the frequency of tracking ID switching, and the proportion of frames identified as invalid motion data are calculated for a single pig within a complete video period. The confidence score of the quantitative index of the pig's movement is then generated by combining these factors.

[0078] In this embodiment, the total number of video frames is set to... The mean confidence score for pose classification is 1. The tracking ID switching frequency is The number of invalid motion data frames is The percentage of frames identified as invalid motion data. for:

[0079] In this embodiment, a credibility score is generated by combining the results. :

[0080] in, , , These are the weights for the confidence mean, ID switching penalty, and invalid frame percentage, respectively. .

[0081] In this embodiment, when the credibility score Below the preset confidence threshold At that time, data augmentation reanalysis is triggered: the target detection confidence threshold is increased in the original video frames within the corresponding time window for that pig (from the original threshold). Increase to Then, single-target screening, posture classification, and motion statistics were re-executed to cover the original statistical values ​​of the low-confidence period with high-confidence results.

[0082] In this embodiment, a quantitative report of exercise volume is output, including a credibility score, and low-credibility periods are marked. The quantitative report of exercise volume includes: total exercise distance, effective exercise duration, resting duration, percentage of resting duration, activity frequency, credibility score, and low-credibility period markings.

[0083] Example 2 The above-described embodiment one provides a method for detecting pig activity based on posture recognition. Correspondingly, this embodiment provides a device for detecting pig activity based on posture recognition. The device provided in this embodiment can implement the pig activity detection method of embodiment one. This device can be implemented through software, hardware, or a combination of both. For ease of description, this embodiment is described by dividing it into various functional units. Of course, in implementation, the functions of each unit can be implemented in one or more software and / or hardware. For example, the device may include integrated or separate functional modules or functional units to perform the corresponding steps in the methods of embodiment one. Since the device in this embodiment is basically similar to the method embodiment, the description process of this embodiment is relatively simple. For relevant parts, please refer to the description of embodiment one. The embodiment of the pig activity detection device based on posture recognition provided by this invention is merely illustrative.

[0084] Specifically, the pig activity detection device based on posture recognition provided in this embodiment includes: The data acquisition and preprocessing unit is configured to acquire live pig video streams, detect and track live pig targets in the video streams, and generate single-target cropped image sequences.

[0085] In this embodiment, the data acquisition and preprocessing unit includes a video acquisition module, a target detection module, and an image cropping module. The video acquisition module acquires a video stream of the pigsty through a camera device; the target detection module uses a YOLOv26-based target detection model to identify and locate pig targets in the video frames, and outputs target detection boxes, detection confidence scores, and target location information; the image cropping module performs a single-target screening strategy based on the detection confidence score, retaining the detection box with the highest confidence score in a single image as the only valid detection box, and cropping the detection box region into a standardized image.

[0086] The pose recognition unit is configured to input the current frame image from a single-target cropped image sequence into the pose classification model to obtain the initial pose classification result of the pig.

[0087] In this embodiment, the posture recognition unit loads the REViT-Net ensemble classification network and the optimal model weights obtained from training, performs posture inference on the input cropped pig image, and outputs the initial posture classification result of lying down posture or non-lying down posture, providing a priori posture basis for subsequent quantification of exercise volume.

[0088] The motion feature extraction unit is configured to track the position of the pig target in multiple consecutive frames of images and extract the inter-frame motion features of the pig target.

[0089] In this embodiment, the motion feature extraction unit calculates the center point coordinates based on the coordinates of the pig body detection box, calculates the inter-frame displacement distance and inter-frame motion speed based on the center point coordinates of the current frame and the preset number of frames before and after, and performs mean smoothing on the original inter-frame motion speed of multiple consecutive frames through a speed smoothing window to obtain the smoothed motion speed.

[0090] The fusion decision unit is configured to adopt a posture-motion fusion decision strategy to determine the effective motion state of the pig target in the current frame based on the initial posture classification results and inter-frame motion features.

[0091] In this embodiment, the fusion decision unit includes a motion prior scoring module, a posture comparison and correction module, and an effective motion determination module. The motion prior scoring module scores the matching degree of preset behavior categories based on inter-frame motion features to obtain motion prior behavior and motion prior confidence score; the posture comparison and correction module compares the motion prior behavior with the initial posture classification result. When the motion prior confidence score exceeds a preset confidence threshold and is inconsistent with the initial posture classification result, the motion prior behavior is used to cover the initial posture classification result to obtain a corrected posture classification result; the effective motion determination module determines the effective motion state of the pig target based on the corrected posture classification result and inter-frame motion features.

[0092] The exercise volume statistics unit is configured to quantify the exercise volume of pig targets based on effective exercise status and generate quantitative exercise volume indicators.

[0093] In this embodiment, the motion volume statistics unit includes a three-state cache module, an anti-interference correction module, and an index generation module. The three-state cache module establishes a three-state motion volume statistics cache area for effective walking motion state, standing still state, and lying still state; the anti-interference correction module performs secondary verification and backtracking correction on the standing still state and filters out brief jitters in the lying still state; the index generation module outputs the original motion volume, the corrected motion volume, and the noise removal ratio.

[0094] The group analysis unit is configured to perform group behavior correlation analysis based on the spatiotemporal distribution of exercise volume.

[0095] In this embodiment, the group analysis unit includes a heatmap construction module, an anomaly pattern recognition module, and an early warning report generation module. The heatmap construction module aggregates the quantitative indicators of individual movement of multiple pigs in the pigsty in a spatiotemporal manner using a preset time window to construct a group movement heatmap, referencing... Figure 3 The abnormal pattern recognition module identifies abnormal group movement patterns where multiple pigs in a local area simultaneously experience a decrease in effective movement time and their posture classification results simultaneously change to a lying posture. The early warning report generation module sorts individual pigs in the abnormal area according to their degree of movement deviation, marks individuals whose deviation from the group mean exceeds a preset multiple as key attention targets, and generates a group health early warning report.

[0096] The credibility assessment unit is configured to perform credibility assessment and adaptive correction of exercise volume statistics.

[0097] In this embodiment, the credibility assessment unit includes a credibility scoring module, a reanalysis triggering module, and a report output module. The credibility scoring module calculates the average confidence score of a single pig's posture classification, the frequency of tracking ID switching, and the proportion of invalid motion data frames to generate a comprehensive credibility score. When the credibility score is lower than a preset credibility threshold, the reanalysis triggering module triggers data enhancement reanalysis to increase the target detection confidence threshold and re-execute motion statistics. The report output module outputs a quantitative report of motion volume containing the credibility score and marks low-credibility periods.

[0098] Example 3 This embodiment provides an electronic device corresponding to the posture recognition-based pig activity detection method provided in Embodiment 1. The electronic device can be an electronic device for client use, such as a mobile phone, laptop, tablet computer, desktop computer, etc., to execute the method of Embodiment 1.

[0099] like Figure 2 As shown, the electronic device includes a processor, a memory, a communication interface, and a bus. The processor, memory, and communication interface are connected via the bus to enable communication between them. The memory stores a computer program that can run on the processor. When the processor runs the computer program, it executes the method of Embodiment 1. The implementation principle and technical effects are similar to those of Embodiment 1, and will not be repeated here. Those skilled in the art will understand that... Figure 2 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computing device on which the present application is applied. The specific computing device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.

[0100] In a preferred embodiment, the logical instructions in the aforementioned memory can be implemented as software functional units and sold or used as independent products, and can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), and optical discs.

[0101] In a preferred embodiment, the processor can be any type of general-purpose processor such as a central processing unit (CPU) or a digital signal processor (DSP), and is not limited thereto.

[0102] Example 4 This embodiment provides a computer-readable storage medium for storing one or more programs, the one or more programs including computer instructions, which, when executed by a computer, cause the computer to perform the method provided in Embodiment 1 above.

[0103] In a preferred embodiment, the computer-readable storage medium may be a tangible device for holding and storing instructions executable, such as, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any combination thereof. The computer-readable storage medium stores computer program instructions that cause a computer to perform the method provided in Embodiment 1 above.

[0104] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (devices), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0105] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0106] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0107] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In the description of this specification, the terms "a preferred embodiment," "furthermore," "specifically," "in this embodiment," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the embodiments in this specification. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0108] Finally, it should be noted that the above preferred embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail through the above preferred embodiments, those skilled in the art should understand that various changes can be made to it in form and detail without departing from the scope defined by the claims of the present invention.

Claims

1. A method for detecting the activity level of pigs based on posture recognition, characterized in that, include: Step S1: Acquire live pig video stream, detect and track live pig targets in the video stream, and generate a single-target cropped image sequence; Step S2: Input the current frame image from the single-target cropped image sequence into the pose classification model to obtain the initial pose classification result of the pig; the initial pose classification result includes lying posture and non-lying posture; Step S3: Track the position of the pig target in multiple consecutive frames and extract the inter-frame motion features of the pig target; inter-frame... Motion features include inter-frame displacement and inter-frame motion velocity; Step S4: Using a pose-motion fusion decision strategy, determine the effective motion state of the pig target in the current frame based on the initial pose classification results and inter-frame motion features; whereby the effective motion state includes the effective walking motion state. Step S5: Based on the effective movement status, quantify and statistically analyze the movement amount of the target pig to generate a quantitative index of movement amount.

2. The method for detecting the activity level of pigs based on posture recognition according to claim 1, characterized in that, The attitude-motion fusion decision strategy in step S4 includes: Based on inter-frame motion features, a matching score is calculated for preset behavior categories to obtain prior motion behaviors and corresponding prior motion confidence scores. The matching score is calculated based on the degree of conformity between the current inter-frame motion speed, inter-frame motion distance and the ideal feature range of each preset behavior category. Compare the prior motion behavior with the initial pose classification results; When the motion prior confidence score exceeds the preset confidence threshold and is inconsistent with the initial pose classification result, the motion prior behavior is used to cover the initial pose classification result to obtain the corrected pose classification result. Based on the corrected pose classification results and inter-frame motion characteristics, the effective motion state of the pig target in the current frame is determined.

3. A method for detecting the activity level of pigs based on posture recognition according to claim 2, characterized in that, Matching scores are assigned to preset behavior categories based on inter-frame motion features, including: For each preset behavior category, set the ideal feature range for inter-frame motion speed and the ideal feature range for motion distance; The comprehensive matching score for each preset behavior category is calculated based on the degree of match between the current inter-frame motion speed and its ideal feature range, and the degree of match between the current inter-frame motion distance and its ideal feature range. The preset behavior category with the highest comprehensive matching score is selected as the prior behavior of the movement, and the highest comprehensive matching score is used as the prior confidence score of the movement.

4. A method for detecting the activity level of pigs based on posture recognition according to claim 1, characterized in that, The specific steps for extracting inter-frame motion features in step S3 include: Calculate the coordinates of the center point of the pig target based on the coordinates of the body detection box. Calculate the inter-frame displacement distance and inter-frame motion speed based on the center point coordinates of the current frame and the preset number of frames before and after it; Set a speed smoothing window, perform mean smoothing on the inter-frame motion speed of multiple consecutive frames, and obtain the smoothed motion speed as the inter-frame motion speed in the inter-frame motion features. The inter-frame displacement distance is calculated based on pixel coordinates and mapped to the actual displacement distance by combining the pixel-to-actual-space scaling factor.

5. A method for detecting the activity level of pigs based on posture recognition according to claim 1, characterized in that, The pose classification model in step S2 is the REViT-Net ensemble classification network. The REViT-Net ensemble classification network integrates the feature extraction results of three sub-networks: ResNet50, EfficientNet-B0, and ViT-B / 16. It improves the pose classification accuracy through multi-scale feature complementarity and provides a priori basis for subsequent motion quantification. The ResNet50 subnetwork is used to extract local convolutional features, the EfficientNet-B0 subnetwork is used to extract lightweight and efficient features, and the ViT-B / 16 subnetwork is used to extract global context features. The REViT-Net ensemble classification network fuses the output probabilities of the three subnetworks by arithmetic averaging to obtain the final initial pose classification result.

6. A method for detecting the activity level of pigs based on posture recognition according to claim 1, characterized in that, The detection and tracking of pig targets in step S1 also includes a dedicated processing mechanism for occlusion scenarios in group-housed pigs: When the confidence score of the detection box for the pig target continuously falls below the preset low score threshold due to occlusion, the trajectory preservation mode is triggered: the target position is continuously predicted through Kalman filtering, and the update of appearance features is paused. When the target reappears after the occlusion is removed, ID recovery matching is performed: the IOU between the predicted trajectory box and the actual detection box of the reappearing target is calculated, and the historical appearance features of the reappearing target are extracted and compared with the current appearance features using cosine similarity; when the IOU is greater than the first matching threshold and the cosine similarity is greater than the second matching threshold, the reappearing target is associated with the historical trajectory, and its original tracking ID is restored. When the original ID cannot be recovered, the ID inheritance mechanism is executed: a tracking trajectory is created for the new ID, but the motion statistics sequence of the original ID is merged and marked with the motion statistics sequence of the new ID to avoid interruption or duplicate counting of motion statistics due to ID switching.

7. A method for detecting the activity level of pigs based on posture recognition according to claim 1, characterized in that, The generation of quantitative indicators of exercise volume adopts an anti-interference statistical method based on posture-motion joint methods, specifically including: Establish a three-state motion volume statistics buffer, corresponding to the effective walking motion state, standing still state, and lying still state, respectively; Secondary verification of the standing still state: When multiple consecutive frames are determined to be in a standing still state, but the average motion speed of the preceding and following frames exceeds the effective walking speed threshold, the motion state of these frames is backtracked and corrected to an effective walking motion state, and the inter-frame displacement is added to the total motion distance. Filtering out brief jitters in a lying-down, stationary state: When an abnormally high inter-frame motion speed occurs in a lying-down state, but the preceding and following frames are both in a lying-down, stationary state, the motion data of that frame is identified as noise and removed from the motion statistics. Output the motion quantity indicators after interference suppression, including the original motion quantity, the corrected motion quantity, and the noise removal ratio.

8. A method for detecting the activity level of pigs based on posture recognition according to claim 7, characterized in that, The training process of the pose classification model adopts a domain-adaptive training strategy tailored to the pig farming scenario: Construct a multi-scenario training dataset by collecting video data from different pig houses, under different lighting conditions, and with different pig densities, and label the data for each scenario. Scene-adaptive batch normalization is adopted: In the batch normalization layer of REViT-Net, independent mean and variance statistics are maintained for different aquaculture scenarios. During inference, the corresponding statistics are dynamically selected for normalization based on the scene recognition results of the current frame. Introducing a pose difficulty example mining mechanism: During training, samples whose model prediction confidence is within a preset fuzzy range are marked and accumulated, and the sampling weight of difficulty example samples is increased in the next training round; Temporal consistency constraints are adopted: the pose classification results of consecutive frames are added to the loss function as temporal smoothing constraints to reduce the impact of misclassification in a single frame on the overall pose sequence.

9. A method for detecting the activity level of pigs based on posture recognition according to claim 1, characterized in that, It also includes a group behavior correlation analysis step based on the spatiotemporal distribution of exercise volume: Using a preset time window as a unit, the quantitative indicators of individual exercise volume of multiple pigs in the pigsty are aggregated in time and space to construct a heat map of group exercise volume; Identifying abnormal patterns of group movement: When the effective movement time of multiple pigs in a local area decreases in the same step and the posture classification results change to lying posture simultaneously, it is determined that there is an environmental stress event or abnormal group health in that area. Individual pigs within abnormal areas are ranked by their degree of activity deviation. Individuals whose deviation from the group mean exceeds a preset multiple are marked as key targets for attention, and a group health early warning report is generated.

10. A method for detecting the activity level of pigs based on posture recognition according to claim 1, characterized in that, It also includes reliability assessment and adaptive correction steps for exercise volume statistics: The confidence score of the pig's exercise volume quantitative index is generated by calculating the mean confidence score of posture classification, tracking ID switching frequency, and the proportion of frames identified as invalid motion data for a single pig in a complete video period. When the confidence score is lower than the preset confidence threshold, data augmentation reanalysis is triggered: the target detection confidence threshold of the original video frames within the corresponding time window of the pig is increased and single target screening, posture classification and motion statistics are re-executed so that the high confidence results cover the original statistical values ​​of the low confidence period. Output a quantitative report of exercise volume including a credibility score, and mark and prompt periods with low credibility.