Pig counting method, system and equipment for intelligent parcel land flower pig house
Through edge detection algorithm and feature analysis technology, initial score and optimization factors are constructed, and the target area in the pig house is screened out, which solves the problems of inefficient and low accuracy of traditional pig counting methods, and achieves efficient and accurate pig counting.
Patent Information
- Application Number
- CN202510315639.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-18
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2045-03-18
AI Technical Summary
Traditional pig counting methods are inefficient and error-prone, especially in complex pig house environments, where the low accuracy of candidate box generation results in reduced pig counting accuracy and efficiency.
The edge detection algorithm is used to obtain the closed area in the grayscale map of the pig house. By analyzing the contrast characteristics of the flower pig plaque and the texture characteristics of the closed area, the initial score and optimization factors are constructed, the target area is selected, the topological feature vector is constructed, and the pig count is realized.
It improves the accuracy of pig statistics, reduces the impact of interference such as complex lighting, enhances the accuracy and efficiency of pig counting, and avoids the impact of mutual occlusion between pigs on counting.
Smart Images

Figure CN119851316A_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: 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 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. (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 determine the optimization factor of each closed area by combining 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; (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.
[0005] Preferably, 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.
[0006] Preferably, 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.
[0007] Preferably, the method for determining the distribution characteristic of each closed area is: In each closed area, the difference in the number of feature areas between any two clusters is calculated, recorded as the distribution difference between any two clusters, and the mean of all the distribution differences is recorded as the distribution mean of each closed area; Calculate the difference in the number of all closed edge points between any two feature regions in each cluster, record it as the feature difference between any two feature regions, 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 region as the feature value of each closed region; The distribution characteristic 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 region Q; exp( ) represents the exponential function with a natural constant as the base.
[0008] Preferably, the expression of the optimization factor of each closed area 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 regions within the closed area Q.
[0009] Preferably, the optimization score of each closed area is obtained by multiplying the initial score of each closed area by the optimization factor.
[0010] Preferably, 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.
[0011] Preferably, 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.
[0012] In a second aspect, an embodiment of the present application provides a pig counting system for a smart plot pig house, the system comprising: 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.
[0013] In the third aspect, an embodiment of the present application also provides a pig counting device for a smart pig house on a plot of land, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein when the processor executes the computer program, the steps of any one of the above-mentioned methods for counting pigs in a smart pig house on a plot of land are implemented.
[0014] It can be seen from the above embodiments that the method for counting pigs in a smart pig house provided in the embodiments of the present application has at least the following beneficial effects: The present application adopts an edge detection algorithm to obtain the closed area in the grayscale image of the pig's bird's-eye view, and constructs an initial score by analyzing the contrast characteristics of the spotted pig's patches and the texture characteristics of the closed area, which can preliminarily improve the accuracy of pig counting; further, by analyzing the irregular boundary characteristics of the spotted pig's patches and the distribution characteristics of the patches on the surface of the spotted pig, an optimization factor is constructed, which can optimize the initial score and reduce the impact of interference such as complex lighting, thereby further improving the counting accuracy and efficiency of pigs; further, the optimization factor and the initial score are combined to construct an optimized score, which can further screen out the target area. When using the optimized score for target detection to generate a candidate frame, the impact of interference such as complex lighting on the candidate frame can be effectively reduced, and at the same time, the influence of the judgment of mutual occlusion between pigs on the pig count can be avoided, thereby improving the accuracy and efficiency of pig counting. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0016] Figure 1 A flowchart of a method for counting pigs in a smart pig house provided in one embodiment of the present application; Figure 2 A flowchart of the steps for obtaining a topological feature vector provided in one embodiment of the present application; Figure 3 A block diagram of a pig counting system for a smart pig house provided in accordance with an embodiment of the present application. DETAILED DESCRIPTION
[0017] In order to further explain the technical means and effects adopted by the present application to achieve the predetermined invention purpose, the following, in combination with the accompanying drawings and preferred embodiments, describes in detail the pig counting method, system and equipment for a smart plot flower pig house proposed in the present application, its specific implementation method, structure, features and effects. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.
[0018] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs.
[0019] The following is a detailed description of the specific scheme of the pig counting method, system and equipment for a smart pig house provided by the present application in conjunction with the accompanying drawings.
[0020] See also Figure 1 , which shows a flowchart of a method for counting pigs in a smart pig house provided by an embodiment of the present application, the method comprising the following steps: S1: Install a camera on the top of the pig house in the smart plot to collect a grayscale image of the pig house from above in real time.
[0021] A wide-angle camera is deployed on the top of the smart pig house to collect real-time images of the interior of the pig house and convert them into grayscale images, which are recorded as the grayscale images of the pig house from above. The time interval for image collection is set to T.
[0022] It should be noted that the value of the time interval T is manually set. In this embodiment, the value of the time interval T is 30s. The implementer can also set it by himself according to the specific situation. This embodiment does not impose any special restrictions.
[0023] S2: Analyze the local area features of the grayscale image of the pig house at each moment, and determine the topological feature vector of each target area at each moment.
[0024] The spotted pig has unique stripes and patches, which are usually composed of black and white contrasting colors. These unique black and white stripes not only provide the spotted pig with a significant appearance feature, but also form a high contrast with the background in the pig house environment, thereby facilitating image segmentation and target detection. Therefore, this embodiment analyzes the unique texture features of the spotted pig, identifies the area where the pigs are located from the grayscale image of the pig house from above, and counts the pigs. The specific process is as follows: (1) 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.
[0025] Firstly, the edge detection algorithm is used to obtain the edge pixels in the grayscale image of the pig house top view.
[0026] It should be understood that there are many 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 grayscale image of the pig house top view. In actual application, as other implementation methods, the implementer may also use other methods such as the Sobel edge detection algorithm. Regarding the selection of the edge detection algorithm, this embodiment does not impose any special restrictions.
[0027] Among them, the Canny edge detection algorithm is a well-known technology, and its specific principle process will not be repeated here.
[0028] Since the edge pixel points detected by the edge detection algorithm may be discrete, for each edge pixel point, in the grayscale image of the pig house 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; The method for calculating the gradient direction angle of a pixel point is a well-known technique, and the specific calculation process will not be described in detail.
[0029] If the continuity between an edge point and its neighboring points is greater than a preset threshold, the edge pixel point is connected to its neighboring points, and all edge pixel points are traversed until there is no edge pixel point with a continuity greater than the preset threshold between its neighboring points, that is, there are no adjacent edge pixel points that can be connected. The area enclosed by all edge lines in a closed loop state in the connection result is counted as a closed area.
[0030] It should be noted that the value of the preset threshold is artificially set. In this embodiment, the value of the preset threshold is 0.1. The implementer can also set it by himself according to the specific situation. This embodiment does not impose any special restrictions.
[0031] All edge pixel points on each closed area are recorded as closed edge points, and all edge pixel points outside all closed areas are recorded as discrete edge points.
[0032] (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.
[0033] Due to the complex environment of the pig house, there may be changes in lighting, mutual occlusion of pigs, dynamic interference and other phenomena. The detected closed area is not the actual spotted pig area. At this time, direct target detection will affect the accuracy and efficiency of target detection. Therefore, by analyzing the texture features of spotted pigs, the area where the pigs are located can be determined more accurately, specifically: The body surface of spotted pigs usually has stripes and patches. The stripes are composed of black and white contrasting colors, and the patch boundaries are irregular. They are usually distributed in the back, flank, head and other areas of the spotted pig. The stripes are composed of multiple patches and their boundaries. Since the stripes of spotted pigs are black and white contrasting colors, the gradient amplitude of the edge pixels of the patches in the grayscale image is larger, and the patches are relatively concentrated in the local area of the spotted pig.
[0034] Based on the above analysis, the initial score of each closed area is determined to improve the accuracy of pig counting, specifically: For any closed area u, if the closed area u is located inside other closed areas, the closed area u is recorded as a feature area. Further, the number of feature areas in each closed area, the number of edge pixels in the closed area, and the gradient amplitude of the edge pixels are counted. The texture information contained in the closed area can be characterized by the contained closed area and discrete edge pixels. At the same time, the contrast characteristics of the pattern are reflected by the gradient amplitude of the discrete edge pixels. Based on this, the initial score of the closed area is constructed, which is specifically: 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.
[0035] The calculation method of the gradient amplitude is a well-known technology, and its specific calculation process will not be repeated here.
[0036] 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.
[0037] (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.
[0038] 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: All characteristic regions in each closed area are clustered to obtain multiple clusters, wherein the centroid method is used to extract the centroids of all characteristic regions in each closed area, and the distances between the centroids of the characteristic regions are used as metric clustering in the clustering algorithm.
[0039] 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 feature areas to obtain multiple cluster clusters. In actual application, as other implementation methods, implementers can also use other clustering methods such as DPC density peak clustering algorithm. Regarding the selection of clustering methods, this embodiment does not make any special restrictions.
[0040] Among them, the k-means clustering algorithm is a well-known technology, and its specific principle is not repeated here.
[0041] In particular, closed areas that do not contain feature areas are not considered in the analysis.
[0042] In each closed area, the difference in the number of feature areas between any two clusters is calculated, recorded as the distribution difference between any two clusters, and the mean of all the distribution differences is recorded 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 and value of each cluster, and take the mean of the feature and values of all clusters in each closed area as the feature value of each closed area.
[0043] It should be noted that there are many methods for measuring the differences between data. In this embodiment, the absolute value method of the difference is used to calculate the difference in the number of all closed edge points between any two closed areas in each cluster. In actual application, implementers can also use other methods such as ratios to measure the differences between data. Regarding the selection of methods for measuring the differences between data, this embodiment does not impose any special restrictions.
[0044] It is additionally noted that, in this embodiment, whenever differences between data are measured, the method of taking the absolute value of the difference is adopted.
[0045] Furthermore, the distribution characteristic degree of each closed area is determined according to the distribution mean and characteristic value, specifically: The distribution characteristic 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 region Q; exp( ) represents the exponential function with a natural constant as the base.
[0046] According to the distribution characteristic degree of each closed area, it can be understood that if the distribution mean is smaller, it means that the difference in the number of characteristic regions between clusters is smaller, the distribution of characteristic regions is more uniform, the more consistent with the distribution law of spotted pig pattern, and the distribution characteristic degree is larger; and the smaller the eigenvalue is, the smaller the difference between characteristic regions is, the more likely it is spotted pig pattern, and the larger the distribution characteristic degree is; conversely, if the distribution mean is larger, it means that the difference in the number of characteristic regions between clusters is larger, the distribution of characteristic regions is more uneven, the less consistent with the distribution law of spotted pig pattern, and the smaller the distribution characteristic degree is; and the larger the eigenvalue is, the greater the difference between characteristic regions is, the less likely it is spotted pig pattern, and the smaller the distribution characteristic degree is.
[0047] Furthermore, by analyzing 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 areas in each closed area and the distribution characteristic degree, the optimization factor of each closed area is determined, specifically: Optimization factor of closed area 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 feature area in the closed area Q; Represents the number of all feature regions within the closed area Q.
[0048] The method for calculating the LBP value of a pixel is a well-known technique, and the specific calculation process will not be described in detail.
[0049] According to the optimization factors of each closed area, it can be understood 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 area is larger, the optimization factor is larger, which means that the closed area is more consistent with the distribution law and boundary characteristics of the spotted pig pattern, thereby further improving the accuracy and efficiency of pig counting; conversely, 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 area is smaller, the optimization factor is smaller, which means that the closed area is less consistent with the distribution law and boundary characteristics of the spotted pig pattern.
[0050] (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 for each target area.
[0051] The product of the initial score of each closed area and the optimization factor is taken as the optimization score of each closed area.
[0052] According to the above steps, the optimized scores of each closed area can be obtained. When the optimized scores are used to generate candidate frames for target detection, although the influence of interference candidate frames caused by interference such as complex lighting can be effectively reduced, there will still be a phenomenon that the spotted pigs in the pig house block each other, causing multiple spotted pigs to be misjudged as one spotted pig, which in turn interferes with the pig counting.
[0053] Therefore, the target area is preliminarily screened out according to the optimization score, and the topological feature vector of the target area is determined, specifically: 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.
[0054] It should be noted that there are many commonly used threshold segmentation algorithms. In this embodiment, the maximum inter-class variance algorithm is used to obtain the segmentation threshold, so as to divide the closed area. In actual application, as other implementation methods, the implementer may also adopt other threshold segmentation methods. Regarding the selection of threshold segmentation algorithm, this embodiment does not make any special restrictions.
[0055] Among them, the construction process of the adjacency matrix, the method of obtaining the average adjacency number and the maximum connected domain according to the adjacency matrix, and the maximum inter-class variance are well-known technologies, and their specific principles are not repeated here.
[0056] Preferably, the flowchart of the topological feature vector acquisition steps provided in this embodiment is as follows: Figure 2 shown.
[0057] 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.
[0058] In order to avoid the influence of occlusion between pigs on pig counting, the following operations are performed: 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.
[0059] It should be noted that, in this embodiment, the preset value is one fifth of the number of all feature regions in the target region corresponding to the current vector. The implementer may also set it according to the specific situation, and this embodiment does not impose any special limitation.
[0060] Among them, the watershed segmentation algorithm is a well-known technology, and its specific segmentation principle will not be described in detail.
[0061] 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 pig house, including: 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.
[0062] The present application embodiment provides a block diagram of a pig counting system for a smart plot pig house, such as Figure 3 shown.
[0063] Based on the same inventive concept as the above method, an embodiment of the present application also provides a pig counting device for a smart pig house on a plot of land, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein when the processor executes the computer program, the steps of any one of the above-mentioned methods for counting pigs in a smart pig house on a plot of land are implemented.
[0064] It should be noted that the above sequence of the embodiments of the present application is for description only and does not represent the advantages and disadvantages of the embodiments. The above is a description of a specific embodiment of this specification. In addition, the processes depicted in the accompanying 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.
[0065] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.
[0066] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present application should 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 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. (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 determine the optimization factor of each closed area by combining 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; (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 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.
4. The method for counting pigs in a smart pig house according to claim 1, characterized in that: The method for determining the distribution characteristic degree of each closed area is: In each closed area, the difference in the number of feature areas between any two clusters is calculated, recorded as the distribution difference between any two clusters, and the mean of all the distribution differences is recorded as the distribution mean of each closed area; Calculate the difference in the number of all closed edge points between any two feature regions in each cluster, record it as the feature difference between any two feature regions, 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 region as the feature value of each closed region; The distribution characteristic 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 region Q; exp( ) represents the exponential function with a natural constant as the base.
5. The method for counting pigs in a smart pig house as claimed in claim 4, characterized in that: The expression of the optimization factor of each closed area 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 regions within the closed area Q.
6. 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.
7. 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.
8. 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.
9. 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.
10. 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-8.
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
Inspection method, computer-readable recording medium, and reference standard plate
US20210209743A1
Polysemant meaning learning and search result display
WO2020024951A1