A pig crowding condition detection method and system, and a storage medium

By combining rotational target detection and sort tracking algorithms with distance and overlap rate detection, the detection criteria are dynamically adjusted, and manual review is introduced. This solves the problems of false detection and missed detection in pig crowding detection, and achieves efficient and accurate pig crowding detection.

CN120726544BActive Publication Date: 2025-11-11厦门农芯数字科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511222466.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-08-29
Publication Date
2025-11-11
Estimated Expiration
2045-08-29

AI Technical Summary

Technical Problem

Existing technologies have high false positive and false negative rates in detecting crowded pigs, especially in scenarios with narrow passages and dense pig populations. Detection algorithms based on horizontal bounding boxes have limited ability to identify rotating, overlapping, and occluded targets.

Method used

A rotating target detection algorithm is used to obtain the rotating bounding boxes of pigs. The sort tracking algorithm is used for counting, and the crowding of pigs is judged in parallel by a distance detection mechanism and an overlap rate detection mechanism. The detection criteria are dynamically adjusted, and a manual review process is introduced to ensure the accuracy of the detection results.

Benefits of technology

It significantly improves detection efficiency, reduces false positive and false negative rates, enhances the real-time performance and accuracy of detection, strengthens the robustness and adaptability of the system, and ensures the reliability and credibility of detection results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120726544B_ABST
    Figure CN120726544B_ABST
Patent Text Reader

Abstract

A method, system, and storage medium for detecting pig overcrowding include: acquiring a real-time video stream and using a rotating target detection algorithm to obtain the rotating bounding box of each pig; counting the pigs using a sort tracking algorithm based on the rotating bounding boxes; determining whether pig overcrowding exists through a parallel distance detection mechanism and an overlap rate detection mechanism; calculating the distance between the center points of pig pairs in each video frame of the real-time video stream, identifying and counting the number of first pig pairs whose center point distance is less than a distance threshold; calculating the overlap rate between the rotating bounding boxes of pig pairs in each video frame of the real-time video stream, identifying and counting the number of second pig pairs whose overlap rate is greater than a threshold; when both the number of first and second pig pairs are greater than or equal to the corresponding thresholds, pig overcrowding exists, and a crowded frame is acquired; based on the crowded frame, a crowded video segment containing the crowded frame is extracted; the crowded video segment is enhanced and then pushed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of pig target detection technology, and in particular to a method, system and storage medium for detecting crowded conditions in pigs. Background Technology

[0002] Currently, farms mostly rely on video monitoring systems for manual observation. However, due to the diverse camera angles, varied pig morphologies, and severe obstruction, manual monitoring suffers from low efficiency, delayed response, and a high risk of missed detections.

[0003] Although some studies have used deep learning-based target detection algorithms for pig counting and behavior analysis, most of them are based on horizontal bounding box detection, which has limited ability to identify rotating, overlapping, and occluded targets. Especially in scenarios with narrow passages and dense pig populations, the false detection rate and false negative rate are high.

[0004] Therefore, existing technologies suffer from high rates of false positives and false negatives in detecting overcrowding in pigs. Summary of the Invention

[0005] To solve the above-mentioned technical problems, the present invention provides a method for detecting overcrowding in pigs, which includes the following steps:

[0006] Acquire real-time video streams and use a rotating target detection algorithm to obtain the rotating bounding box of each pig;

[0007] Based on the rotated bounding box, the sort tracking algorithm is used to count the pigs and obtain the number of pigs.

[0008] Based on the rotated bounding box and real-time video stream, the system uses a distance detection mechanism and an overlap rate detection mechanism in parallel to determine whether there is overcrowding of pigs.

[0009] The distance detection mechanism includes: calculating the distance between the center points of pig pairs in each video frame of the real-time video stream; and determining and counting the number of pig pairs whose center point distance is less than the distance threshold based on a distance threshold.

[0010] The overlap rate detection mechanism includes: calculating the overlap rate between the rotated bounding boxes of pig pairs in each video frame of the real-time video stream, and based on the overlap rate threshold, determining and counting the number of second pig pairs that are greater than the overlap rate threshold;

[0011] Specifically, when the number of the first pig pair is greater than or equal to the threshold of the first pig pair, and the number of the second pig pair is greater than or equal to the threshold of the second pig pair, it is determined that there is a pig crowding situation and a crowding frame is obtained.

[0012] Based on crowded frames, extract crowded video segments containing crowded frames;

[0013] Enhance crowded video clips and push the enhanced crowded video clips.

[0014] Optionally, the distance detection mechanism specifically includes the following steps:

[0015] Based on the rotated bounding box, calculate the pixel width of each pig in each video frame within the real-time video stream;

[0016] Calculate the average pixel width of all pigs in each video frame;

[0017] Calculate the center point coordinates of the bounding box of each pig in each video frame, and calculate the center point distance between all pairs of pigs in each video frame;

[0018] Based on a distance threshold, count the number of the first pig pairs whose center point distance is less than the distance threshold.

[0019] Determine whether the number of pigs in the first pig pair is greater than or equal to the threshold of the first pig pair. If not, there is no pig crowding. If so, determine whether there is pig crowding in parallel with the overlap rate detection mechanism.

[0020] Optionally, the distance threshold is a preset multiple of the average pixel width.

[0021] Optionally, based on the rotated bounding box, the pixel width of each pig in each video frame within the real-time video stream is calculated, specifically including the following steps:

[0022] Based on the rotated bounding box, obtain the coordinates of the four vertices and the rotation angle of the rotated bounding box;

[0023] Calculate the pixel width perpendicular to the pig's body length direction based on the coordinates of the four vertices and the rotation angle.

[0024] Optionally, the overlap rate detection mechanism specifically includes the following steps:

[0025] Based on the rotated bounding box, obtain the coordinates of the four vertices of the rotated bounding box;

[0026] Calculate the overlap area between the pigs' rotating bounding boxes in each video frame of the real-time video stream according to the preset overlap area calculation formula.

[0027] Based on the overlapping area, calculate the overlap rate between the pigs' rotated bounding boxes in each video frame;

[0028] Based on the overlap rate threshold, determine and count the number of second pig pairs that are greater than the overlap rate threshold;

[0029] Determine whether the number of the second pig pair is greater than or equal to the threshold of the second pig pair. If not, there is no pig overcrowding. If so, determine whether there is pig overcrowding in parallel with the distance detection mechanism.

[0030] Optionally, the crowded video clips may be enhanced by at least one of the following steps:

[0031] At least one of the following should be superimposed on the video frame: the pig's rotated bounding box, ID identification information, distance detection result, or overlap rate detection result;

[0032] The system compresses crowded video clips using a preset video encoding format.

[0033] Obtain the recognition confidence score for each rotated bounding box, and add a timestamp to video frames with a recognition confidence score less than the confidence score threshold.

[0034] Optional, also includes:

[0035] Obtain the results of manual review of the crowded video clips; the results of manual review should include at least the actual number of pigs, the confirmation of the authenticity of the crowded event, and the crowding level label;

[0036] The results of manual verification are compared with the results of pig crowding detection, and a second verification is determined based on the comparison results.

[0037] Based on the comparison results, the training dataset corresponding to the pig crowding detection method is updated, and the pig crowding detection model corresponding to the pig crowding detection method is optimized.

[0038] Optionally, the manual verification results are compared with the pig crowding detection results, and based on the comparison results, it is determined whether a second verification is needed, including at least the following steps:

[0039] The actual number of pigs is compared with the count of pigs, and the difference between the two is obtained; if the difference is greater than the preset difference threshold, a second verification is required.

[0040] The results of the confirmation of the overcrowding event are compared with the results of the pig overcrowding detection to determine whether there is any misjudgment in the pig overcrowding detection results; if so, a second verification is required.

[0041] Corresponding to the pig crowding detection method described above, the present invention provides a pig crowding detection system, which includes:

[0042] The pig detection module is used to acquire real-time video streams and uses a rotating target detection algorithm to obtain the rotating bounding box of each pig.

[0043] The counting module is used to count pigs based on a rotated bounding box and a sort tracking algorithm to obtain the number of pigs.

[0044] The pig crowding detection module is used to determine whether pig crowding exists based on rotated bounding boxes and real-time video streams, using a distance detection mechanism and an overlap rate detection mechanism in parallel. The distance detection mechanism includes: calculating the distance between the center points of pig pairs in each video frame of the real-time video stream; and determining and counting the number of first pig pairs whose center point distance is less than the distance threshold based on a distance threshold. The overlap rate detection mechanism includes: calculating the overlap rate between the rotated bounding boxes of pig pairs in each video frame of the real-time video stream; and determining and counting the number of second pig pairs whose overlap rate is greater than the overlap rate threshold based on an overlap rate threshold. Specifically, when the number of first pig pairs is greater than or equal to the first pig pair threshold, and the number of second pig pairs is greater than or equal to the second pig pair threshold, pig crowding is determined to exist, and a crowded frame is acquired.

[0045] The congested video clip acquisition module is used to extract congested video clips containing congested frames based on congested frames.

[0046] The congested video clip processing module is used to enhance congested video clips and push the enhanced congested video clips.

[0047] In addition, to achieve the above objectives, the present invention also provides a computer-readable storage medium storing a pig crowding detection program, which, when executed by a processor, implements the steps of the pig crowding detection method described above.

[0048] Compared with existing technologies, this invention uses a rotating target detection algorithm to automatically obtain the rotating bounding box of each pig; based on the rotating bounding box, a sort tracking algorithm is used to count the pigs, obtaining the pig count, replacing manual counting and observation, significantly improving detection efficiency, and avoiding the lag and missed detection problems of manual observation; furthermore, by using a distance detection mechanism and an overlap rate detection mechanism in parallel to determine the pig crowding situation, the detection has high real-time performance, enabling this invention to quickly detect and respond at the moment crowding occurs, effectively solving the problem of delayed manual response and reducing false detection and missed detection rates.

[0049] Compared with existing technologies, this invention provides a dynamic distance threshold for subsequent distance detection by calculating the pixel width of each pig and the average pixel width of all pigs. This enables the detection mechanism to automatically adjust the detection standard according to the size of the pigs, enhancing the system's adaptability to pigs of different sizes.

[0050] Compared with existing technologies, this invention provides a simple and effective method for dynamically determining the distance threshold by setting it as a preset multiple of the average pixel width. This method can automatically adjust the detection criteria based on the overall body shape characteristics of the pig population, avoiding misjudgments caused by individual body shape differences, while enhancing the robustness and versatility of the system in different farming scenarios.

[0051] Compared with existing technologies, this invention can more accurately identify scenarios where crowding actually exists by precisely calculating the overlap rate between pairs of pigs.

[0052] Compared with existing technologies, this invention, by overlaying at least one of the following into video frames—a pig's rotated bounding box, ID identification information, distance detection results, and overlap rate detection results—allows reviewers to intuitively understand the AI's judgment criteria, thereby improving review efficiency and accuracy. This invention also employs a preset video encoding format to compress crowded video segments, reducing storage space and transmission time while maintaining video clarity. Furthermore, by obtaining the recognition confidence level corresponding to the rotated bounding box and adding timestamps to video frames with low confidence levels, this invention guides reviewers to focus on frames that may have detection errors, thus optimizing the review process.

[0053] Compared with existing technologies, this invention introduces a manual review process to double-check the detection results, ensuring their accuracy and reliability. By manually verifying the actual number of pigs, confirming the authenticity of overcrowding events, and labeling overcrowding levels, it provides more realistic and detailed decision-making basis for livestock management. Furthermore, the manual review results are compared with the AI ​​detection results, and the discrepancies are used to determine whether a second review is needed, further refining the review process and ensuring that every detection result is fully verified. The training dataset is updated and the detection model is optimized based on the comparison results, enabling continuous improvement and optimization of the detection method, and constantly enhancing the performance and accuracy of pig overcrowding detection.

[0054] Compared with existing technologies, this invention provides specific logic for comparing the actual number of pigs with the AI ​​counting results, as well as a method for comparing the confirmation results of overcrowding events with the AI ​​detection results. It clarifies the triggering conditions for secondary review, enhances the system's intelligent decision-making ability in the review process, avoids unnecessary review work, and improves overall work efficiency. Attached Figure Description

[0055] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this invention, illustrate exemplary embodiments of the invention and are used to explain the invention, but do not constitute an undue limitation of the invention. In the drawings:

[0056] Figure 1 This is a simplified flowchart of an embodiment of the pig crowding detection method of the present invention;

[0057] Figure 2 This is a schematic diagram illustrating the effect of an embodiment of the enhancement process in the pig crowding detection method of the present invention;

[0058] Figure 3 This is a framework diagram of an embodiment of the pig crowding detection system of the present invention. Detailed Implementation

[0059] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0060] like Figure 1 As shown, a method for detecting overcrowding in pigs according to the present invention includes the following steps:

[0061] Acquire real-time video streams and use a rotating target detection algorithm to obtain the rotating bounding box of each pig;

[0062] Based on the rotated bounding box, the sort tracking algorithm is used to count the pigs and obtain the number of pigs.

[0063] Based on the rotated bounding box and real-time video stream, the system uses a distance detection mechanism and an overlap rate detection mechanism in parallel to determine whether there is overcrowding of pigs.

[0064] The distance detection mechanism includes: calculating the distance between the center points of pig pairs in each video frame of the real-time video stream; and determining and counting the number of pig pairs whose center point distance is less than the distance threshold based on a distance threshold.

[0065] The overlap rate detection mechanism includes: calculating the overlap rate between the rotated bounding boxes of pig pairs in each video frame of the real-time video stream, and based on the overlap rate threshold, determining and counting the number of second pig pairs that are greater than the overlap rate threshold;

[0066] Specifically, when the number of the first pig pair is greater than or equal to the threshold of the first pig pair, and the number of the second pig pair is greater than or equal to the threshold of the second pig pair, it is determined that there is a pig crowding situation and a crowding frame is obtained.

[0067] Based on crowded frames, extract crowded video segments containing crowded frames;

[0068] Enhance crowded video clips and push the enhanced crowded video clips.

[0069] Understandably, a pig pair is any two distinct pigs.

[0070] In this embodiment, the threshold values ​​for the first pig pair and the threshold values ​​for the second pig pair can be the same preset value, preferably 5.

[0071] It should be noted that obtaining the rotated bounding box for each pig using a rotated object detection algorithm can be achieved using existing technology, and will not be elaborated upon here. The pig rotational object detection algorithm outputs an angled bounding box, providing basic data for subsequent pig counting and crowding assessment. This invention, based on rotated bounding boxes, uses a sort tracking algorithm to count pigs, obtaining the pig count by counting across lines.

[0072] Preferably, the method involves extracting crowded video segments containing crowded frames, specifically within the range of "segments containing crowded frames and pigs." This process relies heavily on the DeepStream recording control interface.

[0073] If you choose to extract the segment before the congested frame, you need to call DeepStream's backtracking recording function (based on pre-stored video data in a circular buffer) when congestion is detected to extract the video stream N seconds before the congested frame. This mode is suitable for tracing the cause of congestion events. The buffer size needs to be configured in advance to balance storage usage and backtracking duration (usually set to 5-10 seconds). No additional algorithm adjustments are required by calling DeepStream's start_recording() and stop_recording() interfaces.

[0074] This invention employs a rotating target detection algorithm to automatically obtain the rotating bounding box of each pig. Based on the rotating bounding box, a sort tracking algorithm is used to count the pigs, thus replacing manual counting and observation, significantly improving detection efficiency and avoiding the lag and missed detection problems of manual observation. Furthermore, by using a distance detection mechanism and an overlap rate detection mechanism in parallel to determine the pig crowding situation, the detection has high real-time performance. This allows the invention to quickly detect and respond to crowding at the moment it occurs, effectively solving the problem of delayed manual response and reducing the false detection and missed detection rates.

[0075] In this embodiment, the distance detection mechanism specifically includes the following steps:

[0076] Based on the rotated bounding box, calculate the pixel width of each pig in each video frame within the real-time video stream;

[0077] Calculate the average pixel width of all pigs in each video frame;

[0078] Calculate the center point coordinates of the bounding box of each pig in each video frame, and calculate the center point distance between all pairs of pigs in each video frame;

[0079] Based on a distance threshold, count the number of the first pig pairs whose center point distance is less than the distance threshold.

[0080] Determine whether the number of pigs in the first pig pair is greater than or equal to the threshold of the first pig pair. If not, there is no pig crowding. If so, determine whether there is pig crowding in parallel with the overlap rate detection mechanism.

[0081] Preferably, the calculation of the center point coordinates of the rotating bounding box of each pig in each video frame is specifically as follows: obtain the coordinates of the four vertices of the rotating bounding box of each pig (X1,Y1), (X2,Y2), (X3,Y3), (X4,Y4);

[0082] Calculate the center point coordinates (X, X) of the rotated bounding box based on the coordinates of the four vertices. center ,Y center );

[0083] Among them, X center = (X1 + X2 + X3 + X4) / 4, Y center = (Y1+Y2+Y3+Y4) / 4.

[0084] In this embodiment, the distance d between the center points of all pairs of pigs in each video frame is calculated. ij Specifically: ;in, , These are the X-coordinates of the center points of the rotated bounding boxes of the two pigs in the pig pair. , These are the Y-coordinates of the center points of the rotated bounding boxes of the two pigs in the pig pair.

[0085] This invention calculates the pixel width of each pig and the average pixel width of all pigs to provide a dynamic distance threshold for subsequent distance detection. This allows the detection mechanism to automatically adjust the detection standard according to the size of the pigs, enhancing the system's adaptability to pigs of different sizes.

[0086] In this embodiment, the distance threshold is a preset multiple of the average pixel width. Preferably, it is 2 times.

[0087] This invention provides a simple and effective method for dynamically determining distance thresholds by setting the distance threshold to a preset multiple of the average pixel width. This method can automatically adjust the detection criteria based on the overall body shape characteristics of the pig population, avoiding misjudgments caused by individual body shape differences, while enhancing the robustness and versatility of the system in different farming scenarios.

[0088] In this embodiment, the pixel width of each pig in each video frame within the real-time video stream is calculated based on the rotated bounding box, specifically including the following steps:

[0089] Based on the rotated bounding box, obtain the coordinates of the four vertices and the rotation angle of the rotated bounding box;

[0090] Calculate the pixel width perpendicular to the pig's body length direction based on the coordinates of the four vertices and the rotation angle.

[0091] In this embodiment, the overlap rate detection mechanism specifically includes the following steps:

[0092] Based on the rotated bounding box, obtain the coordinates of the four vertices of the rotated bounding box;

[0093] Calculate the overlap area between the pigs' rotating bounding boxes in each video frame of the real-time video stream according to the preset overlap area calculation formula.

[0094] Based on the overlapping area, calculate the overlap rate between the pigs' rotated bounding boxes in each video frame;

[0095] Based on the overlap rate threshold, determine and count the number of second pig pairs with an overlap rate greater than the threshold; preferably, the overlap rate threshold is 0.3.

[0096] Determine whether the number of the second pig pair is greater than or equal to the threshold of the second pig pair. If not, there is no pig overcrowding. If so, determine whether there is pig overcrowding in parallel with the distance detection mechanism.

[0097] Preferably, the overlapping area between the rotated bounding boxes of pigs in each video frame of the real-time video stream is calculated according to a preset overlapping area calculation formula, specifically including the following steps:

[0098] For each of the two rotated bounding boxes containing two pigs, obtain the coordinates of their four vertices, denoted as follows:

[0099] ;

[0100] as well as ;

[0101] Based on the preset overlap area calculation formula, the overlap area between the rotated bounding boxes of the pigs in each video frame of the real-time video stream is calculated; the specific formula for calculating the preset overlap area S is as follows:

[0102]

[0103] ;

[0104] In this embodiment, the overlap rate P between the pig pairs' rotated bounding boxes in each video frame is calculated based on the overlap area, specifically as follows: Where W is the sum of the areas of the two rotated bounding boxes of the two pigs, which can be calculated using polygon area calculation formulas (such as the shoelace formula).

[0105] This invention, by accurately calculating the overlap rate between pig pairs, can more accurately identify scenarios where true overcrowding exists.

[0106] In this embodiment, enhancing crowded video clips includes at least one of the following steps:

[0107] At least one of the following should be superimposed on the video frame: the pig's rotated bounding box, ID identification information, distance detection result, or overlap rate detection result (the superimposition effect can be referenced). Figure 2 );

[0108] The system compresses crowded video clips using a preset video encoding format.

[0109] Obtain the recognition confidence score for each rotated bounding box, and add a timestamp to video frames with a recognition confidence score less than a confidence score threshold. Preferably, the confidence score threshold is 0.5.

[0110] This invention improves review efficiency and accuracy by overlaying at least one of the following onto video frames: a pig's rotated bounding box, ID identification information, distance detection results, and overlap rate detection results. This allows reviewers to intuitively understand the AI's judgment criteria. Furthermore, this invention uses a preset video encoding format to compress crowded video segments, reducing storage space and transmission time while maintaining video clarity. Finally, by obtaining the recognition confidence level corresponding to the rotated bounding box and adding timestamps to video frames with low confidence levels, this invention guides reviewers to focus on frames that may have detection errors, thus optimizing the review process.

[0111] In this embodiment, it also includes:

[0112] Obtain the results of manual review of the crowded video clips (this can be done by issuing a notification for manual data entry or by having people submit their own reports); the results of manual review should include at least the actual number of pigs, the confirmation of the authenticity of the crowded event, and the crowding level label.

[0113] The results of manual verification are compared with the results of pig crowding detection, and a second verification is determined based on the comparison results.

[0114] Based on the comparison results, the training dataset corresponding to the pig crowding detection method is updated, and the pig crowding detection model corresponding to the pig crowding detection method is optimized.

[0115] This invention introduces a manual review process to double-check the detection results, ensuring their accuracy and reliability. Manual review verifies the actual number of pigs, confirms the authenticity of overcrowding events, and labels the overcrowding level, providing more realistic and detailed decision-making basis for livestock management. Furthermore, the manual review results are compared with the AI ​​detection results, and differences are used to determine whether a second review is needed, further refining the review process and ensuring that every detection result is fully verified. The training dataset is updated and the detection model is optimized based on the comparison results, enabling continuous improvement and optimization of the detection method, and constantly enhancing the performance and accuracy of pig overcrowding detection.

[0116] In this embodiment, the manual verification results are compared with the detection results of pig overcrowding, and based on the comparison results, it is determined whether a second verification is needed. This includes at least the following steps:

[0117] The actual number of pigs is compared with the count of pigs to obtain the difference between the two; if the difference is greater than the preset difference threshold, a second verification is required; preferably, the preset difference threshold is ±1.

[0118] The results of the confirmation of the overcrowding event are compared with the results of the pig overcrowding detection to determine whether there is any misjudgment in the pig overcrowding detection results; if so, a second verification is required.

[0119] This invention provides specific logic for comparing the actual number of pigs with the AI ​​counting results, as well as a method for comparing the confirmation results of overcrowding events with the AI ​​detection results. It clarifies the triggering conditions for secondary review, enhances the system's intelligent decision-making ability in the review process, avoids unnecessary review work, and improves overall work efficiency.

[0120] like Figure 3 As shown, the present invention also provides a pig crowding detection system, which includes:

[0121] The pig detection module 10 is used to acquire real-time video streams and use a rotating target detection algorithm to obtain the rotating bounding box of each pig.

[0122] The counting module 20 is used to count pigs based on a rotated bounding box and a sort tracking algorithm to obtain the number of pigs.

[0123] The pig crowding detection module 30 is used to determine whether pig crowding exists based on a rotating bounding box and a real-time video stream, using a distance detection mechanism and an overlap rate detection mechanism in parallel. The distance detection mechanism includes: calculating the distance between the center points of pig pairs in each video frame of the real-time video stream; and determining and counting the number of first pig pairs whose center point distance is less than the distance threshold based on a distance threshold. The overlap rate detection mechanism includes: calculating the overlap rate between the rotating bounding boxes of pig pairs in each video frame of the real-time video stream; and determining and counting the number of second pig pairs whose overlap rate is greater than the overlap rate threshold based on an overlap rate threshold. When the number of first pig pairs is greater than or equal to the first pig pair threshold, and the number of second pig pairs is greater than or equal to the second pig pair threshold, it is determined that pig crowding exists and a crowded frame is acquired.

[0124] The crowded video clip acquisition module 40 is used to extract crowded video clips containing crowded frames based on the crowded frames.

[0125] The crowded video clip processing module 50 is used to enhance crowded video clips and push the enhanced crowded video clips.

[0126] This invention also provides a computer-readable storage medium, which may be a computer-readable storage medium included in the memory described in the above embodiments; or it may be a standalone computer-readable storage medium not assembled into a device. The computer-readable storage medium stores at least one instruction, which is loaded and executed by a processor to implement... Figure 1 The method for detecting overcrowding in pigs is shown. The computer-readable storage medium may be a read-only memory, a disk, or an optical disk, etc.

[0127] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For system embodiments and storage medium embodiments, since they are basically similar to method embodiments, the descriptions are relatively simple; relevant parts can be referred to the descriptions in the method embodiments.

[0128] Furthermore, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0129] The foregoing description illustrates and describes preferred embodiments of the present invention. It should be understood that the present invention is not limited to the forms disclosed herein and should not be construed as excluding other embodiments. It can be used in various other combinations, modifications, and environments, and can be altered within the scope of the inventive concept by means of the foregoing teachings or techniques or knowledge in related fields. Any modifications and variations made by those skilled in the art that do not depart from the spirit and scope of the present invention should be within the protection scope of the appended claims.

Claims

1. A method for detecting overcrowding in pigs, characterized in that, Includes the following steps: Acquire real-time video streams and use a rotating target detection algorithm to obtain the rotating bounding box of each pig; Based on the rotated bounding box, the sort tracking algorithm is used to count the pigs and obtain the number of pigs. Based on the rotated bounding box and real-time video stream, the system uses a distance detection mechanism and an overlap rate detection mechanism in parallel to determine whether there is overcrowding of pigs. The distance detection mechanism includes: calculating the distance between the center points of pig pairs in each video frame of the real-time video stream; and determining and counting the number of pig pairs whose center point distance is less than the distance threshold based on a distance threshold. The overlap rate detection mechanism includes: calculating the overlap rate between the rotated bounding boxes of pig pairs in each video frame of the real-time video stream, and based on the overlap rate threshold, determining and counting the number of second pig pairs that are greater than the overlap rate threshold; Specifically, when the number of the first pig pair is greater than or equal to the threshold of the first pig pair, and the number of the second pig pair is greater than or equal to the threshold of the second pig pair, it is determined that there is a pig crowding situation and a crowding frame is obtained. Based on crowded frames, extract crowded video segments containing crowded frames; Enhance crowded video clips and push the enhanced crowded video clips; The distance detection mechanism specifically includes the following steps: Based on the rotated bounding box, calculate the pixel width of each pig in each video frame within the real-time video stream; Calculate the average pixel width of all pigs in each video frame; Calculate the center point coordinates of the bounding box of each pig in each video frame, and calculate the center point distance between all pairs of pigs in each video frame; Based on a distance threshold, count the number of the first pig pairs whose center point distance is less than the distance threshold. Determine whether the number of pigs in the first pig pair is greater than or equal to the threshold of the first pig pair. If not, there is no pig crowding. If so, determine whether there is pig crowding in parallel with the overlap rate detection mechanism. The overlap rate detection mechanism specifically includes the following steps: Based on the rotated bounding box, obtain the coordinates of the four vertices of the rotated bounding box; Calculate the overlap area between the pigs' rotating bounding boxes in each video frame of the real-time video stream according to the preset overlap area calculation formula. Based on the overlapping area, calculate the overlap rate between the pigs' rotated bounding boxes in each video frame; Based on the overlap rate threshold, determine and count the number of second pig pairs that are greater than the overlap rate threshold; Determine whether the number of the second pig pair is greater than or equal to the threshold of the second pig pair. If not, there is no pig overcrowding. If so, determine whether there is pig overcrowding in parallel with the distance detection mechanism.

2. The method for detecting overcrowding in pigs according to claim 1, characterized in that, The distance threshold is a preset multiple of the average pixel width.

3. The method for detecting overcrowding in pigs according to claim 1, characterized in that, Based on the rotated bounding box, the pixel width of each pig in each video frame within the real-time video stream is calculated, specifically including the following steps: Based on the rotated bounding box, obtain the coordinates of the four vertices and the rotation angle of the rotated bounding box; Calculate the pixel width perpendicular to the pig's body length direction based on the coordinates of the four vertices and the rotation angle.

4. The method for detecting overcrowding in pigs according to claim 1, characterized in that, Enhancing crowded video clips includes at least one of the following steps: At least one of the following should be superimposed on the video frame: the pig's rotated bounding box, ID identification information, distance detection result, or overlap rate detection result; The system compresses crowded video clips using a preset video encoding format. Obtain the recognition confidence score for each rotated bounding box, and add a timestamp to video frames with a recognition confidence score less than the confidence score threshold.

5. The method for detecting overcrowding in pigs according to claim 1, characterized in that, Also includes: Obtain the results of manual review of crowded video clips; The results of manual verification should include at least the actual number of pigs, the confirmation of the authenticity of the overcrowding event, and the overcrowding level label; The results of manual verification are compared with the results of pig crowding detection, and a second verification is determined based on the comparison results. Based on the comparison results, the training dataset corresponding to the pig crowding detection method is updated, and the pig crowding detection model corresponding to the pig crowding detection method is optimized.

6. The method for detecting overcrowding in pigs according to claim 5, characterized in that, The manual verification results are compared with the results of the pig crowding detection, and based on the comparison results, it is determined whether a second verification is needed. This process includes at least the following steps: The actual number of pigs is compared with the count of pigs, and the difference between the two is obtained; if the difference is greater than the preset difference threshold, a second verification is required. The results of the confirmation of the overcrowding event are compared with the results of the pig overcrowding detection to determine whether there is any misjudgment in the pig overcrowding detection results; if so, a second verification is required.

7. A system for detecting overcrowding in pigs, characterized in that, include: The pig detection module is used to acquire real-time video streams and uses a rotating target detection algorithm to obtain the rotating bounding box of each pig. The counting module is used to count pigs based on a rotated bounding box and a sort tracking algorithm to obtain the number of pigs. The pig crowding detection module is used to determine whether pig crowding exists based on a rotating bounding box and a real-time video stream, using both distance detection and overlap rate detection mechanisms in parallel. The distance detection mechanism includes: calculating the distance between the center points of pig pairs in each video frame of the real-time video stream; and determining and counting the number of first pig pairs whose center point distance is less than the distance threshold based on a distance threshold. The overlap rate detection mechanism includes: calculating the overlap rate between the rotated bounding boxes of pig pairs in each video frame of the real-time video stream; and determining and counting the number of second pig pairs whose overlap rate is greater than the overlap rate threshold based on an overlap rate threshold. Specifically, when the number of first pig pairs is greater than or equal to the first pig pair threshold, and the number of second pig pairs is greater than or equal to the second pig pair threshold, it is determined that there is pig crowding, and a crowded frame is obtained. The distance detection mechanism specifically includes the following steps: calculating the pixel width of each pig in each video frame of the real-time video stream based on the rotated bounding boxes; calculating the average pixel width of all pigs in each video frame; calculating the center point coordinates of the rotated bounding boxes of each pig in each video frame, and calculating the overlap rate between all pig pairs in each video frame. The following steps are taken: First, the distance between the center points of the pigs is calculated. Then, based on a distance threshold, the number of pig pairs whose center point distance is less than the distance threshold is counted. Next, it is determined whether the number of pig pairs is greater than or equal to the first pig pair threshold. If not, there is no pig crowding. If so, the overlap rate detection mechanism is used in parallel to determine whether pig crowding exists. The overlap rate detection mechanism specifically includes the following steps: First, based on the rotated bounding box, the coordinates of the four vertices of the rotated bounding box are obtained. Then, according to a preset overlap area calculation formula, the overlap area between the rotated bounding boxes of pig pairs in each video frame of the real-time video stream is calculated. Based on the overlap area, the overlap rate between the rotated bounding boxes of pig pairs in each video frame is calculated. Finally, based on the overlap rate threshold, the number of pig pairs whose center point distance is greater than the overlap rate threshold is determined and counted. Then, it is determined whether the number of pig pairs is greater than or equal to the second pig pair threshold. If not, there is no pig crowding. If so, the overlap rate detection mechanism is used in parallel to determine whether pig crowding exists. The congested video clip acquisition module is used to extract congested video clips containing congested frames based on congested frames. The congested video clip processing module is used to enhance congested video clips and push the enhanced congested video clips.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a pig crowding detection program, which, when executed by a processor, implements the steps of the pig crowding detection method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Breeding environment information prompting method and device, medium and electronic equipment

    CN112101290A

  • Adaptive bounding box merge method in blob analysis for video analytics

    US20180047193A1