Livestock outlier detection method, electronic device, and computer storage medium

By constructing a heatmap by selecting images at intervals from video segments, and calculating the distance and density scores of livestock, the problems of computational complexity and low accuracy in existing technologies are solved, and efficient and accurate livestock out-of-group identification is achieved.

CN121147812BActive Publication Date: 2026-06-23ANYOU BIOTECH GRP +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
ANYOU BIOTECH GRP
Filing Date
2025-08-27
Publication Date
2026-06-23

Smart Images

  • Figure CN121147812B_ABST
    Figure CN121147812B_ABST
Patent Text Reader

Abstract

The present application relates to livestock state monitoring technical field, especially in kind of livestock outlier detection method, electronic equipment and computer storage medium, including the following steps: S1. Construct data set; S2. Use target detection tool to carry out object detection to each picture in data set, draw the position mark of each livestock; S3. The position mark of all pictures in data set is superimposed in position, and the hotspot map is drawn;S4. According to the position mark in picture, the distance value of each livestock and the density score value of each livestock are calculated;S5. If the distance value and the density score value of certain livestock meet the outlier condition, the livestock is regarded as outlier;S6. If the time of continuously finding the livestock regarded as outlier exceeds time threshold, it is determined that there is livestock outlier in the fence;The present application does not need to be matched with identity tag, identification and tracking technology, and the calculation amount is small, fully considers space density, resource distribution, group activity mode, individual difference and other factors, and the outlier recognition precision and efficiency are significantly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of livestock condition monitoring technology, and in particular to a method for detecting livestock leaving the herd, an electronic device, and a computer storage medium. Background Technology

[0002] Livestock living in enclosures (such as pigs and sheep) typically exhibit gregarious behavior, maintaining a certain level of social interaction among themselves. However, in some cases, some livestock may exhibit autistic behavior. These isolated animals may face higher disease risks, decreased growth rates, and even negatively impact the dynamics of the entire herd.

[0003] To help livestock exhibiting autistic behavior, traditional methods mainly rely on manual patrols, which are time-consuming, labor-intensive, costly, and inefficient. Furthermore, the identification of autistic behavior depends heavily on worker experience, resulting in low reliability. To overcome the shortcomings of manual patrols, continuous video segments or single-frame images are currently commonly used to calculate livestock density by measuring the distance between livestock. Based on the livestock density, autistic livestock can be identified. However, the above methods have the following drawbacks: (1) Whether using continuous video segments or single-frame images, it is necessary to label and identify the livestock before tracking them, which makes the identification process complex and requires high equipment performance. There are also issues with the accuracy of identification and tracking. (2) Identifying autistic livestock through livestock density only considers spatial density factors and does not consider other factors such as resource distribution, group activity patterns, and individual differences, leading to biases in the identification of autistic behavior. For example, when resources (such as food and water) are unevenly distributed within the enclosure, some livestock may stay in low-density areas, either actively or passively. For instance, weaker individuals may avoid highly competitive high-density areas. When the group is resting, individuals may temporarily stay in low-density areas for foraging or drinking. Some livestock may choose to keep their distance from other individuals due to their personality (such as introverted individuals), physiological state (such as pregnancy or injury), or age (such as elderly individuals), resulting in them staying in low-density areas for a period of time. It can be seen that in the above situations, although some livestock are in low-density areas, they are still within the group's perception range (such as visual and auditory connections), and they have not truly separated from the group. (3) Using continuous video segments for out-of-group identification requires labeling, identifying, and tracking each frame of the video segment, which is computationally intensive and has limited efficiency. (4) Using single-frame images for out-of-group identification, livestock may be photographed during movement and mistakenly identified as either out of the group or not, resulting in misjudgment and missed judgment. Summary of the Invention

[0004] The technical problem to be solved by the present invention is to overcome the shortcomings of the prior art and provide a livestock out-of-group detection method, electronic device and computer storage medium that does not require the use of identity tags, identification and tracking technology, has low computational load, and fully considers factors such as spatial density, resource distribution, group activity patterns and individual differences, thereby significantly improving the accuracy and efficiency of out-of-group identification.

[0005] The technical solution adopted by this invention to solve its technical problem is: a method for detecting livestock leaving their herd, comprising the following steps:

[0006] S1. Collect video clips of livestock fences, select multiple images at intervals from the video clips, and construct a dataset;

[0007] S2. Use an object detection tool to perform object detection on each image in the dataset, draw the edges of all livestock in the image, and draw the location marker of each livestock based on the shape of the livestock edges;

[0008] S3. Overlay the location markers of all images in the dataset to create a heat map;

[0009] S4. Calculate the distance value of each animal based on the location markers in the image; at the same time, place the location markers in the image on the heat map and calculate the density score of each animal.

[0010] S5. If the distance value and density score of a certain animal in the picture meet the out-of-group condition, then the animal is considered to be out of the group;

[0011] S6. If the time period for which livestock are considered to be out of the herd exceeds the time threshold, it is determined that there are livestock out of the herd within the enclosure.

[0012] Furthermore, the higher the hotspot value of a point in the hotspot map, the higher the frequency of livestock appearing at that point.

[0013] Furthermore, in step S4, the distance value for each animal includes the nearest neighbor distance value and the nearest N neighbor distance value, wherein the nearest neighbor distance value is the distance between an animal and its closest animal, and the nearest N neighbor distance value is the average distance between an animal and its N closest animals.

[0014] Furthermore, the formula for calculating the density fraction value of each animal in step S4 is as follows:

[0015]

[0016] In the formula, DS represents the density fraction at a certain location; (x1, y1) represents the coordinates of the upper left corner of the location; (x2, y2) represents the coordinates of the lower right corner of the location; d ij This represents the hotspot value at coordinate point (i,j) in the hotspot graph.

[0017] Furthermore, the outlier condition in step S5 is as follows:

[0018]

[0019] In the formula, L1 is the nearest neighbor distance value of a certain animal; L N DS is the nearest N-neighbor distance value of a certain animal; DS is the density score of a certain animal. DS * These are preset thresholds.

[0020] Furthermore, the preset threshold The preset threshold is calculated by summing the average nearest neighbor distance values ​​of all livestock in all images with the error. The preset threshold DS is calculated by summing the average of the nearest N-neighbor distances of all livestock in all images and the error. * Take the percentiles of all livestock density scores in all images, sorted from smallest to largest.

[0021] Furthermore, the location marking in step S2 includes an outer frame marking and an ellipse marking, wherein the outer frame marking is used to draw the heat map and calculate the density score, and the ellipse marking is used to calculate the distance value.

[0022] Furthermore, in step S1, the time interval for selecting images from the video segment is four minutes; in step S6, the time threshold is one hour.

[0023] An electronic device includes a processor and a memory storing computer program instructions, the processor reading and executing the computer program instructions to implement the above-described livestock separation detection method.

[0024] A computer storage medium storing computer program instructions, which, when executed by a processor, implement the above-described livestock separation detection method.

[0025] The beneficial effects of this invention are:

[0026] (1) This invention first selects multiple images from a video segment at intervals to construct a dataset. Then, it overlays the location markers of all images in the dataset to draw a heat map, thereby obtaining the daily living area of ​​livestock within the enclosure. Then, it places the location markers in each image onto the heat map and calculates the density score of each animal. At the same time, it calculates the distance value of each animal. Based on whether the distance value and density score of the animal meet the out-of-group condition, it determines whether the animal in the image is considered out of group. Finally, it filters by time threshold. If the time for which the animal is considered out of group exceeds the time threshold, it is determined that there is an out-of-group animal within the enclosure. Compared with existing out-of-group identification methods, it does not require identity tags, identification and tracking technologies, has a small computational load, and fully considers factors such as spatial density, resource distribution, group activity patterns, and individual differences, thereby significantly improving the accuracy and efficiency of out-of-group identification.

[0027] (2) In this invention, the distance value of each animal includes the nearest neighbor distance value and the nearest N neighbor distance value. The nearest N neighbor distance value emphasizes the influence of regional density, which reduces the possibility of misjudgment of the nearest neighbor distance value, thereby further improving the accuracy of out-of-group identification.

[0028] (3) The location markers in this invention include outer frame markers and ellipse markers. The outer frame markers are used to draw heat maps and calculate density scores, ensuring that the heat maps can accurately reproduce the daily living areas of livestock and facilitate area calculation, saving computational energy and ensuring the accuracy of density scores. The ellipse markers are used to calculate distance values, which can accurately calculate distances, ensuring that the distance values ​​are close to the actual distances of livestock and simplifying the complexity of distance calculation, further reducing the amount of computation.

[0029] (4) The images in the dataset of this invention are selected at intervals from video segments. Compared with continuous video segments, this significantly reduces the amount of computation and greatly improves efficiency. Compared with single-frame images, it avoids misjudgment and missed judgment. Attached Figure Description

[0030] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0031] Figure 1 This is a flowchart of the livestock separation detection method in this invention;

[0032] Figure 2 This is a schematic diagram of the outer frame in this invention;

[0033] Figure 3 This is a schematic diagram of the elliptical markings in this invention;

[0034] Figure 4 This is a schematic diagram showing the superimposed positions of the outer frame markings in images taken at different times in this invention;

[0035] Figure 5This is a heat map formed by superimposing the positions marked on the outer frame of images taken at different times in this invention. Detailed Implementation

[0036] The present invention will now be further described in conjunction with the accompanying drawings and preferred embodiments. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.

[0037] Example 1

[0038] like Figure 1 As shown, a method for detecting livestock leaving their herd includes the following steps:

[0039] S1. Collect video clips of livestock fences, select multiple images at intervals from the video clips, and construct a dataset.

[0040] Images in the dataset are selected at intervals from video segments, which significantly reduces the amount of computation and greatly improves efficiency compared to continuous video segments; compared to single-frame images, it avoids false positives and false negatives.

[0041] Specifically, the time interval for selecting images from video segments can be set to a fixed time, such as four minutes. This makes the data to be processed relatively lightweight, which is particularly suitable for scenarios with limited network signal and device performance.

[0042] S2. Use an object detection tool to perform object detection on each image in the dataset, draw the edges of all livestock in the image, and draw the location marker of each livestock based on the shape of the livestock edges.

[0043] Specifically, Detectron2 was chosen as the target detection tool, which can quickly and accurately draw the location markers for each animal. Detectron2 is an existing technology. The location markers include outline markers and ellipse markers, such as... Figure 2 and Figure 3 As shown.

[0044] It should be noted that the purpose of the location markers is only to mark the location of each animal in the picture. It is not necessary to match a particular animal with a location marker. Therefore, there is no need to label the animals with identification tags or to identify and track the location markers in different pictures.

[0045] S3. Overlay the positional markers of all images in the dataset, such as... Figure 4 As shown, a heat map is drawn, as follows. Figure 5 As shown.

[0046] Specifically, the higher the heat value of a point in a heatmap, the higher the frequency of livestock appearing at that point. Figure 5The brighter the point, the better; the location marker used in drawing the heat map is the outer frame marker, ensuring that the heat map can accurately reproduce the daily living area of ​​livestock.

[0047] Since the images in the dataset were selected from video segments at time intervals, all images in the dataset were taken at different times. The bounding box markers were then overlaid using images taken at different times (e.g., ...). Figure 4 Different colors in the image represent livestock captured at different times, which can more fully and realistically recreate the daily living area of ​​livestock within the enclosure (i.e., the brighter areas in the heatmap), thus facilitating subsequent detection of livestock leaving the enclosure.

[0048] S4. Calculate the distance value of each animal based on the location markers in the image; at the same time, place the location markers in the image on the heat map and calculate the density score of each animal.

[0049] Specifically, the location markers used to calculate distance values ​​are elliptical, which can accurately calculate distances, ensuring that the distance values ​​are close to the actual distances of livestock, and simplifying the complexity of distance calculations, further reducing the amount of calculation; the location markers used to calculate density scores are outlined, which facilitates area calculations, saves computational energy, and ensures the accuracy of density score values.

[0050] The distance values ​​for each animal include the nearest neighbor distance (single-point distance) and the nearest N-neighbor distance (multi-point distance). The nearest neighbor distance is the distance between an animal and its closest neighbor, and the nearest N-neighbor distance is the average distance between an animal and its N closest neighbors. Specifically, N can be 3.

[0051] The nearest N-neighbor distance emphasizes the influence of region density, reducing the likelihood of misjudgment due to the nearest neighbor distance value, thereby further improving the accuracy of outlier identification.

[0052] like Figure 2 As shown, the formula for calculating the density fraction of each animal is as follows:

[0053]

[0054] In the formula, DS represents the density fraction at a certain location; (x1, y1) represents the coordinates of the upper left corner of the location; (x2, y2) represents the coordinates of the lower right corner of the location; d ij This represents the hotspot value at coordinate point (i,j) in the hotspot graph.

[0055] If livestock are located in their daily living area, the density score within the marked area of ​​their location will be higher; if livestock are located in a sparsely populated area (i.e., a darker area in the heatmap), the density score within the marked area of ​​their location will be lower, and they are very likely to be stray animals.

[0056] The following is a brief explanation of the hotspot value of a point in the heatmap:

[0057] Each image in the dataset contains multiple livestock, each marked with an outer frame. Pixels are evenly distributed within the marked area, and each pixel is assigned a value, such as 1. The outer frame markings of all images in the dataset are superimposed, and the values ​​of the same pixel are added together to obtain the hotspot value of that point in the hotspot map.

[0058] S5. If the distance value and density score of a certain animal in the picture meet the out-of-group condition, then the animal is considered to be out of the group.

[0059] Specifically, the outlier conditions are as follows:

[0060]

[0061] In the formula, L is the nearest neighbor distance value of a certain animal; L N DS represents the nearest N-neighbor distance of a certain animal; DS represents the density score of the certain animal; DS * These are preset thresholds.

[0062] Among them, the preset threshold The average of the nearest neighbor distances for all livestock in all images is summed with the error, where the error is multiplied by the standard deviation (σ1), for example, 3 times, i.e., 3σ1; a preset threshold is used. The average of the nearest N-neighbor distances for all livestock in all images is summed with the error, where the error is multiplied by the standard deviation (σ²), for example, 3 times, i.e., 3σ²; a preset threshold DS is used. * Take the percentile of all livestock density scores in all images, sorted from smallest to largest, for example, the fifth percentile (P5).

[0063] The following describes the preset threshold DS. * The fifth percentile is used as the reference point for explanation:

[0064] A percentile is a statistical term used to describe the value at a specific percentage position within a set of data. Specifically, if a set of data is sorted from smallest to largest and the corresponding cumulative percentiles are calculated, the data value corresponding to a particular percentile is called the percentile of that percentile. It can be represented as: a set of n observations arranged numerically, with the value at the p% position called the p-th percentile.

[0065] This application selects the fifth percentile of all livestock density scores for two reasons. Firstly, the fifth percentile effectively excludes outliers, preserving the majority of normal cases. The fifth percentile represents 95% of the samples above this value; that is, only the lowest 5% of livestock density scores are considered abnormal or noteworthy. These extremely low livestock density scores correspond to livestock in this application being in sparsely populated areas rather than their usual daily habitats, and few other livestock are near their location, making them highly likely to be out-of-group animals. Secondly, the fifth percentile has a theoretical basis in robust statistics. As a type of "trimmed percentile," the fifth percentile belongs to the categories of Winsorization and trimmed mean. One of the commonly used robust statistical methods that is insensitive to outliers is the 5% trimming of the mean, which removes the upper and lower 5% of the data before recalculating the average. This method is often used in finance, economics, and psychological experiments. The 5% Windsoring method compresses the upper and lower 5% extreme values ​​to P5 / P95, which is often used to prevent extreme values ​​from distorting statistics. The above methods have been proven in statistics to reduce the interference of extreme values, improve the robustness of the estimator, and are suitable for skewed or heavy-tailed distributions of data (such as real sensed data). Therefore, choosing the fifth percentile as the lower limit threshold is in line with the robust statistical design concept.

[0066] When resources (such as food and water) are unevenly distributed within an enclosure, vulnerable individuals may avoid highly competitive, high-density areas and remain in lower-density areas. Because these vulnerable individuals consistently stay in lower-density areas, these areas become their daily living zones, and their density scores may exceed preset thresholds. Although their nearest neighbor distance and nearest N-neighbor distance values ​​may exceed the corresponding preset thresholds, they are not considered outcasts. Similarly, when the group rests, individuals may temporarily reside in low-density areas while foraging. Since livestock tend to forage at food distribution points, these areas become their daily living zones. Some livestock may choose to keep their distance from other individuals due to their temperament, physiological state, or age, resulting in them residing in low-density areas for a period of time; however, these areas remain their own daily living zones.

[0067] S6. If livestock are continuously observed to be stray for a period exceeding a time threshold, then livestock within the enclosure are considered to have strayed from the herd. Specifically, the time threshold can be set to one hour.

[0068] Because the images in the dataset are selected at discrete times, livestock may be photographed while moving and mistakenly identified as out of the herd. Filtering out-of-herd results using a time threshold further improves the reliability of out-of-herd detection.

[0069] It should be noted that the images in the dataset are selected from video segments at time intervals. Therefore, the time threshold in step S6 can be replaced by the number of images threshold. When the number of images that are considered to be out-of-herd livestock exceeds the number of images threshold, it is determined that there are out-of-herd livestock in the enclosure, and an alarm is triggered.

[0070] This application first constructs a dataset by selecting multiple images at intervals from a video segment. Then, it overlays the location markers of all images in the dataset to create a heatmap with brightness differences, thereby obtaining the daily living area of ​​livestock within the enclosure. Next, it places the location markers in the images onto the heatmap and calculates the density score and distance value of each animal. Based on whether the distance and density scores of the animals meet the out-of-group criteria, it determines whether the animals in the images are considered out-of-group. Finally, it filters through a time threshold. If the time for which animals are continuously found to be considered out-of-group exceeds the time threshold, it is determined that there are out-of-group animals within the enclosure. Compared with existing out-of-group identification methods, this method does not require identity tags, identification, and tracking technologies, has a low computational load, and fully considers factors such as spatial density, resource distribution, group activity patterns, and individual differences, thus significantly improving the accuracy and efficiency of out-of-group identification.

[0071] Example 2

[0072] An electronic device includes a processor and a memory storing computer program instructions. The processor reads and executes the computer program instructions to implement the livestock separation detection method in Embodiment 1.

[0073] Example 3

[0074] A computer storage medium storing computer program instructions, which, when executed by a processor, implement the livestock separation detection method in Embodiment 1.

[0075] The above embodiments are only for illustrating the technical concept and features of the present invention. Their purpose is to enable those skilled in the art to understand the content of the present invention and implement it. They should not be used to limit the scope of protection of the present invention. All equivalent changes or modifications made in accordance with the spirit and essence of the present invention should be covered within the scope of protection of the present invention.

Claims

1. A method for detecting livestock leaving their herd, characterized in that, Includes the following steps: S1. Collect video clips of livestock fences, select multiple images at intervals from the video clips, and construct a dataset; S2. Use an object detection tool to perform object detection on each image in the dataset, draw the edges of all livestock in the image, and draw the location marker of each livestock based on the shape of the livestock edges; S3. Overlay the location markers of all images in the dataset to create a heat map; the higher the heat value of a point in the heat map, the higher the frequency of livestock appearing at that point; S4. Based on the location markers in the image, calculate the distance value for each animal; simultaneously, place the location markers in the image onto the heat map and calculate the density score for each animal using the following formula: In the formula, A density fraction value indicating a specific location; Mark the coordinates of the top left corner of a given location; Mark the coordinates of the bottom right corner of a certain location; Coordinates of points in the heat map Hotspot value at the location; S5. If the distance value and density score of a certain animal in the picture meet the out-of-group condition, then the animal is considered to be out of the group; S6. If the time period for which livestock are considered to be out of the herd exceeds the time threshold, it is determined that there are livestock out of the herd within the enclosure.

2. The livestock separation detection method according to claim 1, characterized in that, In step S4, the distance value for each animal includes the nearest neighbor distance value and the nearest N-neighbor distance value. The nearest neighbor distance value is the distance between an animal and its closest neighbor, and the nearest N-neighbor distance value is the average distance between an animal and its N closest neighbors.

3. The livestock separation detection method according to claim 2, characterized in that, The outlier condition in step S5 is as follows: In the formula, This represents the nearest neighbor distance value for a particular animal. This represents the nearest N-neighbor distance of a certain animal; This represents the density score of a certain type of livestock. , , These are preset thresholds.

4. The livestock separation detection method according to claim 3, characterized in that, The preset threshold The preset threshold is calculated by summing the average nearest neighbor distance values ​​of all livestock in all images with the error. The preset threshold is calculated by summing the average of the nearest N-neighbor distances of all livestock in all images and the resulting error. Take the percentiles of all livestock density scores in all images, sorted from smallest to largest.

5. The livestock separation detection method according to claim 1, characterized in that, In step S2, the location marking includes an outer frame marking and an ellipse marking. The outer frame marking is used to draw the heat map and calculate the density score, while the ellipse marking is used to calculate the distance value.

6. The livestock separation detection method according to claim 1, characterized in that, In step S1, the time interval for selecting images from the video segment is four minutes; in step S6, the time threshold is one hour.

7. An electronic device, characterized in that, It includes a processor and a memory storing computer program instructions, the processor reading and executing the computer program instructions to implement the livestock separation detection method as described in any one of claims 1-6.

8. A computer storage medium, characterized in that, The computer storage medium stores computer program instructions, which, when executed by a processor, implement the livestock separation detection method as described in any one of claims 1-6.