A method, system and device for counting pigs in an intelligent plot flower pigsty
By installing a camera on the top of the pig house in the smart parcel, collecting the topographic grayscale map in real time and building topological feature vectors, the problem of inefficiency of the pig counting method is solved, and high-precision and efficient pig counting is achieved.
Patent Information
- Application Number
- CN202510315639.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-18
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2045-03-18
AI Technical Summary
The existing pig counting methods are inefficient and prone to errors, especially in complex environments in pig houses, and the occlusion phenomenon between pigs affects the counting accuracy and efficiency.
A camera is installed on the top of the pig house in the smart parcel, and the grayscale maps are collected in real time. Topological feature vectors are constructed by analyzing local area features, target areas are selected, and occlusion effects are avoided through similarity analysis, thereby improving counting accuracy and efficiency.
It effectively reduces the impact of complex lighting and occlusion interference on pig counting, and improves the accuracy and efficiency of pig counting.
Smart Images

Figure CN119851316B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image recognition technology, and specifically to a method, system and equipment for counting pigs in a smart pig house. Background Art
[0002] In pig farms, the number of pigs is one of the most important concerns of managers. The traditional method is to count and count manually, which is not only inefficient but also prone to errors. The pig recognition technology in AI intelligent pig counting software mainly uses computer vision technology to process and analyze pig images to achieve accurate counting of the number of pigs. The emergence of this technology not only improves the management efficiency of the pig farming industry, but also provides better protection for the healthy growth of pigs. The pig counting recognition technology can automatically identify and count pig images in the pig house, thereby achieving accurate control of the number of pigs.
[0003] A common pig counting method is the target detection algorithm. In the target detection algorithm, it is usually necessary to generate candidate frames for pigs. The generation accuracy of the candidate frames will directly affect the detection accuracy of the pigs. When the candidate frames are generated, they will be disturbed by the complex environment of the pig house. At the same time, there will be mutual occlusion between pigs, resulting in low candidate frame generation accuracy, which in turn reduces the accuracy and efficiency of pig counting. Summary of the invention
[0004] In a first aspect, an embodiment of the present application provides a method for counting pigs in a smart plot pig house, the method comprising the following steps:
[0005] S1: Install a camera on the top of the smart plot pig house to collect the grayscale image of the pig house from above in real time;
[0006] S2: Analyze the local area features of the grayscale image of the pig house at each time, and determine the topological feature vector of each target area at each time. The specific process is as follows:
[0007] (1) Extract all edge pixels in the grayscale image of the pig house at each moment, analyze the distance between all edge pixels and the rate of change of the grayscale values of all edge pixels, obtain the closed area formed by the edge pixels, record all edge pixels on each closed area as closed edge points, and record all edge pixels outside all closed areas as discrete edge points;
[0008] (2) The closed areas inside the closed areas are recorded as feature areas. The number of all feature areas, the number of all discrete edge points, and the number of all closed edge points in each closed area are counted to determine the initial score of each closed area.
[0009] (3) Cluster all the feature regions within each closed region, analyze the differences in the number of all feature regions between each cluster and all the other clusters, as well as the differences in the total number of closed edge points between any two feature regions within each cluster, determine the distribution feature degrees of each closed region, and combine the brightness differences between each closed edge point within each closed region and all the closed edge points within its neighborhood, as well as the number of all feature regions within each closed region, to determine the optimization factors of each closed region;
[0010] (4) Based on the optimization factors and the initial scores, determine the optimized scores of each closed region, and screen out the target regions from all the closed regions to construct the topological feature vectors of each target region;
[0011] S3: Analyze the similarity of the topological feature vectors of any two target regions between the overhead grayscale images of the pigsty at different times, and count the pigs in the intelligent zoned flower pigsty.
[0012] Preferably, the obtaining of the closed regions composed of edge pixel points includes:
[0013] In the overhead grayscale images of the pigsty at each time, calculate the gradient direction angles of each edge pixel point, record the edge pixel point closest to each edge pixel point as the neighboring point of each edge pixel point, calculate the difference in the gradient direction angles between each edge pixel point and its neighboring point, and take the reciprocal of the product of the distance between each edge pixel point and its neighboring point and the difference as the continuity between each edge pixel point and its neighboring point;
[0014] If the continuity between an edge pixel point and its neighboring point is greater than a preset threshold, then connect the edge pixel point and its neighboring point, traverse all the edge pixel points until there is no edge pixel point whose continuity with its neighboring point is greater than the preset threshold, and count the regions enclosed by all the edge lines in the connected result that are in a closed-loop state as the closed regions.
[0015] Preferably, the expression for the initial score of each closed region is: ; represents the initial score of the closed region Q; represents the number of feature regions included in the closed region Q; represents the total number of discrete edge points in the closed region Q; represents the gradient amplitude of the closed edge point a in the closed edge Q; represents the total number of all closed edge points in the closed region Q.
[0016] Preferably, the method for determining the distribution feature degree of each closed region is:
[0017] In each closed region, calculate the difference in the number of feature regions between any two clustering clusters, denoted as the distribution difference between any two clustering clusters, and denote the mean of all the distribution differences as the distribution mean of each closed region;
[0018] Calculate the difference in the number of all closed edge points between any two feature regions within each clustering cluster, denoted as the feature difference between any two feature regions, calculate the sum of all the feature differences in each clustering cluster, denoted as the feature sum value of each clustering cluster, and take the mean of the feature sum values of all the clustering clusters within each closed region as the feature value of each closed region;
[0019] The distribution characteristic degree of the closed region Q The expression is: ; In the formula, represents the distribution mean of the closed region Q; represents the feature value of the closed region Q; exp( ) represents the exponential function with the natural constant as the base.
[0020] Preferably, the expression of the optimization factor of each closed region is: ; In the formula, represents the optimization factor of the closed region Q; represents the sum of the differences between the LBP values of all the closed edge points within the u-th feature region in the closed region Q; represents the number of all the feature regions within the closed region Q.
[0021] Preferably, the optimization score of each closed region is obtained by multiplying the initial score of each closed region by the optimization factor.
[0022] Preferably, screening out the target regions from all the closed regions to construct the topological feature vectors of each target region includes:
[0023] Take the optimization scores of all the closed regions in the top-down grayscale map of the pigsty at each moment as the input of the threshold segmentation algorithm, output the segmentation threshold, and take the closed regions greater than or equal to the segmentation threshold as the target regions;
[0024] Obtain the adjacency matrix of each target region, obtain the average adjacency number and the largest connected domain according to the adjacency matrix, and form the topological feature vectors of each target region with the number of all the feature regions, the average adjacency number and the largest connected domain in each target region.
[0025] Preferably, counting the pigs in the intelligent plot pigsty includes:
[0026] Respectively, denote the topological feature vectors of all target regions in the top-down grayscale image of the pigsty at the current moment and the topological feature vectors of all target regions in the top-down grayscale image of the pigsty at the previous moment of the current moment as the current vectors and historical vectors; calculate the similarity between each current vector and all historical vectors, and take the historical vector corresponding to the maximum similarity as the analog vector of each current vector;
[0027] Calculate the difference in the number of feature regions between the target region corresponding to each current vector and the target region corresponding to the analog vector, and perform iterative judgment based on the difference. Specifically:
[0028] (a) If the difference is greater than or equal to the preset value, there is no occlusion in the target region, and number the target region;
[0029] (b) If the difference is less than the preset value, there is occlusion in the target region, and divide the target region into multiple sub-closed regions;
[0030] Iterate the sub-closed regions according to (a) and (b) until there is no occlusion in the sub-closed regions, and count the number of all numbered regions as the number of pigs.
[0031] In a second aspect, an embodiment of the present application provides a pig counting system for an intelligent zoned flower pigsty, and the system includes:
[0032] A pig image acquisition module, which is used to install a camera on the top of the intelligent zoned flower pigsty to collect the top-down grayscale image of the pigsty in real time;
[0033] A pig weight acquisition module, which is used to analyze the local region features of the top-down grayscale image of the pigsty at each moment, and determine the topological feature vectors of each target region at each moment. The specific process is as follows:
[0034] Extract all edge pixel points in the top-down grayscale image of the pigsty at each moment, analyze the distances between all edge pixel points and the change rate of the gray values of all edge pixel points, obtain the closed regions composed of edge pixel points, denote all edge pixel points on each closed region as closed edge points, and denote all edge pixel points outside all closed regions as discrete edge points;
[0035] Denote the closed regions inside the closed regions as feature regions, respectively count the number of all feature regions, the number of all discrete edge points, and the number of all closed edge points in each closed region, and determine the initial score of each closed region;
[0036] Cluster all the feature regions within each closed region, analyze the differences in the number of all feature regions between each cluster and all the other clusters, as well as the differences in the total number of closed edge points between any two feature regions within each cluster, determine the distribution feature degrees of each closed region, and combine the brightness differences between each closed edge point within each closed region and all the closed edge points within its neighborhood, as well as the number of all feature regions within each closed region, to determine the optimization factors of each closed region;
[0037] Based on the optimization factors and the initial scores, determine the optimized scores of each closed region, and screen out the target regions from all the closed regions to construct the topological feature vectors of each target region;
[0038] The pig counting module is used to analyze the similarity of the topological feature vectors of any two target regions between the top-down grayscale images of the pigsty at different times, and count the pigs in the intelligent zoned flower pigsty.
[0039] In a third aspect, an embodiment of the present application further provides a pig counting device for an intelligent zoned flower pigsty, including a memory, a processor, and a computer program stored in the memory and running on the processor. When the processor executes the computer program, it implements the steps of the pig counting method for an intelligent zoned flower pigsty according to any one of the above.
[0040] As can be seen from the above embodiments, the pig counting method for an intelligent zoned flower pigsty provided by the embodiments of the present application has at least the following beneficial effects:
[0041] The present application uses an edge detection algorithm to obtain the closed regions in the top-down grayscale image of the pig, constructs an initial score by analyzing the contrast features of the flower pig patches and the texture features of the closed regions, which can initially improve the accuracy of pig statistics; further, by analyzing the boundary irregularity characteristics of the flower pig patches and the distribution characteristics of the patches on the surface of the flower pig, an optimization factor is constructed, which can optimize the initial score and reduce the influence brought by interference such as complex lighting, thereby further improving the counting accuracy and efficiency of pigs; further, by combining the optimization factor and the initial score, an optimized score is constructed, which can further screen out the target regions. When using the optimized score for target detection to generate candidate boxes, it can effectively reduce the influence of interference candidate boxes brought by interference such as complex lighting, and at the same time avoid the influence of the judgment of the mutual occlusion phenomenon between pigs on pig counting, and improve the accuracy and efficiency of pig counting. Description of the Drawings
[0042] To more clearly illustrate the technical solutions and advantages in the embodiments of the present application or the prior art, the following will briefly introduce the attached drawings required for the description of the embodiments or the prior art. Obviously, the attached drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other attached drawings can be obtained based on these drawings.
[0043] Figure 1 It is a flowchart of the steps of a method for counting pigs in an intelligent zoned flower pigsty provided by an embodiment of the present application;
[0044] Figure 2 It is a flowchart of the steps for obtaining a topological feature vector provided by an embodiment of the present application;
[0045] Figure 3 It is a block diagram of a system for counting pigs in an intelligent zoned flower pigsty provided by an embodiment of the present application. Detailed implementation manners
[0046] To further elaborate on the technical means and effects adopted by the present application to achieve the intended invention purpose, the following, in conjunction with the attached drawings and preferred embodiments, details the specific implementation manners, structures, features, and effects of a method, system, and device for counting pigs in an intelligent zoned flower pigsty proposed according to the present application. In the following description, different "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. In addition, the specific features, structures, or characteristics in one or more embodiments can be combined in any suitable form.
[0047] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the technical field to which the present application belongs.
[0048] The following specifically describes the specific solutions of a method, system, and device for counting pigs in an intelligent zoned flower pigsty provided by the present application with reference to the attached drawings.
[0049] Please refer to Figure 1 , which shows a flowchart of the steps of a method for counting pigs in an intelligent zoned flower pigsty provided by an embodiment of the present application. The method includes the following steps:
[0050] S1: Install a camera on the top of the intelligent zoned flower pigsty to collect the top-down grayscale image of the pigsty in real time.
[0051] Deploy a wide-angle camera on the top of the intelligent zoned flower pigsty to collect the internal image of the pigsty in real time and convert it into a grayscale image, denoted as the top-down grayscale image of the pigsty. Among them, the time interval for image acquisition is set to T.
[0052] It should be noted that the value of the time interval T is set artificially. In this embodiment, the value of the time interval T is 30 s. The implementer can also set it by combining specific situations, and this embodiment does not make special restrictions.
[0053] S2: Analyze the local region features of the top-down grayscale map of the pigsty at each moment, and determine the topological feature vectors of each target region at each moment.
[0054] The spotted pigs have unique stripes and patches on their bodies, which are usually composed of black and white contrast colors. These unique black and white stripes not only provide significant appearance features for the spotted pigs, but also make them form a high contrast with the background in the pigsty environment, thus facilitating image segmentation and target detection. Therefore, in this embodiment, by analyzing the unique texture features of the spotted pigs, the areas where the pigs are located are identified from the top-down grayscale map of the pigsty, and the pigs are counted. The specific process is as follows:
[0055] (1) Extract all edge pixel points in the top-down grayscale map of the pigsty at each moment, analyze the distances between all edge pixel points, and the change rate of the grayscale values of all edge pixel points, obtain the closed regions composed of edge pixel points, record all edge pixel points on each closed region as closed edge points, and record all edge pixel points outside all closed regions as discrete edge points.
[0056] First, an edge detection algorithm is used to obtain the edge pixel points in the top-down grayscale map of the pigsty.
[0057] It should be understood that there are various methods for edge detection, such as: Canny edge detection algorithm, Sobel edge detection algorithm, etc. In this embodiment, the Canny edge detection algorithm is used to obtain the edge pixel points in the top-down grayscale map of the pigsty. In the actual application process, as other implementation manners, the implementer can also use other methods such as the Sobel edge detection algorithm. Regarding the selection of the edge detection algorithm, this embodiment does not make special restrictions.
[0058] Among them, the Canny edge detection algorithm is a well-known technology, and its specific principle process will not be elaborated.
[0059] Since the edge pixel points detected by the edge detection algorithm may be discrete, for each edge pixel point, in the top-down grayscale map of the pigsty at each moment, calculate the gradient direction angle of each edge pixel point, record the edge pixel point closest to each edge pixel point as the neighboring point of each edge pixel point, calculate the difference in the gradient direction angle between each edge pixel point and its neighboring point, and take the reciprocal of the product of the distance between each edge pixel point and its neighboring point and the difference as the continuity between each edge pixel point and its neighboring point;
[0060] Among them, the calculation method of the gradient direction angle of the pixel point is a well-known technology, and its specific calculation process will not be elaborated.
[0061] If the continuity between an edge point and its neighboring points is greater than a preset threshold, then connect the edge pixel point with its neighboring points. Traverse all edge pixel points until there are no edge pixel points whose continuity with their neighboring points is greater than the preset threshold, that is, until there are no adjacent edge pixel points that can be connected. Count the areas enclosed by all the edge lines in a closed-loop state in the connection result as the enclosed areas.
[0062] It should be noted that the value of the preset threshold is set manually. In this embodiment, the value of the preset threshold is 0.1. Implementers can also set it according to specific situations by themselves, and this embodiment does not make special restrictions.
[0063] Denote all the edge pixel points on each enclosed area as enclosed edge points, and denote all the edge pixel points outside all the enclosed areas as discrete edge points.
[0064] (2) Denote the enclosed areas inside the enclosed areas as characteristic areas, and respectively count the number of all characteristic areas, the number of all discrete edge points, and the number of all enclosed edge points in each enclosed area to determine the initial score of each enclosed area.
[0065] Due to the complex environment of the pigsty, phenomena such as light changes, mutual occlusion of pigs, and dynamic interference may occur. The detected enclosed areas are not the actual areas of spotted pigs. At this time, directly performing target detection will affect the accuracy and efficiency of target detection. Therefore, by analyzing the texture features of spotted pigs, the areas where the pigs are located are more accurately determined. Specifically:
[0066] Spotted pigs usually have stripes and patches on their body surfaces. The stripes are composed of black and white contrast colors. The boundaries of the patches are irregular and are usually distributed in areas such as the back, side abdomen, and head of the spotted pigs. The stripes are composed of multiple patches and their boundaries. Since the stripes of spotted pigs are black and white contrast colors, the gradient amplitude of the edge pixel points of the patches in the grayscale image is larger, and the patches are relatively concentrated in the local areas of the spotted pigs.
[0067] Based on the above analysis, determine the initial scores of each enclosed area to improve the accuracy of pig counting. Specifically:
[0068] For any enclosed area u, if the enclosed area u is located inside other enclosed areas, then denote the enclosed area u as a characteristic area. Further, count the number of characteristic areas in each enclosed area, as well as the number of edge pixel points and the gradient amplitude of the edge pixel points in the enclosed area. The texture information contained in the enclosed area can be characterized by the included enclosed areas and discrete edge pixels, and at the same time, the contrast feature of the stripes is reflected by the gradient amplitude of the discrete edge pixel points. Based on this, construct the initial score of the enclosed area, specifically:
[0069] The expression of the initial score of each closed area is: ; represents the initial score of the closed area Q; Indicates the number of feature regions contained in the closed area Q; Represents the total number of discrete edge points in the closed area Q; represents the gradient amplitude of the closed edge point a in the closed edge Q; Represents the total number of all closed edge points in the closed area Q.
[0070] The calculation method of the gradient amplitude is a well-known technology, and its specific calculation process will not be repeated here.
[0071] According to the initial scores of each closed area, it can be understood that if the closed area Q contains more feature areas, it means that the target features contained in the area are richer, and the more likely it is that it is a spotted pig area; and the more discrete edge points in the closed area Q, the richer the texture features corresponding to the area are, and the more likely it is that it is a spotted pig area, and the larger the initial score should be; at the same time, the larger the gradient amplitude is, the closed area usually has a more obvious boundary, and the larger the initial score is, the more likely it is that it is a spotted pig area; conversely, if the closed area Q contains fewer feature areas, it means that the area contains fewer target features, and the less likely it is that it is a spotted pig area; and the fewer discrete edge points in the closed area Q, the simpler the texture features corresponding to the area are, and the less likely it is that it is a spotted pig area, and the smaller the initial score should be; at the same time, the smaller the gradient amplitude is, the less obvious the boundary of the closed area is, and the smaller the initial score is, and the less likely it is that it is a spotted pig area.
[0072] (3) Cluster all feature regions in each closed area, analyze the difference in the number of all feature regions between each cluster and all other clusters, and the difference in the total number of closed edge points between any two feature regions in each cluster, determine the distribution characteristic degree of each closed area, and combine the brightness difference between each closed edge point in each closed area and all closed edge points in its neighborhood, as well as the number of all feature regions in each closed area, to determine the optimization factor of each closed area.
[0073] The initial score is constructed by the texture information contained in the closed area. However, in the plot flower pig house scene, when there is complex lighting interference, the texture information in the closed area is also relatively rich. When the initial score is directly used to generate the candidate frame, the generated candidate frame has low accuracy. Therefore, in this embodiment, the shape characteristics and distribution characteristics of the feature area contained in the closed area are used to construct the optimization factor, and then the initial score is optimized. The specific process is as follows:
[0074] Cluster all the feature regions within each enclosed area to obtain multiple clusters. Among them, the centroid method is used to extract the centroid of all the feature regions within each enclosed area, and the distance between the centroids of the feature regions is used as the metric for clustering in the clustering algorithm.
[0075] It should be noted that there are many commonly used clustering algorithms. In this embodiment, the k-means clustering algorithm is used to cluster all the feature regions to obtain multiple clusters. In the actual application process, as other implementation manners, the implementer can also use other clustering methods such as the DPC density peak clustering algorithm. Regarding the selection of the clustering method, this embodiment does not make special restrictions.
[0076] Among them, the k-means clustering algorithm is a well-known technology, and its specific principle will not be elaborated here.
[0077] In particular, for the enclosed areas that do not contain feature regions, no analysis and consideration are made.
[0078] In each enclosed area, calculate the difference in the number of feature regions between any two clusters, which is denoted as the distribution difference between any two clusters, and denote the mean value of all the distribution differences as the distribution mean value of each enclosed area;
[0079] Calculate the difference in the number of all enclosed edge points between any two feature regions in each cluster, which is denoted as the feature difference between any two feature regions, calculate the sum of all the feature differences in each cluster, which is denoted as the feature sum value of each cluster, and use the mean value of the feature sum values of all the clusters within each enclosed area as the feature value of each enclosed area.
[0080] It should be noted that there are many methods for measuring the difference between data. In this embodiment, the method of taking the absolute value of the difference is used to calculate the difference in the number of all enclosed edge points between any two enclosed areas in each cluster. In the actual application process, the implementer can also use other methods for measuring the difference between data such as the ratio. Regarding the selection of the method for measuring the difference between data, this embodiment does not make special restrictions.
[0081] It is further explained that in this embodiment, whenever it comes to measuring the difference between data, the method of taking the absolute value of the difference is used.
[0082] Furthermore, according to the distribution mean value and the feature value, determine the distribution feature degree of each enclosed area, specifically:
[0083] The distribution feature degree of the enclosed area Q The expression is: ; In the formula, represents the distribution mean value of the enclosed area Q; represents the feature value of the enclosed area Q; exp( ) represents the exponential function with the natural constant as the base.
[0084] It can be understood from the distribution characteristic degree of each closed region that if the distribution mean value is smaller, it indicates that the difference in the number of characteristic regions between clustering clusters is smaller, the distribution of characteristic regions is more uniform, and it is more in line with the distribution law of spotted pig markings, and the distribution characteristic degree is larger; and the smaller the characteristic value, it indicates that the difference between characteristic regions is smaller, and it is more likely to be spotted pig markings, and the distribution characteristic degree is larger; on the contrary, if the distribution mean value is larger, it indicates that the difference in the number of characteristic regions between clustering clusters is larger, the distribution of characteristic regions is more uneven, and it is less in line with the distribution law of spotted pig markings, and the distribution characteristic degree is smaller; and the larger the characteristic value, it indicates that the difference between characteristic regions is larger, and it is less likely to be spotted pig markings, and the distribution characteristic degree is smaller.
[0085] Furthermore, by analyzing the brightness difference between each closed edge point in each closed region and all closed edge points in its neighborhood, as well as the number of all characteristic regions and the distribution characteristic degree in each closed region, the optimization factor of each closed region is determined, specifically:
[0086] The optimization factor of closed region Q The expression is: ; In the formula, represents the cumulative sum of the differences between the LBP values of all closed edge points in the u-th characteristic region in closed region Q; represents the number of all characteristic regions in closed region Q.
[0087] Among them, the calculation method of the LBP value of pixel points is a well-known technology, and its specific calculation process will not be elaborated here.
[0088] It can be understood from the optimization factors of each closed region that if the distribution characteristic degree is larger and the cumulative sum of the differences between the LBP values of all closed edge points in the characteristic region is larger, then the optimization factor is larger, indicating that the closed region is more in line with the distribution law and boundary characteristics of spotted pig markings, thereby further improving the accuracy and efficiency of pig counting; on the contrary, if the distribution characteristic degree is smaller and the cumulative sum of the differences between the LBP values of all closed edge points in the characteristic region is smaller, then the optimization factor is smaller, indicating that the closed region is less in line with the distribution law and boundary characteristics of spotted pig markings.
[0089] (4) Based on the optimization factor and the initial score, determine the optimized score of each closed region, and screen out the target regions from all closed regions to construct the topological feature vectors of each target region.
[0090] Multiply the initial score of each closed region by the optimization factor as the optimized score of each closed region.
[0091] According to the above steps, the optimized scores of each closed region can be obtained. When using the optimized scores to generate candidate bounding boxes for object detection, although the influence of interfering candidate bounding boxes caused by interference such as complex lighting can be effectively reduced, there will still be a phenomenon that the spotted pigs in the pigsty block each other, resulting in multiple spotted pigs being misjudged as one spotted pig, which will further interfere with the pig counting.
[0092] Therefore, the target regions are preliminarily screened according to the optimized scores, and the topological feature vectors of the target regions are determined, specifically as follows:
[0093] Take the optimized scores of all closed regions in the top-down grayscale image of the pigsty at each moment as the input of the threshold segmentation algorithm, output the segmentation threshold, and regard the closed regions greater than or equal to the segmentation threshold as the target regions;
[0094] Obtain the adjacency matrix of each target region, obtain the average adjacency number and the largest connected domain according to the adjacency matrix, and form the topological feature vector of each target region with the number of all feature regions in each target region, the average adjacency number and the largest connected domain.
[0095] It should be noted that there are many commonly used threshold segmentation algorithms. In this embodiment, the Otsu algorithm is used to obtain the segmentation threshold, so as to divide the closed regions. In the actual application process, as other implementation manners, the implementer can also adopt other threshold segmentation methods. Regarding the selection of the threshold segmentation algorithm, this embodiment does not make special restrictions.
[0096] Among them, the construction process of the adjacency matrix, the method of obtaining the average adjacency number and the largest connected domain according to the adjacency matrix, and the Otsu method are well-known technologies, and their specific principles will not be elaborated here.
[0097] Preferably, the flow chart of the steps for obtaining the topological feature vector provided in this embodiment is as Figure 2 shown.
[0098] S3: Analyze the similarity of the topological feature vectors of any two target regions between the top-down grayscale images of the pigsty at different moments, and count the pigs in the intelligent plot pigsty.
[0099] In order to avoid the influence of pig occlusion on pig counting, the following operations are now carried out, specifically as follows:
[0100] Respectively denote the topological feature vectors of all target regions in the top-down grayscale image of the pigsty at the current moment and the topological feature vectors of all target regions in the top-down grayscale image of the pigsty at the previous moment of the current moment as the current vectors and the historical vectors; calculate the similarity between each current vector and all historical vectors, and regard the historical vector corresponding to the maximum similarity as the analog vector of each current vector;
[0101] Calculate the difference in the number of feature regions between the target region corresponding to each current vector and the target region corresponding to the analog vector, and perform judgment and iteration based on the difference. Specifically:
[0102] (a) If the difference is greater than or equal to the preset value, there is no occlusion in the target region, and number the target region;
[0103] (b) If the difference is less than the preset value, there is occlusion in the target region, and divide the target region into multiple sub-closed regions;
[0104] Iterate over the sub-closed regions according to (a) and (b) until there is no occlusion in the sub-closed regions, and count the number of all numbered regions as the number of pigs.
[0105] It should be noted that in this embodiment, the preset value is taken as one-fifth of the number of all feature regions in the target region corresponding to the current vector. The implementer can also set it according to the specific situation, and this embodiment does not make special restrictions.
[0106] Among them, the watershed segmentation algorithm is a well-known technology, and its specific segmentation principle will not be elaborated here.
[0107] Based on the same inventive concept as the above method, the embodiment of the present application also provides a pig counting system for a smart plot flower pigsty, including:
[0108] A pig image acquisition module, used to install a camera on the top of the smart plot flower pigsty to collect the top-down grayscale image of the pigsty in real time;
[0109] A pig weight acquisition module, used to analyze the local region features of the top-down grayscale image of the pigsty at each moment, and determine the topological feature vector of each target region at each moment. The specific process is as follows:
[0110] Extract all edge pixel points in the top-down grayscale image of the pigsty at each moment, analyze the distances between all edge pixel points and the change rate of the grayscale values of all edge pixel points, obtain the closed regions composed of edge pixel points, record all edge pixel points on each closed region as closed edge points, and record all edge pixel points outside all closed regions as discrete edge points;
[0111] Record the closed regions inside the closed regions as feature regions, respectively count the number of all feature regions, the number of all discrete edge points, and the number of all closed edge points in each closed region, and determine the initial score of each closed region;
[0112] Cluster all the feature regions within each enclosed area, analyze the differences in the number of feature regions between each cluster and all the other clusters, as well as the differences in the total number of enclosed edge points between any two feature regions within each cluster, determine the distribution feature degrees of each enclosed area, and combine the brightness differences between each enclosed edge point within each enclosed area and all the enclosed edge points within its neighborhood, as well as the number of all the feature regions within each enclosed area, to determine the optimization factors for each enclosed area;
[0113] Based on the optimization factors and the initial scores, determine the optimized scores for each enclosed area, and screen out the target areas from all the enclosed areas to construct the topological feature vectors of each target area;
[0114] The pig counting module is used to analyze the similarity of the topological feature vectors of any two target areas between the top-down grayscale images of the pigsty at different times, and count the pigs in the intelligent zoned flower pigsty.
[0115] The block diagram of a pig counting system for an intelligent zoned flower pigsty provided by an embodiment of the present application is as Figure 3 shown.
[0116] Based on the same inventive concept as the above method, an embodiment of the present application also provides a pig counting device for an intelligent zoned flower pigsty, including a memory, a processor, and a computer program stored in the memory and running on the processor. When the processor executes the computer program, it implements the steps of any one of the above methods for the pig counting method of an intelligent zoned flower pigsty.
[0117] It should be noted that: the above sequence of the embodiments of the present application is only for description and does not represent the superiority or inferiority of the embodiments. And the above specifically describes a specific embodiment of this specification. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0118] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between each embodiment can be referred to each other. Each embodiment focuses on the differences from other embodiments.
[0119] The above are only the preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method for counting pigs in a smart plot pig house, characterized in that: The method comprises the following steps: S1: Install a camera on the top of the smart plot pig house to collect the grayscale image of the pig house from above in real time; S2: Analyze the local area features of the grayscale image of the pig house at each time, and determine the topological feature vector of each target area at each time. The specific process is as follows: (1) Extract all edge pixels in the grayscale image of the pig house at each moment, analyze the distance between all edge pixels and the rate of change of the grayscale values of all edge pixels, obtain the closed area formed by the edge pixels, record all edge pixels on each closed area as closed edge points, and record all edge pixels outside all closed areas as discrete edge points; (2) The closed area inside the closed area is recorded as the feature area, and the initial score of each closed area is determined. The expression is: ; represents the initial score of the closed area Q; Indicates the number of feature regions contained in the closed area Q; Represents the total number of discrete edge points in the closed area Q; represents the gradient amplitude of the closed edge point a in the closed edge Q; Represents the total number of all closed edge points in the closed area Q; (3) In each closed area, calculate the difference in the number of feature areas between any two clusters, record it as the distribution difference between any two clusters, and record the mean of all the distribution differences as the distribution mean of each closed area; calculate the difference in the number of all closed edge points between any two feature areas in each cluster, record it as the feature difference between any two feature areas, calculate the cumulative sum of all the feature differences in each cluster, record it as the feature sum value of each cluster, and take the mean of the feature sum values of all clusters in each closed area as the feature value of each closed area; calculate the distribution feature degree of the closed area Q , the expression is: ; In the formula, represents the distribution mean of the closed area Q; represents the eigenvalue of the closed area Q; exp( ) represents an exponential function with a natural constant as the base; the optimization factor of each closed area is calculated, and the expression is: ; In the formula, represents the optimization factor of the closed area Q; Represents the cumulative sum of the differences between the LBP values of all closed edge points in the u-th feature area in the closed area Q; Represents the number of all feature areas in the closed area Q; (4) Based on the optimization factor and the initial score, the optimization score of each closed area is determined, and the target area is screened out from all closed areas to construct a topological feature vector of each target area; S3: Analyze the similarity of the topological feature vectors of any two target areas between the grayscale images of the pig house at different times, and count the number of pigs in the smart plot pig house.
2. The method for counting pigs in a smart pig house according to claim 1, characterized in that: The step of obtaining a closed area formed by edge pixels includes: In the grayscale image of the pig house viewed from above at each moment, the gradient direction angle of each edge pixel point is calculated, the edge pixel point closest to each edge pixel point is recorded as the neighboring point of each edge pixel point, the difference in the gradient direction angle between each edge pixel point and its neighboring point is calculated, and the reciprocal of the product of the distance between each edge pixel point and its neighboring point and the difference is taken as the continuity between each edge pixel point and its neighboring point; If the continuity between an edge pixel point and its neighboring points is greater than a preset threshold, the edge pixel point is connected to its neighboring points, and all edge pixels are traversed until there is no edge pixel point with a continuity between its neighboring points greater than the preset threshold. The area enclosed by all edge lines in a closed loop state in the connection result is counted as a closed area.
3. The method for counting pigs in a smart pig house according to claim 1, characterized in that: The optimization score of each closed area is obtained by multiplying the initial score of each closed area by the optimization factor.
4. The method for counting pigs in a smart pig house according to claim 1, characterized in that: The step of selecting target areas from all closed areas to construct topological feature vectors of each target area includes: The optimized scores of all closed areas in the grayscale image of the pig house at each moment are used as the input of the threshold segmentation algorithm, and the segmentation threshold is output. The closed areas greater than or equal to the segmentation threshold are used as the target areas. The adjacency matrix of each target area is obtained, and the average adjacency number and the maximum connected domain are obtained according to the adjacency matrix. The number of all feature areas in each target area, the average adjacency number and the maximum connected domain are combined to form a topological feature vector of each target area.
5. The method for counting pigs in a smart pig house according to claim 1, characterized in that: The counting of the pigs in the smart plot pig house includes: The topological feature vectors of all target areas in the grayscale image of the pig house at the current moment and the topological feature vectors of all target areas in the grayscale image of the pig house at the moment before the current moment are recorded as the current vector and the historical vector; the similarity between each current vector and all historical vectors is calculated, and the historical vector corresponding to the maximum similarity is used as the analogy vector of each current vector; Calculate the difference in the number of feature areas between the target area corresponding to each current vector and the target area corresponding to the analog vector, and perform judgment iteration based on the difference, specifically: (a) If the difference is greater than or equal to the preset value, there is no occlusion in the target area, and the target area is numbered; (b) If the difference is less than a preset value, the target area is blocked and the target area is divided into multiple sub-enclosed areas; Iterate the sub-enclosed area according to (a) and (b) until there is no occlusion in the sub-enclosed area, and count the number of all numbers as the number of pigs.
6. A pig counting system for a smart plot pig house, implementing a pig counting method for a smart plot pig house as claimed in claim 1, characterized in that: The system comprises: The pig image acquisition module is used to install a camera on the top of the smart plot pig house to collect the grayscale image of the pig house from above in real time; The pig weight acquisition module is used to analyze the local area characteristics of the grayscale image of the pig house at each moment and determine the topological feature vector of each target area at each moment. The specific process is as follows: Extract all edge pixels in the grayscale image of the pig house at each moment, analyze the distances between all edge pixels and the rate of change of the grayscale values of all edge pixels, obtain the closed area formed by the edge pixels, record all edge pixels on each closed area as closed edge points, and record all edge pixels outside all closed areas as discrete edge points; The closed areas inside the closed areas are recorded as feature areas, and the number of all feature areas, the number of all discrete edge points and the number of all closed edge points in each closed area are counted to determine the initial score of each closed area; Cluster all feature regions in each closed area, analyze the difference in the number of all feature regions between each cluster and all other clusters, and the difference in the total number of closed edge points between any two feature regions in each cluster, determine the distribution characteristic degree of each closed area, and combine the brightness difference between each closed edge point in each closed area and all closed edge points in its neighborhood, as well as the number of all feature regions in each closed area, to determine the optimization factor of each closed area; Based on the optimization factor and the initial score, the optimization score of each closed area is determined, and the target area is screened out from all the closed areas to construct the topological feature vector of each target area; The pig counting module is used to analyze the similarity of the topological feature vectors of any two target areas between the grayscale images of the pig house at different times, and count the pigs in the smart plot pig house.
7. A pig counting device for a smart plot pig house, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the steps of a method for counting pigs in a smart pig house on a plot of land are implemented as described in any one of claims 1-5.
Citation Information
Patent Citations
Living pig counting and multi-target tracking method based on convolutional neural network
CN116051488A
Calligraphy character recognition method based on twinborn convolutional neural network
CN116486419A