A method, system, device and medium for counting cattle in a pasture

By dividing the open pasture into high and low density zones and using the characteristics of cattle ridges to disassemble the adhered contours, the problem of low counting results in the existing technology was solved, and accurate cattle counting was achieved.

CN122493496APending Publication Date: 2026-07-31GUIZHOU DONGCAI SUPPLY CHAIN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
GUIZHOU DONGCAI SUPPLY CHAIN TECH CO LTD
Filing Date
2026-06-29
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

Existing image counting methods misclassify areas of adhesion caused by cattle gathering or physical contact in open pastures as individual individuals, resulting in significantly lower counting results.

Method used

By responding to the spatial distribution of cattle in pasture images, high-density and low-density zones are divided, the ridgeline features of cattle are extracted, and the ridgeline direction is used to constrain the adhesion contours. The results are then corrected by combining historical point records, and the final point count is output.

Benefits of technology

Accurate counting of cattle stuck together in open pastures, with the count results matching the actual number, improves the reliability of management data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122493496A_ABST
    Figure CN122493496A_ABST
Patent Text Reader

Abstract

This invention discloses a method, system, device, and medium for counting cattle in an open-air pasture, belonging to the field of cattle counting technology. The method includes the following steps: responding to density assessment of the spatial distribution of cattle in a pasture image, dividing the pasture image into high-density and low-density zones according to the density assessment results; extracting the ridgeline features of cattle in the high-density zones; using the ridgeline features as morphological segmentation anchor points, applying ridgeline direction constraints to the adhesion contours of the high-density zones, decomposing the adhesion contours into a set of independent individual sub-contours; performing a first-level correction between the global cattle count and historical counting records, and outputting the final counting result. This invention extracts the ridgeline direction of each cattle's back, uses the ridgeline direction as a constraint to perform directional scanning of the adhesion contours, locates the extreme points of contour concavity between individuals, and extends cutting lines along these points to the opposite side, decomposing the connected adhesion regions into independent sub-contours corresponding to the actual number of individuals.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of cattle counting technology in pastures, specifically to a method, system, equipment, and medium for counting cattle in open-air pastures. Background Technology

[0002] In the daily management of open-air ranches, ranch staff typically need to periodically count the free-range cattle to monitor the number of animals and detect any abnormal losses. With the widespread adoption of drone aerial photography technology, automating cattle counting through image processing methods has become a viable approach.

[0003] Existing image counting methods use overall contour detection to directly identify continuous foreground regions in an image as independent individuals. When cattle in a pasture come into physical contact or partially obscure each other due to factors such as gathering to rest, concentrated feeding, or crowded passageways, the body contours of adjacent cattle will stick together in the image, merging into a single connected region.

[0004] In such cases, existing methods may misclassify the entire adhered area as a single individual, leading to a significantly lower count. For example, near a feeding trough on a ranch, more than ten cattle may be densely clustered together, their body outlines merging in aerial images to form a large area of ​​adhered foreground. Existing counting methods can only identify one or two counting units in this area, which is far from the actual number of individuals and cannot provide reliable data support for ranch management. Summary of the Invention

[0005] In view of the above-mentioned problems, the present invention provides a method, system, equipment and medium for counting cattle in open pastures.

[0006] Therefore, the technical problem solved by the present invention is that the existing method misjudges the entire adhesion area as a single individual, resulting in a seriously low counting result.

[0007] To solve the above-mentioned technical problems, the present invention provides the following technical solution: a method for counting cattle in an open-air pasture, comprising the following steps: responding to the density assessment of the spatial distribution of cattle in a pasture image, dividing the pasture image into high-density and low-density regions according to the density assessment results, and extracting the ridgeline features of cattle in the high-density regions; using the ridgeline features of cattle as morphological segmentation anchor points, applying ridgeline orientation constraints to the adhesion contours of the high-density regions, and decomposing the adhesion contours into a set of independent individual sub-contours; performing direct contour counting on the low-density regions, and enumerating the individual sub-contours in the high-density regions, summing the direct contour counts and the individual enumerations to obtain a global cattle count value; performing a first-level correction on the global cattle count value and historical counting records, and outputting the final counting result.

[0008] As a preferred embodiment of the cattle counting method in an open-air pasture according to the present invention, the step of performing the density assessment includes: performing local pixel ratio statistics on the pasture image according to the spatial grid to obtain the cattle body coverage density value of each grid; using the cattle body coverage density value as the basis to partition and label the pasture image, classifying the grids whose cattle body coverage density value exceeds the distribution mean into high-density partitions, and classifying the remaining grids into low-density partitions.

[0009] As a preferred embodiment of the cattle counting method in an open-air pasture according to the present invention, the step of extracting the ridgeline features of cattle in high-density zones includes: performing skeletalization processing on the foreground region of the cattle body in the high-density zone to obtain the central axis of the connected region; dividing the central axis of the connected region into segments according to the bifurcation nodes to obtain the central axis segments; calculating the ratio of the length to the width of each central axis segment and performing a filtering mechanism on the calculation results; and obtaining the ridgeline features of cattle in response to the results of the filtering mechanism. The screening mechanism includes the following steps: retaining the midline segments whose calculation results fall within the range of cattle body size proportions as candidate ridge segments; and removing the midline segments whose calculation results do not fall within the range of cattle body size proportions.

[0010] As a preferred embodiment of the cattle counting method in an open-air pasture according to the present invention, the step of determining the cattle body size ratio range for candidate ridge segments includes: taking the skeletal extension direction of the candidate ridge segment as the major axis direction, sampling the cross-sectional width of the connected region where the candidate ridge segment is located along the direction perpendicular to the major axis direction, and taking the median of the widths of each cross-section as the ridge segment width; taking the distance between the endpoints of the candidate ridge segment as the ridge segment length, calculating the ratio of the ridge segment length to the ridge segment width to obtain a screening value; when the screening value is within a preset ratio range, retaining the corresponding candidate ridge segment and extracting the cattle ridge features; when the screening value is not within the preset ratio range, deleting the corresponding candidate ridge segment.

[0011] As a preferred embodiment of the cattle counting method in an open-air pasture according to the present invention, the step of applying ridge direction constraints to the high-density partitioned adhesion contour includes: using the direction angle of the cattle ridge feature as the reference direction, searching for contour curvature values ​​along a scanning path perpendicular to the reference direction on the adhesion contour boundary; determining the zero-crossing point where the contour curvature value changes from positive to negative as the contour concavity extreme point; using the contour concavity extreme point as the starting position, extending a cutting line along the reference direction to the opposite boundary of the contour; and splitting the adhesion contour along the cutting line to obtain a set of independent individual sub-contours.

[0012] As a preferred embodiment of the cattle counting method in an open pasture according to the present invention, the step of searching for contour depression extreme points on the adhesion contour boundary includes: scanning the adhesion contour along a direction perpendicular to the reference direction, counting the number of intersections between the scan column and the contour boundary, and marking the scan column with a number of intersections greater than a preset threshold X as an adhesion column; calculating the local curvature of the contour boundary points within the adhesion column range, and taking the position where the local curvature changes from positive to negative as the zero-crossing candidate point; merging adjacent zero-crossing candidate points according to the ridge spacing constraint, and determining the merged zero-crossing candidate point as the contour depression extreme point.

[0013] In a preferred embodiment of the cattle counting method for an open-air pasture according to the present invention, the step of performing the first-level correction includes: extracting the counting sequence of consecutive times from the historical counting records; performing trend fitting on the counting sequence to obtain the predicted counting value for the current time; using the difference between the global cattle count value and the predicted counting value as the deviation, and using the historical fluctuation range of the counting sequence as the reference range; marking the global cattle count values ​​whose deviation exceeds the reference range as count values ​​to be reviewed, and performing a second-level judgment on the count values ​​to be reviewed; and determining the global cattle count values ​​whose deviation is within the reference range as the final counting result. The steps for performing a secondary judgment on the count value to be verified include: performing high-density partitioning on the pasture image corresponding to the count value to be verified to obtain a refined density distribution; redetermining the boundary of the high-density partition based on the refined density distribution, and performing ridge feature extraction and adhesion contour segmentation on the redefined high-density partition again; replacing the count value to be verified with the count value obtained after verification as the final point count result.

[0014] This invention provides a cattle counting system for open-air pastures.

[0015] To solve the above-mentioned technical problems, the present invention provides the following technical solution: an open-air pasture cattle counting system, comprising: an extraction module, which, based on the density assessment of the spatial distribution of cattle in a pasture image, divides the pasture image into high-density and low-density zones according to the density assessment results, and extracts the ridgeline features of cattle in the high-density zones; a decomposition module, which applies ridgeline orientation constraints to the adhered contours in the high-density zones, decomposing the adhered contours into a set of independent individual sub-contours; a counting module, which performs direct contour counting in the low-density zones and enumerates the individual sub-contours in the high-density zones to obtain a global cattle count value; and an output module, which performs a first-level correction between the global cattle count value and historical counting records, and outputs the final counting result.

[0016] The present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the above-described method for counting cattle in an open pasture.

[0017] The present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the above-described method for counting cattle in an open pasture.

[0018] The beneficial effects of the present invention are as follows: For high-density adhesion areas appearing in the image, the present invention extracts the ridgeline direction of each cow's back, uses the ridgeline direction as a constraint to perform directional scanning of the adhesion contour, locates the contour concavity extreme point between individuals, and extends the cutting line along the point to the opposite side, decomposing the connected adhesion area into independent sub-contours that correspond to the actual number of individuals.

[0019] For example, in scenarios where cattle are clustered together in the feeding trough, this invention can identify and separate individuals that are stuck together based on the ridgeline characteristics of each cattle in different directions, so that the counting results in that area can be restored from the original low to match the actual number. Attached Figure Description

[0020] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0021] Figure 1 This is a flowchart illustrating an overall method for counting cattle in an open-air pasture, as provided in one embodiment of the present invention.

[0022] Figure 2 This is a schematic diagram of a pasture image illustrating a method for counting cattle in an open-air pasture, as provided in one embodiment of the present invention. Detailed Implementation

[0023] To make the present invention more apparent and understandable, the specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the protection scope of the present invention.

[0024] Example 1, referring to Figure 1 This is one embodiment of the present invention, which provides a method for counting cattle in an open pasture, including the following steps: S1. In response to the density assessment of the spatial distribution of cattle in the pasture image, the pasture image is divided into high-density and low-density regions according to the density assessment results, and the ridge line features of cattle are extracted for the high-density regions.

[0025] S2. Using the ridgeline features of the cattle as morphological segmentation anchor points, apply ridgeline direction constraints to the high-density partitioned adhesion contours, and decompose the adhesion contours into a set of independent individual sub-contours.

[0026] S3. Perform direct contour counting on the low-density partition and individual enumeration on the set of independent individual sub-contours in the high-density partition. Summate the direct contour count and the individual enumeration to obtain the global cattle count value.

[0027] S4. Perform a first-level correction between the global cattle count value and the historical point record, and output the final point result.

[0028] It should be understood that existing image counting methods use overall contour detection to directly identify continuous foreground regions in an image as independent individuals. When cattle in a pasture come into physical contact or partially obscure each other due to factors such as gathering to rest, concentrated feeding, or crowded passageways, the body contours of adjacent cattle will stick together in the image, merging into a single connected region.

[0029] In this situation, existing methods may misclassify the entire adhesion area as a single individual, resulting in a significantly lower count.

[0030] The present invention extracts the ridgeline direction of each cow's back through steps S1-S4, performs directional scanning of the adhesion contour with the ridgeline direction as a constraint, locates the contour concavity extreme point between individuals, and extends the cutting line along the point to the opposite side, decomposing the connected region of adhesion into independent sub-contours that correspond to the actual number of individuals.

[0031] For example, in scenarios where cattle are clustered together in the feeding trough, this invention can identify and separate individuals that are stuck together based on the ridgeline characteristics of each cattle in different directions, so that the counting results in that area can be restored from the original low to match the actual number.

[0032] Example 2, refer to Figures 1-2 As an embodiment of the present invention, based on the previous embodiment, a method for counting cattle in an open-air pasture is provided, comprising: like Figure 2 As shown, S1, in response to the density assessment of the spatial distribution of cattle in the pasture image, divides the pasture image into high-density and low-density regions according to the density assessment results, and extracts the ridgeline features of cattle for the high-density regions.

[0033] It's important to know that the images were taken from above by a drone over the pasture. The pasture images show approximately 40 cattle, with about 30 scattered throughout the pasture and another 10 densely clustered near the supplemental feeding troughs.

[0034] The density assessment steps include S1.1 to S1.2: S1.1 Perform local pixel ratio statistics on the pasture image according to the spatial grid to obtain the cow body coverage density value of each grid.

[0035] The pasture image is divided into multiple spatial grids. Pixels in each spatial grid are detected, and the ratio of the number of foreground pixels of cattle to the total number of pixels in the grid is counted. This ratio is used as the cattle coverage density value of that grid.

[0036] In this embodiment, the pasture image is uniformly divided into 576 grids of 32×18 pixels. Color and texture thresholding are performed on the pixels within each grid to extract the foreground region of the cow.

[0037] Taking a grid near the feeding trough as an example, the grid contains 14,400 pixels. After foreground extraction, 9,800 cow body pixels were identified. Therefore, the cow body coverage density of the grid is 9,800 ÷ 14,400 ≈ 0.68. In the middle of the grassland, there is a sparse grid with only 720 pixels for the cow body, and the density value is 720÷14400=0.05.

[0038] S1.2. Based on the cattle body cover density value, the pasture image is divided into zones and labeled. Grids with cattle body cover density values ​​exceeding the distribution mean are assigned to high-density zones, and the remaining grids are assigned to low-density zones.

[0039] Calculate the mean distribution of cattle body cover density values, and use this mean as a threshold to classify and label all grids. Grids exceeding the mean are marked as high-density partitions, and the remaining grids are marked as low-density partitions, thus completing the partitioning of the pasture image.

[0040] Taking this embodiment as an example, the average cow body coverage density value distribution of the 576 grids is 0.12. Grids with density values ​​higher than 0.12 are classified into high-density zones, concentrated in a continuous area near the feeding trough, totaling 38 grids; The remaining 538 grid density values ​​are all below 0.12, and are classified as low-density zones, covering most of the grassland area.

[0041] The steps for extracting ridgeline features from high-density regions of cattle include S1.3~S1.6: S1.3. Skeletalize the foreground region of the cow body within the high-density partition to obtain the central axis of the connected region.

[0042] For example, after binarization, the foreground area of ​​the cows in the high-density partition presents a large connected block formed by multiple cows sticking together, with an area of ​​approximately 18,600 square pixels.

[0043] The skeletonization algorithm is applied to the connected component, and after iterative refinement, a central axis network with a width of one pixel is obtained. The total length of the central axis network is approximately 2400 pixels, corresponding to the back extension direction of each cow in the region.

[0044] S1.4. Divide the central axis of the connected region into segments according to the bifurcation nodes to obtain the central axis segment.

[0045] Specifically, a topology analysis is performed on the central axis network obtained by skeletonization, and pixels that connect three or more branches on the central axis are detected and identified as fork nodes. The central axis is then split into independent central axis segments using the fork nodes as breakpoints.

[0046] In this embodiment, 11 branching nodes were detected in the 2400-pixel central axis network through topology scanning.

[0047] The central axis network was divided into 18 independent central axis segments by using these 11 bifurcation nodes as cutting points.

[0048] S1.5 Calculate the ratio of the length to the width of each central axis segment and implement a filtering mechanism for the calculation results.

[0049] Calculate the length-to-width ratio of each central axis segment obtained in step S1.4, and use this ratio as a screening value to determine whether each central axis segment conforms to the body shape characteristics of the cattle's spine according to the screening mechanism.

[0050] The screening mechanism includes steps A1 to A2: A1. The midline segment that falls within the range of the cattle's body size proportion is retained as a candidate ridge segment.

[0051] The midline segment whose screening value falls within the preset range of cattle body size proportions is determined to be a valid line segment that conforms to the morphological characteristics of the cattle's torso and is marked as a candidate ridge line segment.

[0052] In this embodiment, based on prior statistics of the aspect ratio of the torso in the top view image of a cow, the preset ratio range is 2.0-4.5.

[0053] Of the 18 central axis segments, 9 segments had screening values ​​within this range. These 9 segments were of moderate length, had regular direction, and their shape matched the ridgeline on the back of the cattle, so they were retained as candidate ridgeline segments.

[0054] A2. Remove the midline segment whose calculation result is not within the range of cattle body size proportions.

[0055] S1.6. Based on the results of the screening mechanism, the ridge line features of cattle are obtained.

[0056] The steps for determining the range of cattle body size proportions for candidate ridge segments include B1 to B4: B1. Taking the skeleton extension direction of the candidate ridge segment as the major axis direction, sample the cross-sectional width of the connected region where the candidate ridge segment is located along the direction perpendicular to the major axis, and take the median of the cross-sectional width as the ridge segment width.

[0057] The skeleton extension direction of the candidate ridge segment is determined as the major axis. Several cross sections are uniformly set on the connected region where the candidate ridge segment is located along the direction perpendicular to the major axis. The lateral span of the foreground region at each cross section is measured one by one. The median of all cross section width values ​​is taken as the ridge segment width corresponding to the candidate ridge segment.

[0058] For example, cross-sectional sampling is performed on a candidate ridge segment. In this embodiment, the skeleton extension angle is 42°, and a cross-section is set every 10 pixels along the direction perpendicular to 42°, for a total of 22 cross-sections.

[0059] The foreground width values ​​measured at each cross-section are 58, 61, 63, 65, 62, 60, 64, 63, 61, 59, 57, 62, 64, 65, 63, 61, 60, 58, 56, 61, 63, and 62 pixels, respectively. Taking the median, the ridge segment width is 62 pixels.

[0060] B2. Using the distance between the endpoints of the candidate ridge segments as the ridge segment length, calculate the ratio of the ridge segment length to the ridge segment width to obtain the screening value.

[0061] Extract the coordinates of the two endpoints of the candidate ridge segment, calculate the Euclidean distance between the endpoints as the ridge segment length, divide this length by B1 to obtain the ridge segment width, and obtain the screening value used for body proportion determination.

[0062] Taking this embodiment as an example, the coordinates of the two endpoints of the candidate ridge segment are (214, 187) and (368, 293) respectively, and the Euclidean distance between the endpoints is... The final result is 187 pixels, which is used as the ridge segment length. The filter value is 187 ÷ 62 ≈ 3.02.

[0063] B3. When the screening value is within the preset ratio range, retain the corresponding candidate ridge segment and extract the ridge features of the cattle.

[0064] The selected value is compared with a preset ratio range. If the selected value is within the range, the aspect ratio of the candidate ridge segment is determined to be consistent with the body shape characteristics of the cattle trunk, and it is retained. The ridge feature of the cattle is then extracted.

[0065] Specifically, the screening value of the candidate ridge segment is 3.02, which is within the preset ratio range of 2.0-4.5, and it is deemed to have passed the test.

[0066] Subsequently, the ridge segment was preserved, and its skeleton extension angle of 42° and endpoint coordinates were output as ridge features.

[0067] B4. When the filter value is not within the preset ratio range, delete the corresponding candidate ridge segment.

[0068] In another embodiment, the screening value of another candidate ridge segment calculated by steps B1 and B2 is 1.4, which is lower than the lower limit of the preset ratio range of 2.0. It is determined that the shape is too short and thick and does not conform to the proportion characteristics of the cattle body.

[0069] S2. Using the ridgeline features of the cattle as morphological segmentation anchor points, apply ridgeline direction constraints to the high-density partitioned adhesion contours, and decompose the adhesion contours into a set of independent individual sub-contours.

[0070] In this embodiment, nine ridge features of cattle were extracted from the high-density partitions near the supplementary feeding trough, and the directional angle of each ridge segment was distributed between 15° and 162°.

[0071] After contour extraction, the adhered foreground region within the high-density partition appears as a large connected contour with an area of ​​approximately 18,600 square pixels. This contour actually includes multiple individual cattle, with complex boundary morphology and multiple depressions and jagged edges.

[0072] Using ridge features as segmentation anchor points, ridge direction constraints are applied to the adhered contour to gradually locate the boundary cutting positions between individuals, and finally the adhered contour is decomposed into a set of independent individual sub-contours.

[0073] The steps for applying ridge orientation constraints to the high-density partitioned adhesion profile include S2.1 to S2.4: S2.1 Using the direction angle of the ridge feature of the cattle as the reference direction, search for the contour curvature value along a scanning path perpendicular to the reference direction on the adhesion contour boundary.

[0074] The directional angle of the ridgeline features of each cow is extracted. Using this angle as the reference direction, a scanning path perpendicular to the reference direction is constructed. The adhesion contour boundary is traversed column by column along the scanning path, and the local morphological information of the contour boundary at each scanning position is recorded.

[0075] In this embodiment, a ridge feature with a 42° directional angle is selected as the current processing object. Using 42° as the reference direction, a scanning path perpendicular to the 42° direction is constructed, which is the 132° direction.

[0076] A total of 284 scanning columns were set up along the 132° direction within the coverage area of ​​the adhesion contour, with a step size of 1 pixel. Each column crossed the boundary of the adhesion contour, and the coordinate sequence of the intersection point between each scanning column and the contour boundary was recorded.

[0077] S2.2. The zero-crossing point where the contour curvature value changes from positive to negative is determined as the extreme point of contour concavity.

[0078] The steps for searching for extreme points of contour depressions on the adhesion contour boundary include C1~C3: C1. Scan the adhesion contour along the direction perpendicular to the reference, count the number of intersections between the scan column and the contour boundary, and mark the scan column with a number of intersections greater than the preset threshold X as the adhesion column.

[0079] Specifically, the adhesion contour is scanned column by column along a scanning path perpendicular to the reference direction, and the number of intersections between each scanning column and the contour boundary is counted.

[0080] For a single, complete individual outline, the scanning column only intersects the outline boundary at two points: one incident point and one exit point. However, at the location where two cows are stuck together, the outline boundary is concave due to the shape of the neck where the two cows are stuck together, and the scanning column will intersect the outline boundary at more than two points.

[0081] Scan columns with more than a preset threshold X are marked as sticky columns.

[0082] For example, the number of intersections was counted one by one along the 132° scanning direction for 284 scan columns. The results showed that the number of intersections for the scan columns was 2, but the number of intersections increased to 4 in the range of scan columns 91 to 118, indicating that there was obvious adhesion of the contours in this range.

[0083] With a preset threshold X=2, the 28 scan columns from the 91st to the 118th, which have more than 2 intersection points, are marked as sticky columns.

[0084] C2. Calculate the local curvature of the contour boundary points within the adhesion column range, and take the position where the local curvature changes from positive to negative as the candidate point for zero crossing.

[0085] For the contour boundary points within the marked adhesion column range, extract the local neighborhood centered on each boundary point, and fit the local curvature value using the coordinate sequence of the boundary points within the neighborhood. Positive values ​​indicate that the contour bulges outward, and negative values ​​indicate that the contour is concave inward.

[0086] Taking this embodiment as an example, the local curvature of the contour boundary points corresponding to the 91st to 118th adhesion columns is calculated, and the coordinate sequence of 15 points, 7 boundary points before and after each boundary point, is used for second-order fitting.

[0087] In the upper boundary sequence within the adhesion column range, the curvature value at the 97th scan column jumps from +0.031 to -0.018, and a zero-crossing candidate point P1 is detected; In the lower boundary sequence, the curvature value at the 103rd scan column jumps from +0.027 to -0.022, and a zero-crossing candidate point P2 is detected, resulting in a total of 2 zero-crossing candidate points.

[0088] C3. Merge adjacent zero-crossing candidate points according to the ridge line spacing constraint, and determine the merged zero-crossing candidate points as the extreme points of the contour concavity.

[0089] It is important to know that when there are multiple adjacent zero-crossing candidate points within the adhesion column, if the distance between them is less than the minimum preset value of the cattle's body width, these candidate points are determined to belong to the boundary noise of the same adhesion neck and are merged into a single representative point. When the spacing is greater than the constraint value, it is determined to be an independent candidate point at different adhesion positions and is retained separately. After the merging process is completed, the finally retained zero-crossing candidate points are determined as the extreme points of the contour concavity.

[0090] In this embodiment, the coordinates of P1 and P2 are (301, 224) and (318, 247) respectively, and the distance between the two points is [missing information]. The result is 28.6 pixels.

[0091] Based on prior statistics, the minimum preset value for the body width of cattle is set to 40 pixels. Since 28.6 pixels is less than 40 pixels, it is determined that P1 and P2 belong to the upper and lower side depressions of the same adhered neck. The two points are merged and the midpoint coordinates (310, 236) are taken. This merged point is determined as the extreme value point Q1 of the contour depression in this processing.

[0092] S2.3. Starting from the extreme point of the contour depression, extend the cutting line along the direction perpendicular to the reference direction to the opposite boundary of the contour.

[0093] Using the defined extreme point of the contour depression as the starting point for cutting, a straight cutting line is extended along the direction perpendicular to the reference direction, i.e., along the scanning path, towards the opposite side of the contour until the cutting line intersects with the opposite boundary of the adhered contour. The intersection point is taken as the end point of the cutting line, forming a complete cross-contour cutting line segment.

[0094] Taking this embodiment as an example, starting from the extreme point Q1 of the contour concavity at coordinates (310, 236), a cutting line is extended to the opposite side of the contour along a direction perpendicular to the 42° reference direction, i.e., a 132° direction.

[0095] The cutting line extends along the 132° direction, passes through the interior of the adhesive contour, and intersects the opposite boundary of the contour at coordinates (342,189), forming a cutting line segment from (310,236) to (342,189). The line segment is approximately 38 pixels long and spans the adhesive neck region.

[0096] S2.4. Split the adhered contours along the cutting line to obtain a set of independent individual sub-contours.

[0097] Perform geometric splitting on the adhesive contour along the obtained cutting line, break the contour boundary at both ends of the cutting line, and replace the connection boundary of the original adhesive neck with the cutting line segment, so that the original connected contour is split into two independent sub-contours that are closed by themselves.

[0098] Repeat steps S2.1-S2.3 for all adhered contours within the high-density partition, generating corresponding cutting lines for each adhesion location and performing splitting. Finally, gradually disassemble all adhered and connected contours within the high-density partition to obtain a set of independent individual sub-contours that correspond to the actual number of cattle individuals.

[0099] Specifically, the adhesive contours are split along the cutting line from (310,236) to (342,189). The original adhesive connected contours with an area of ​​approximately 18,600 square pixels are divided into two independent closed sub-contours with areas of approximately 10,200 square pixels and 8,100 square pixels, respectively. In terms of shape, each corresponds to the top view of a complete cow.

[0100] Repeat steps S2.1-S2.3 for the remaining adhesion locations within the high-density partition, performing a total of 8 cutting operations. Finally, the original adhesion area is decomposed into 9 independent individual sub-contours, which match the number of 9 ridge features extracted in step S1. The set of independent individual sub-contours is completed and output to step S3 for individual enumeration and counting.

[0101] S3. Perform direct contour counting on the low-density partition and individual enumeration on the set of independent individual sub-contours in the high-density partition. Summate the direct contour count and the individual enumeration to obtain the global cattle count value.

[0102] In this embodiment, the adhesion contours within the high-density zone have been broken down into 9 independent individual sub-contours. The low-density zone covers most of the grassland area, where individual cattle are sparsely distributed and do not adhere to each other. Each cattle contour is independent and closed.

[0103] Step S3 performs direct contour counting on the low-density partition and individual enumeration on the set of independent individual sub-contours in the high-density partition. The two counting results are summed to obtain the global cattle count value covering the entire map.

[0104] Extract each independent closed contour from the foreground region of the cow body within the low-density partition, and count the connected components whose area exceeds the preset minimum cow body size threshold to obtain the direct contour count result of the low-density partition.

[0105] For the set of independent individual sub-contours obtained within the high-density partition, the total number of sub-contours is counted to obtain the individual enumeration result of the high-density partition.

[0106] Add the two results together to get the global cattle count.

[0107] For example, connected component extraction was performed on the foreground region within the low-density partition. The minimum area threshold was set to 800 square pixels to filter out shadows and ground weed noise. A total of 31 independent closed contours with the area threshold were detected, and the direct count result of the low-density partition contours was 31.

[0108] The set of independent individual sub-contours obtained by S2 decomposition within the high-density partition contains a total of 9 sub-contours, and the individual enumeration result is 9. Summing the two results, i.e., 31 + 9 = 40, we get the global cattle count value of this frame of pasture image as 40.

[0109] S4. Perform a first-level correction between the global cattle count value and the historical point record, and output the final point result.

[0110] The steps for performing the first-level correction include S4.1 to S4.4: S4.1 Extract the counting sequence of consecutive times from the historical point count records, perform trend fitting on the counting sequence, and obtain the count prediction value of the current time.

[0111] In this embodiment, the historical count sequence of the most recent 30 consecutive time periods is extracted. The count value of each time period fluctuates between 37 and 42, showing an overall stable trend without monotonous increase or decrease.

[0112] A linear trend fit was performed on the 30-point sequence, and the slope of the resulting trend line was close to zero, indicating that the number of animals in stock was basically stable.

[0113] Extrapolating the fitted trend line to the current time, the predicted count value for the current time is 40.

[0114] S4.2. The difference between the global cattle count and the predicted count is taken as the deviation, and the historical fluctuation range of the count sequence is taken as the reference range.

[0115] The difference between the global cattle count and the predicted count is calculated. This difference is used as the deviation, reflecting the degree of deviation of the current count from the historical trend.

[0116] At the same time, the maximum deviation of the count value at each time point in the historical count sequence from the trend fitting value is used as the historical fluctuation range to form a reference range for judging whether the current deviation is reasonable.

[0117] In this embodiment, the global cattle count is 40, the predicted count is 40, and the deviation is 40 - 40 = 0.

[0118] For the historical count sequence of 30 time periods, calculate the residuals of each point relative to the fitted trend line. The maximum absolute value of the residual is 3, and the reference range for historical fluctuation amplitude is set to ±3. If the current deviation is 0, which is clearly within the reference range of ±3, then the result is output directly.

[0119] S4.3 Mark the global cattle count values ​​whose deviation exceeds the reference range as count values ​​to be reviewed, and perform a secondary judgment on the count values ​​to be reviewed.

[0120] In another alternative implementation, assuming that the global cattle count output at a certain time is 33 and the predicted count is still 40, then the deviation is 33-40=-7. The absolute value of 7 exceeds the historical fluctuation range reference range of ±3. This count value is marked as a count value to be reviewed, and then a secondary judgment process is performed.

[0121] The steps for performing a secondary judgment on the count value to be reviewed include D1~D2: D1. Perform high-density partitioning on the pasture image corresponding to the verification count value to obtain a refined density distribution.

[0122] Taking the scenario with a deviation of -7 as an example, the density partitioning of the pasture image corresponding to that time period is re-executed. The spatial grid size is reduced from the original 120×120 pixels to 80×80 pixels, the total number of grids is increased from 576 to 1296, and the partitioning condition of high density partitions is adjusted from the distribution mean to the distribution mean plus 0.5 times the standard deviation.

[0123] The refined density distribution shows that the high-density zone near the feeding trough has expanded compared to the initial delineation. New edge transition grids that were initially classified as low-density zones have been added, indicating that there were boundary omissions in the initial delineation, resulting in some adherent individuals not being included in the ridgeline segmentation process.

[0124] D2. Based on the refined density distribution, redetermine the high-density partition boundary, and perform ridge feature extraction and adhesion contour segmentation on the redetermined high-density partition again. Replace the count value to be reviewed with the count value obtained after review, and use it as the final point count result.

[0125] Based on the distribution of refined density, the spatial boundary of the high-density partition is redefined, and the foreground region within the new boundary range is included in the reprocessing process. The ridge feature extraction in step S1 and the adhesion contour segmentation operation in step S2 are performed again on the redefined high-density partition. The direct counting results of the low-density partition are combined and summarized to obtain the verified count value. The verified count value replaces the original count value to be verified and is used as the final point count result output for the current time.

[0126] Specifically, after redefining the high-density partition boundary based on the refined density distribution, the outlines of the three cows in the original edge transition area are included in the reprocessing scope.

[0127] Ridge feature extraction was performed again on the newly defined high-density partitions, and a total of 12 ridge features were extracted. The adhered contours were re-segmented to obtain 12 independent individual sub-contours.

[0128] Combining the direct count results of 28 from the low-density partition, the total count after verification is 28 + 12 = 40, which perfectly matches the predicted count of 40, with the deviation zero and within the reference range. The original count value to be verified, 33, is replaced with the verified count value of 40 as the final point count result for this time period.

[0129] S4.4. Determine the global cattle count value with deviation within the reference range as the final count result.

[0130] For example, if the global cattle count is 40 with a deviation of 0, which is within the historical fluctuation range of ±3, the count result is deemed reliable, and 40 is directly determined as the final count result for this period.

[0131] The result perfectly matches the actual number of 40 animals in the ranch, verifying the counting accuracy of the invention in complex aggregation scenarios. The final count result is output to the ranch management system for recording.

[0132] Example 3 is an embodiment of the present invention, which provides a cattle counting system for open-air pastures, comprising: The extraction module assesses the density of the spatial distribution of cattle in the pasture image, divides the pasture image into high-density and low-density regions according to the density assessment results, and extracts the ridgeline features of cattle for the high-density regions. The disassembly module is used to apply ridge direction constraints to the high-density partitioned adhesive contours, and disassemble the adhesive contours into a set of independent individual sub-contours. The counting module is used to directly count the contours of the low-density partition and enumerate the individual sub-contour sets of the independent individuals in the high-density partition to obtain the global cattle count value. The output module is used to perform a first-level correction between the global cattle count value and the historical point record, and output the final point result.

[0133] This embodiment also provides an electronic device applicable to a method for counting cattle in an open-air pasture, comprising: a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the method for counting cattle in an open-air pasture as proposed in the above embodiment.

[0134] This embodiment also provides a storage medium storing a computer program that, when executed by a processor, implements a method for counting cattle in an open-air pasture as described in the above embodiments.

[0135] The storage medium proposed in this embodiment and the method for counting cattle in an open-air pasture proposed in the above embodiment belong to the same inventive concept. Technical details not described in detail in this embodiment can be found in the above embodiments, and this embodiment has the same beneficial effects as the above embodiments.

[0136] Based on the above description of the implementation methods, those skilled in the art can clearly understand that the present invention can be implemented using software and necessary general-purpose hardware, and of course, it can also be implemented using hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk, or optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of the various embodiments of the present invention.

[0137] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.

Claims

1. A method for counting cattle in an open-air pasture, characterized in that, Includes the following steps: In response to the density assessment of the spatial distribution of cattle in pasture images, the pasture images are divided into high-density and low-density regions according to the density assessment results, and the ridge line features of cattle are extracted for the high-density regions. Using the ridge line features of the cattle as morphological segmentation anchor points, ridge line direction constraints are applied to the high-density partitioned adhesion contours, and the adhesion contours are decomposed into a set of independent individual sub-contours. The contours of the low-density partition are directly counted, and the individual sub-contour sets of the independent individuals in the high-density partition are enumerated. The contour counts and individual enumerations are summed to obtain the global cattle count. The global cattle count is compared with the historical count records using a first-level correction, and the final count result is output.

2. The method for counting cattle in an open-air pasture as described in claim 1, characterized in that, The steps for performing the density assessment include: The local pixel proportion of the pasture image is statistically analyzed according to the spatial grid to obtain the cow body coverage density value of each grid. The pasture image is divided into zones based on the cattle body cover density value. Grids with cattle body cover density values ​​exceeding the distribution mean are assigned to high-density zones, while the remaining grids are assigned to low-density zones.

3. The method for counting cattle in an open-air pasture as described in claim 2, characterized in that, The steps for extracting ridgeline features from high-density regions of cattle include: Skeletalization processing was performed on the foreground region of the cow body within the high-density partition to obtain the central axis of the connected region; The central axis of the connected region is divided into segments according to the bifurcation nodes to obtain the central axis segments; The ratio of the length to the width of each central axis segment is calculated, and a filtering mechanism is implemented for the calculation results; Based on the results of the screening mechanism, the ridge line features of cattle were obtained; The steps of the screening mechanism include: The midline segment whose calculation results fall within the range of cattle body size proportions is retained as a candidate ridge line segment; The midline segment whose calculation results are not within the range of cattle body size proportions will be removed.

4. The method for counting cattle in an open-air pasture as described in claim 3, characterized in that, The steps for determining the range of cattle body size proportions for candidate ridge segments include: Taking the skeleton extension direction of the candidate ridge segment as the major axis direction, the cross-sectional width of the connected region where the candidate ridge segment is located is sampled along the direction perpendicular to the major axis, and the median of the cross-sectional widths is taken as the ridge segment width. Using the distance between the endpoints of the candidate ridge segments as the ridge segment length, the ratio of the ridge segment length to the ridge segment width is calculated to obtain the screening value; When the screening value is within the preset ratio range, the corresponding candidate ridge segment is retained, and the ridge features of cattle are extracted. When the filter value is not within the preset ratio range, the corresponding candidate ridge segment is deleted.

5. The method for counting cattle in an open-air pasture as described in claim 4, characterized in that, The steps for applying ridge orientation constraints to the high-density partitioned adhesion profile include: Using the direction angle of the ridge feature of the cattle as the reference direction, the contour curvature value is searched along a scanning path perpendicular to the reference direction on the adhesion contour boundary. The zero-crossing point where the profile curvature value changes from positive to negative is determined as the extreme point of profile concavity; Starting from the extreme point of the concave contour, extend the cutting line along the direction perpendicular to the reference direction to the opposite boundary of the contour. The adhered contours are split along the cutting line to obtain a set of independent individual sub-contours.

6. The method for counting cattle in an open-air pasture as described in claim 5, characterized in that, The steps for searching for extreme points of concave depressions on the boundary of an adherent contour include: Scan the adhesion contour along the direction perpendicular to the reference, count the number of intersections between the scan column and the contour boundary, and mark the scan column with the number of intersections greater than the preset threshold X as the adhesion column; Calculate the local curvature of the contour boundary points within the adhesion column range, and take the position where the local curvature changes from positive to negative as the candidate point of zero crossing; Adjacent zero-crossing candidate points are merged according to the ridge line spacing constraint, and the merged zero-crossing candidate points are determined as the extreme points of the contour concavity.

7. The method for counting cattle in an open-air pasture as described in claim 6, characterized in that, The steps for performing the first-level correction include: Extract the count sequence of consecutive times from the historical point count records, perform trend fitting on the count sequence, and obtain the count prediction value for the current time. The difference between the global cattle count and the predicted count is used as the deviation, with the historical fluctuation range of the count sequence as the reference range. The global cattle count values ​​whose deviation exceeds the reference range are marked as count values ​​to be reviewed, and a secondary judgment is performed on the count values ​​to be reviewed; The global cattle count value with deviation within the reference range is determined as the final point count result; The steps for performing a secondary judgment on the count value to be reviewed include: High-density partitioning is performed on the pasture image corresponding to the verification count value to obtain a refined density distribution; Based on the refined density distribution, the high-density partition boundary is redefined, and ridge feature extraction and adhesion contour segmentation are performed again on the redefined high-density partition. The count value obtained after verification replaces the count value to be verified, and is used as the final point count result.

8. A cattle counting system for an open-air pasture, employing a cattle counting method for an open-air pasture as described in any one of claims 1 to 7, characterized in that, include: The extraction module assesses the density of the spatial distribution of cattle in the pasture image, divides the pasture image into high-density and low-density regions according to the density assessment results, and extracts the ridgeline features of cattle for the high-density regions. The disassembly module is used to apply ridge direction constraints to the high-density partitioned adhesive contours, and to disassemble the adhesive contours into a set of independent individual sub-contours. The counting module is used to directly count the contours of the low-density partition and enumerate the individual sub-contour sets of the independent individuals in the high-density partition to obtain the global cattle count value. The output module is used to perform a first-level correction between the global cattle count value and the historical point record, and output the final point result.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method for counting cattle in an open pasture as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the method for counting cattle in an open pasture as described in any one of claims 1 to 7.