A group pig identification method based on feature fusion
Through improved feature extraction and fusion methods, combined with an improved hybrid breeding algorithm and PCA dimensionality reduction, high-precision group pig identity recognition is achieved, which solves the problem of insufficient recognition accuracy in existing methods and improves the accuracy of individual pig identity recognition and the generalization ability of the classifier.
Patent Information
- Application Number
- CN202210040796.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-14
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2042-01-14
AI Technical Summary
The existing pig individual recognition methods based on HOG features, SIFT features, LBP features and color histogram features have low accuracy and cannot meet the needs of group pig identity recognition.
Feature extraction was performed using SIFT features based on multi-directional description of sparse points, multi-block improved centrally symmetric local octet pattern features, and connected domain statistical features based on spatial distribution information. Feature fusion and classifier training were performed using an improved hybrid breeding algorithm, and individual pig identity was identified by combining PCA dimensionality reduction and weighted voting method.
The accuracy of pig individual feature acquisition and recognition is improved, the generalization performance of the classifier is enhanced, and the problem of insufficient recognition accuracy in traditional methods is solved.
Smart Images

Figure CN114519864B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer vision technology, and relates to image processing, feature fusion and classification recognition, and in particular to a group pig identification method based on feature fusion. Background Art
[0002] In recent years, with the improvement of the national economy and people's living standards, the scale and number of pig farming in China have continued to expand. The informatization of pig farming is a key model for future pig breeding supervision. Group pig identification plays a vital role in pig breeding management and individual behavior analysis. Compared to methods that identify individual pigs through ear tags and paint markings, biometric-based identification methods are stable and non-invasive. Therefore, surface texture and color features of pigs are often used to identify individual pigs, such as HOG features, SIFT features, LBP features, and color histogram features. However, the description accuracy of these features is not very high. Therefore, the present invention discloses a group pig identity recognition method based on feature fusion. First, the three features of SIFT, LBP and color histogram are improved to obtain SIFT features for multi-directional description of sparse points, centrally symmetric local octet pattern features improved by multi-blocking, and connected domain statistical features based on spatial distribution information, thereby improving the accuracy of obtaining individual pig features. Then, the three features extracted from individual pig images are serially weighted fused, and PCA is used for dimensionality reduction. Finally, a weighted ensemble classifier based on an improved hybrid breeding algorithm is used to classify and train the individual pig images. Summary of the Invention
[0003] The purpose of the present invention is to use machine vision technology to perform individual pig identification on collected bird's-eye view videos of group-raised pigs.
[0004] The technical solution adopted by the present invention is a group pig identification method based on feature fusion, which includes the following steps:
[0005] Step 1: The overhead video of group-raised pigs was framed and key frames were selected using the nearest neighbor pixel comparison method in key areas. After image enhancement, the pigs were segmented using a watershed algorithm based on threshold optimization, resulting in seven individual pig images. The threshold optimization was performed using the improved Fruit Fly Optimization Algorithm based on Adaptive Optimization and Improved Evaluation Strategy (AOIES-FOA).
[0006] Step 2: For each of the seven pig images, the sparse point multi-direction description scale-invariant feature transform (SMD-SIFT) algorithm was used to extract the local features of the pigs. The multi-block improved central symmetry local octet pattern algorithm (MB-ICSLOP) was used to extract the texture features of the pigs. The connected domain statistics algorithm based on spatial distribution information was used to extract the color region block features of the pigs.
[0007] Step 3: After normalizing the three extracted features, each feature is assigned a weight and optimized using the Improved Hybrid Breeding Algorithm (IHBA). The weighted features are then serially fused and finally PCA is used for dimensionality reduction.
[0008] In step 4, a weighted ensemble classifier based on the improved crossbreeding algorithm was trained to classify individual pig images. First, the dataset was sampled with replacement to generate three different training subsets. The three classifiers with the greatest differences were then trained in parallel using the Kappa value. The improved crossbreeding algorithm was then used to optimize the classifier weights to obtain the optimal weight combination. Finally, weighted voting was used to identify individual pigs.
[0009] Furthermore, the step 1 specifically includes:
[0010] First, a bird's-eye view video of seven pigs was collected and framed, and key frames were selected using the key area nearest neighbor pixel comparison method. The specific steps of the key area nearest neighbor pixel comparison method are as follows: After the group pig video is framed, two adjacent frames are extracted according to the frame order. This patent mainly focuses on the identification of pigs in drinking water areas. The same drinking water area is selected in the two frames, and the pixel difference corresponding to the three RGB components of the area is calculated. If the pixel difference sum is less than the set threshold, the two frames are highly similar and the latter frame is discarded. Otherwise, the latter frame is saved, that is, the image with low similarity is used as the key frame.
[0011] Then, local histogram equalization is used to improve the image contrast, and median filtering is used to remove the introduced noise. The effective area of the enhanced image is first extracted, and the watershed algorithm based on threshold optimization is used for segmentation. After morphological processing, the area of each connected region is calculated. Finally, the connected regions with an area smaller than the threshold are discarded to obtain the segmentation map of the individual pig.
[0012] Among them, the specific steps of the watershed algorithm based on threshold optimization include: first, using the improved fruit fly optimization algorithm to search for the optimal threshold, perform threshold segmentation, and obtain a binary image; then, obtain the background and foreground areas through morphological operations and distance transformation; mark the part where the background and foreground areas intersect; finally, use the watershed algorithm to further segment the image to obtain the final segmentation result.
[0013] As for the improvement of the fruit fly optimization algorithm, the first improvement is to change the fixed step size of the original algorithm to an adaptive adjustment of the search step size according to the number of iterations, as shown in formula (1). This enables the algorithm to have a larger search distance for global search in the early stage of optimization, avoiding falling into local optimality too early. In the later stage of optimization, the search distance decreases with the increase of the number of iterations, thereby improving the local search ability of the algorithm.
[0014]
[0015] Among them, D L is the search step length, D is the initial step length, I c is the current iteration number, I max is the maximum number of iterations, and b is the offset.
[0016] The second improvement is that the two-dimensional information total entropy and the two-dimensional inter-class variance of the image are two criteria for judging image segmentation. This patent chooses to perform a weighted fusion of the two as the concentration fitness function, as shown in formula (2).
[0017]
[0018] Among them, F(s, t) is the concentration fitness value, is the total two-dimensional information entropy of the image, O(s, t) is the two-dimensional inter-class variance of the image, S i is the flavor concentration judgment value, i is the current optimization number, ω is the weight value, and r is the coefficient.
[0019] Furthermore, the scale-invariant feature transformation algorithm for multi-directional description of sparse points in step 2 specifically includes: based on the original SIFT algorithm, the following improvements are made: Improvement 1 is to expand the sparsity of key points and make the key points more evenly distributed. This patent sets a 3*3 suppression area and calculates the Harris response value R of all key points in the area according to formula (3): M , key points whose response values are less than the set threshold should be eliminated, making the remaining key points more stable.
[0020]
[0021] Among them, M is the covariance matrix, P is the image block, I xis the gradient value of the key point along the x direction, I y is the gradient value of the key point along the y direction, R M is the Harris response value, trace is the trace of the matrix, and k is the coefficient, which is 0.5.
[0022] The second improvement is to add the grayscale change characteristics of diagonal pixels on the basis of the original algorithm's description of key points, which is conducive to extracting more directional features of individual pig key points and improves the accuracy of feature acquisition.
[0023] 1) Calculate the gradient of the two diagonal directions of the pixel (x, y) according to formula (4).
[0024] G x (x,y)=I(x+1,y+1)-I(x-1,y-1),G y (x,y)=I(x-1,y+1)-I(x+1,y-1) (4)
[0025] Among them, G x (x,y),G y (x,y) is the gradient in the two diagonal directions, and I(x,y) is the value of the pixel (x,y).
[0026] 2) Calculate the gradient magnitude M(x,y) and direction value θ(x,y) according to formula (5).
[0027]
[0028] 3) Then perform histogram statistics of the pixels in the 4×4 window in 8 directions to form a 128-dimensional feature vector.
[0029] The original SIFT feature vector and the feature vector obtained by calculating the diagonal pixel changes are concatenated to finally obtain a 256-dimensional descriptor of the key point.
[0030] Furthermore, the multi-block improved central symmetric local octet pattern algorithm in step 2 specifically includes: the algorithm extracts features by sliding a 9*9 window, divides the window into 9 sub-windows of 3*3 pixels, calculates the average value of each sub-window, obtains a mean image block of 3*3 pixels, and then performs MB-ICSLOP coding calculation on the mean image block. MB-ICSLOP uses two-bit binary coding based on the comparison of the grayscale values of the central pixel and the adjacent pixels to increase the grayscale value comparison between neighboring pixels. It also uses three-bit binary coding to increase the grayscale value comparison of the central symmetric pixel points in the four gradient directions. This can better highlight the subtle difference information between the pixel points, making the extracted texture features more detailed and accurate, which is conducive to the identification of individual pigs. The specific formulas are shown in (6)-(9).
[0031]
[0032] Where s(i)=ν(f(p 2i -p 2i+1 ),f(p 2i+1 -p 2i+2 ))2 i (7)
[0033] t(i)=μ(f(p i -p c ),f(p i+4 -p c ),f(p i -p i+4 ))2 i (8)
[0034]
[0035] Where BM-ICSLOP(C) is the BM-ICSLOP code value of the current pixel C, s(i) is the code value of the neighborhood pixel value comparison, t(i) is the code value of the diagonal pixel value comparison, ν(a,b) represents a two-bit binary code value, μ(a,b,c) represents a three-bit binary code value, f(x) is the pixel comparison function, and p i is the neighborhood pixel value, p c is the center pixel value;
[0036] During the feature extraction process, an MB-ICSLOP operator can generate 150 patterns in a 9*9 pixel window. Therefore, a single pig image can extract 150-dimensional MB-ICSLOP features, reducing the feature dimension without losing detailed information.
[0037] Furthermore, the connected domain statistical features based on spatial distribution information in step 2 specifically include: the color histogram feature is a statistic of global color features, but lacks spatial distribution information of color. To improve this, this patent uses four statistical features of connected regions composed of local color range values to describe the pixel distribution information of the color range value in the image. The specific steps are as follows:
[0038] 1) Define connected domain: If two pixels meet the eight-neighborhood feature and their pixel values are the same, they are considered to belong to a connected domain.
[0039] 2) Divide the color values {0, 1, 2, ..., 255} in the R, G, and B components into 64 ranges in sequence, each with 4 color values. According to the definition of connected domains, find the connected domain image for each color range value, and mark all connected domains in the image.
[0040] 3) Count the number of pixels of the largest connected domain CR1, the number of pixels of the second largest connected domain CR2, and the number of all connected domains N in each connected domain image CR and the density of connected domains ρ CR , each connected domain image obtains 4-dimensional statistical features.
[0041] 4) By cascading the connected domain statistical features generated by the 64 color range values in each R, G, and B component, a 64*4*3=768-dimensional connected domain statistical feature can be obtained, which can better reflect the spatial information of the color.
[0042] Furthermore, the step 3 specifically includes: This patent uses a weighted serial feature fusion algorithm to combine three feature vectors. First, the feature vectors of the normalized SMD-SIFT feature, MB-ICSLOP feature, and the connected domain statistical feature based on spatial distribution information are defined as f1, f2, and f3 respectively. By F = [w1×f1,w2×f2,w3×f3] T The fused feature F is obtained, where w1, w2, and w3 are the weights of f1, f2, and f3, respectively. This feature is optimized using the improved hybrid breeding algorithm. The weighted features are then serially fused to obtain a 1174-dimensional feature. This large dimensionality results in a slow classification speed, so PCA is used for dimensionality reduction to improve classification speed.
[0043] In step 3 above, the improved hybrid breeding algorithm makes two improvements based on the original algorithm. The first improvement is to introduce a random perturbation factor α into the original hybrid operation. This factor uses formula (10) to generate random values to slightly perturb the individuals generated by hybridization, and uses formula (11) to generate new individuals, thereby improving the activity of individuals and the local optimization ability of the algorithm.
[0044] α=[max-rand()*(max-min)] (10)
[0045]
[0046] in, For sterile individuals, To maintain individuality, is a sterile line individual, r2 and r3 are random numbers in [-1,1], and r2+r3≠0, α is a random perturbation factor (max is the maximum value of the required random value, which is 2, min is the minimum value of the required random value, which is -2, that is, the value range of α is -2, -1, 0, 1, 2), [] means rounding, and the value range of rand() is [0, 1].
[0047] The second improvement is to address the shortcoming of the original self-intersection operation algorithm, which has a low optimization speed. According to formula (12), this patent sets a large initial step size in the early stage of algorithm optimization. However, as the number of iterations increases, the search step size gradually decreases. As a result, the global search capability of the algorithm is improved due to the large search range in the early stage, and the local optimization accuracy of the algorithm is improved due to the small search step size in the later stage. New individuals are generated by self-intersection according to formula (13).
[0048]
[0049]
[0050] Among them, I c is the current number of iterations, c0 is the initial value of the control step factor c, represents the new individuals produced by self-pollination of the restorer line, is a randomly selected individual in the restoration line, x best is the current global optimal individual.
[0051] Furthermore, step 4 specifically includes: when performing classification training on individual pig images, first sampling the original training set proportionally with replacement to generate three training subsets of equal size for training base classifiers. Then, the variability of the base classifiers is measured by calculating the Kappa value. The variability is maximized when selecting the three classifiers: KNN, SVM, and Bayes. Finally, the identity of the individual pig is identified using a weighted voting method. Specifically, each base classifier is assigned a weight, optimized using an improved crossbreeding algorithm, and the weighted sum of the identical results identified by the base classifiers is taken. The largest result is selected as the final identity of the individual pig.
[0052] In step 4 above, proportional sampling with replacement is proposed to address the shortcoming of the original Bootstrap sampling technique, which may cause some training data in the original training set to never be extracted. Assuming that the original training set has N samples, m training subsets need to be generated, and each subset requires n training samples, where n>(N / m). The specific steps are as follows: 1) The original training set is evenly distributed to each training subset by generating m parts; 2) The remaining (nN / m) samples in the subset are obtained by sampling with replacement from the original training set (excluding the training samples evenly distributed in the current subset), and finally m training subsets of equal size are generated. This ensures that all training data can be extracted for training.
[0053] For example, this patent selects a total of 9,000 images as the training set, and needs to generate 3 sub-training sets, each with 4,500 images. First, the training set data is evenly divided into 3 parts and distributed to each sub-training set. Each sub-training set has 3,000 images. The remaining 1,500 images are obtained by sampling with replacement on the original training set (excluding the 3,000 images evenly distributed in the current subset, and the remaining 6,000 images).
[0054] Beneficial effects of the present invention
[0055] (1) The nearest neighbor pixel comparison method in key areas selects images with low similarity in key areas as key frames to ensure the diversity of training data.
[0056] (2) The individual pig images were segmented using a watershed algorithm based on threshold optimization, which improved the threshold search speed and accuracy and effectively alleviated the over-segmentation problem of the traditional watershed algorithm.
[0057] (3) Based on the original SIFT algorithm, the SMD-SIFT algorithm uses the Harris response value and non-maximum suppression algorithm to further screen stable key points, and adds the grayscale change characteristics of pixels in the diagonal direction when describing the key points, thereby improving the accuracy of obtaining individual pig features.
[0058] (4) The multi-block improved central symmetric local octet pattern algorithm reduces the influence of random noise, illumination and edge changes by dividing the image into blocks and obtaining the grayscale mean. The texture change angle described by the formed mean block is more comprehensive, and the feature differences are captured more finely, making the extracted features more accurate, which is conducive to the identification of individual pigs.
[0059] (5) The connected domain statistical feature based on spatial distribution information is generated by concatenating the four statistical features of the connected domain composed of the color range values in all components of a single pig image. This feature can better reflect the color distribution information of the individual pig image.
[0060] (6) The improved hybrid breeding algorithm adds a random perturbation factor to the original hybridization operation to improve the activity of individuals and the local optimization ability of the algorithm; by improving the search step size, the global search ability and local optimization accuracy of the algorithm are improved.
[0061] (7) The Bootstrap sampling method is improved to a proportional sampling method with replacement to avoid the situation where some training data in the original training set are never extracted for training.
[0062] (8) The weighted ensemble classifier based on the improved hybrid breeding algorithm uses a proportional sampling method with replacement to generate three different training subsets from the training set, which improves the generalization performance of the model. The improved hybrid breeding algorithm is used to optimize the classifier weights to obtain the optimal weight combination. Finally, the identity of individual pigs is identified through weighted voting, which improves the performance of the ensemble classifier. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 It is a schematic diagram of MB-ICSLOP feature extraction in the present invention;
[0064] Figure 2 This is a comparison chart of different coding values in the present invention;
[0065] Figure 3 Schematic diagram of the statistical feature extraction of connected domains based on spatial distribution information in the present invention; DETAILED DESCRIPTION
[0066] The present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0067] Step 1: The overhead video of group-raised pigs is framed and the key frames are selected using the nearest neighbor pixel comparison method in the key area. After image enhancement, the watershed algorithm based on threshold optimization is used to segment the individual pigs, and seven individual pig images are obtained.
[0068] The specific method is as follows: First, a bird's-eye view video of seven pigs is collected and framed, and the key frame is selected using the key area nearest neighbor pixel comparison method. The specific steps of the key area nearest neighbor pixel comparison method are as follows: After the group pig video is framed, two adjacent frames are extracted according to the frame order. This patent mainly focuses on the identification of pigs in the drinking water area. The same drinking water area is selected in the two frames, and the pixel difference corresponding to the three RGB components of the area is calculated. If the pixel difference sum is less than the set threshold, the two frames are highly similar and the latter frame is discarded. Otherwise, the latter frame is saved, that is, the image with low similarity is used as the key frame.
[0069] Then, local histogram equalization is used to improve image contrast, and median filtering is used to remove introduced noise. The enhanced image is first extracted for valid areas, and then segmented using the threshold-optimized watershed algorithm. Morphological processing is then performed to calculate the area of each connected region. Finally, connected regions with an area smaller than the threshold are discarded to obtain a segmentation map of the individual pig. The specific steps of the threshold-optimized watershed algorithm are:
[0070] Step 1: Use the improved fruit fly optimization algorithm to search for the optimal threshold for segmentation to obtain a binary image;
[0071] Step 1.1, initialize the initial position (X, Y) of the fruit fly population, the initial search step size D, the maximum number of iterations T and the population size N;
[0072] Step 1.2: Use formula (1) to get the adaptive search step size D L , fruit flies search for food based on this distance and random direction, as shown in formulas (2)(3);
[0073]
[0074] X i =X+D L *rand() (2)
[0075] Y i =Y+D L *rand() (3)
[0076] Among them, D is the initial step size, t is the current number of iterations, I max is the maximum number of iterations, b is the offset, X i Y i is the coordinate value of the fruit fly individual; i is the number of fruit flies; rand() is the random search direction.
[0077] Step 1.3, calculate the flavor concentration judgment value based on the position coordinates of the fruit fly individual, as shown in formula (4);
[0078]
[0079] Step 1.4: Use equation (5) as the taste concentration judgment function to calculate the taste concentration value of each fruit fly;
[0080]
[0081] Among them, F(s, t) is the concentration fitness value, is the total two-dimensional information entropy of the image, O(s, t) is the two-dimensional inter-class variance of the image, S i is the flavor concentration judgment value, i is the current optimization number, ω is the weight value, and r is the coefficient.
[0082] Step 1.5: Update and record the optimal flavor concentration value and the coordinates of the optimal fruit fly individual, and continue iterating;
[0083] In step 1.6, the optimal threshold is obtained based on the coordinates of the final optimal fruit fly individual and binary segmentation is performed.
[0084] Step 2, obtain the background and foreground regions through morphological operations and distance transformation;
[0085] Step 3, mark the intersection of the background and foreground areas;
[0086] Step 4: Use the watershed algorithm to perform secondary segmentation to obtain the final segmentation result.
[0087] Following the above steps, a segmentation map of a single pig was obtained, and then feature extraction was performed on this segmentation map. In step 2, for each of the seven pig images, a scale-invariant feature transformation algorithm based on sparse point multi-directional description was used to extract local features of the pigs. A multi-block improved centrosymmetric local octet pattern algorithm was used to extract texture features of the pigs. A connected domain statistics algorithm based on spatial distribution information was used to extract color region block features of the pigs.
[0088] The specific method is as follows: The first extraction is SMD-SIFT features, the specific steps are as follows:
[0089] The original SIFT feature method is used to extract all key points in the pig individual image. Secondly, in order to expand the sparsity of key points and make the key points more evenly distributed, this patent sets a 3*3 suppression area and calculates the Harris response value R of all key points in the area according to formula (6): M , remove key points whose response values are less than the set threshold and retain the most stable key points.
[0090]
[0091] Among them, M is the covariance matrix, P is the image block, I x is the gradient value of the key point along the x direction, I y is the gradient value of the key point along the y direction, R M is the Harris response value, trace is the trace of the matrix, and k is the coefficient, which is 0.5.
[0092] Then, the main direction of the key points is found according to the original SIFT algorithm to ensure the rotation invariance of the features.
[0093] The original SIFT feature descriptor only considers the grayscale changes of pixels in the horizontal and vertical directions. The steps are as follows:
[0094] 1) Calculate the vertical and horizontal gradients of the pixel (x, y) as shown in formula (7).
[0095] G x (x,y)=I(x-1,y)-I(x+1,y),G y (x,y)=I(x,y+1)-I(x,y-1) (7)
[0096] Among them, G x (x,y),G y (x,y) represents the vertical gradient and horizontal gradient of pixel (x,y) respectively.
[0097] Calculate the gradient magnitude M(x,y) and direction value θ(x,y) as shown in formula (8).
[0098]
[0099] Then, the pixels in the 4×4 window are subjected to histogram statistics in 8 directions to form a 128-characteristic vector.
[0100] 2) The improved SIFT algorithm incorporates the grayscale variation features of adjacent diagonals, which improves the accuracy of feature acquisition. The gradients of the two diagonal directions of the pixel (x, y) are calculated according to formula (9).
[0101] G x (x,y)=I(x+1,y+1)-I(x-1,y-1),G y (x,y)=I(x-1,y+1)-I(x+1,y-1) (9)
[0102] Among them, G x (x,y),G y (x,y) represents the gradient of the two diagonal directions of the pixel (x,y).
[0103] The gradient magnitude M(x, y) and direction value θ(x, y) in the diagonal direction are calculated according to formula (8).
[0104] Then the pixels in the 4×4 window are histogram-counted in 8 directions to form a 128-characteristic vector.
[0105] 3) Finally, the original SIFT feature vector and the feature vector calculated by diagonal elements are concatenated to obtain a 256-dimensional descriptor of the key point, which improves the accuracy of feature acquisition.
[0106] The second extracted feature is the MB-ICSLOP feature. The specific steps are as follows:
[0107] Slide the 9*9 window to extract features, and divide the window into 9 sub-windows of 3*3 pixels; first calculate the average value of each sub-window to obtain the mean image block of 3*3 pixels, then perform ICSLOP coding calculation on the mean image block, and finally generate MB-ICSLOP features. Figure 1 shown.
[0108] MB-ICSLOP uses two-bit binary coding to compare the grayscale values of the central pixel and the adjacent pixels, which increases the grayscale value comparison between neighboring pixels. It also uses three-bit binary coding to increase the grayscale value comparison of the central symmetrical pixels in the four gradient directions. Figure 2 As shown in Figure 1, compared with LBP and CSLOP coding, ICSLOP coding generated by averaging the blocks can capture texture features with smaller variations, making the extracted features more accurate and conducive to the identification of individual pigs. Specifically, as shown in formulas (10)-(13).
[0109]
[0110] Where s(i)=ν(f(p 2i -p 2i+1 ),f(p 2i+1 -p 2i+2 ))2 i (11)
[0111] t(i)=μ(f(p i -p c ),f(p i+4 -p c ),f(p i -p i+4 ))2 i (12)
[0112]
[0113] Where BM-ICSLOP(C) is the BM-ICSLOP code value of the current pixel C, s(i) is the code value of the neighborhood pixel value comparison, t(i) is the code value of the diagonal pixel value comparison, ν(a,b) represents a two-bit binary code value, μ(a,b,c) represents a three-bit binary code value, f(x) is the pixel comparison function, and p i is the neighborhood pixel value, p c is the center pixel value;
[0114] During the feature extraction process, an MB-ICSLOP operator can generate 150 patterns in a 9*9 pixel window. Therefore, a single pig image can extract 150-dimensional MB-ICSLOP features, reducing the feature dimension without losing detailed information.
[0115] The third extraction is the statistical features of the connected domain based on spatial distribution information. The specific steps are as follows:
[0116] In the RGB color space, the color values {0, 1, 2, ..., 255} of each R, G, and B component are divided into 64 ranges in order, and each range has 4 color values. In this patent, if two pixels meet the characteristics of eight-neighborhood proximity and the pixel values are the same, then the two pixels are considered to belong to a connected area. According to the definition of the connected domain, a connected domain image of each color range value is found, and all connected domains in the image are marked as distinguished, and pixels not in the connected domain are set to 0. As shown in the accompanying description Figure 3 As shown. Use the ConnectedComponentsWithStats function in OpenCV to calculate the area and number of connected regions, and statistically obtain the number of pixels CR1 of the largest connected region, the number of pixels CR2 of the second largest connected region, the number of all connected regions N CR and the density of the connected regions (S CR represents the sum of pixels of each color range value in the S component), and the color connected region statistical features of the images of each color range value in the S component can be obtained as {CR1, CR2, N CR , ρ CR}. Finally, calculate the 4 connected region statistical features formed by each color range value in all components of a single pig image, and cascade them to generate a 768-dimensional connected region statistical feature based on spatial distribution information with 64 * 4 * 3 = 768 dimensions.
[0117] Step 3: After normalizing the three features extracted above, assign a weight to each feature, optimize it using an improved hybrid breeding algorithm, then perform serial fusion on the weighted features, and finally perform dimensionality reduction using PCA.
[0118] The specific method is as follows: After extracting the above three features according to Step 3, this patent uses a weighted serial feature fusion algorithm to fuse the three feature vectors. Define the feature vectors of the normalized SMD-SIFT feature, MB-ICSLOP feature, and connected region statistical feature based on spatial distribution information as f1, f2, and f3 respectively. The fused feature F can be obtained through F = [w1 × f1, w2 × f2, w3 × f3] T where w1, w2, and w3 are the weights of f1, f2, and f3 respectively, and their values are optimized using an improved hybrid breeding algorithm, and then serial fusion is performed on the weighted features. The fused feature has good classification accuracy. For the fused feature, the feature dimension is 1174 (256 + 150 + 768) dimensions, which is not conducive to improving the classification performance and classification speed of the subsequent classifier. Therefore, it is necessary to simplify the fused feature. PCA is a very mature feature extraction and dimensionality reduction method, and its main idea is to map n-dimensional features to k dimensions (k < n). In order to determine the optimal dimension after dimensionality reduction, the recognition results of six different dimensions of 100, 120, 140, 160, 180, and 200 are compared. By comparing the recognition accuracies of different dimensions, when the fused feature is reduced to 180 dimensions, the recognition accuracy of pig identification is the highest.
[0119] In the above Step 3, the specific steps of the improved hybrid breeding algorithm are as follows:
[0120] Step 1: Initialize the population, including the population size N, the maximum number of iterations I max and the maximum number of self-crosses Tmax , the population individuals are initialized as shown in formula (14);
[0121] x i =x min +r1·(x max -x min ) (14)
[0122] Among them, x i represents the i-th individual in the population, x max 、x min are the upper and lower limits of x, respectively; r1 and r4 are random numbers in [0,1].
[0123] Step 2: Sort the individuals in the population according to their fitness values from high to low. The maintainer line is the individuals in order 1 to N / 3, the restorer line is the individuals in order N / 3+1 to 2N / 3, and the sterile line is the individuals in order 2N / 3+1 to N. The individual with the highest current fitness value is stored.
[0124] Step 3: The maintainer line p and the sterile line q are hybridized to produce new individuals, as shown in formula (16);
[0125] α=[max-rand()*(max-min)] (15)
[0126]
[0127] in, For sterile individuals, To maintain individuality, is a sterile line individual, r2 and r3 are random numbers in [-1,1], and r2+r3≠0, α is a random perturbation factor (max is the maximum value of the required random value, which is 2, min is the minimum value of the required random value, which is -2, that is, the value range of α is -2, -1, 0, 1, 2), [] means rounding, and the value range of rand() is [0, 1].
[0128] Step 4: Calculate the fitness value of the new individual. If it is greater than the fitness value of the original individual, replace it; otherwise, retain the original individual.
[0129] Step 5, if the number of self-crossing <T max , the restorer individual performs self-crossing operation to generate a new restorer individual, as shown in formula (18), otherwise the reset operation is performed according to formula (14). If the fitness value of the new individual is greater than the fitness value of the original individual, it is replaced;
[0130]
[0131]
[0132] Among them, I c is the current number of iterations, c0 is the initial value of the control step factor c, represents the new individuals produced by self-pollination of the restorer line, is a randomly selected individual in the restoration line, x best is the current global optimal individual.
[0133] Step 6, if the number of iterations max , execute step 2; if the number of iterations>=I max , then the global optimal individual is output.
[0134] Step 4: Use a weighted ensemble classifier based on the improved hybrid breeding algorithm to classify and train individual pig images.
[0135] The specific method is as follows: when performing classification training on individual pig images, the original training set is first sampled with replacement in proportion. This patent randomly selects three training subsets of the same size from the original training set to train the base classifier. In this way, the training set samples selected by different base classifiers are different, further increasing the differences in the training of the base classifiers, thereby improving the generalization performance of the classifier.
[0136] Proportional sampling with replacement was proposed to address the drawback of the original Bootstrap sampling technique, which may cause some training data in the original training set to remain unsampled. Assuming the original training set contains N samples, m training subsets need to be generated, each of which requires n training samples, where n > (N / m). The specific steps are as follows: Step 1: Distribute the original training set into m equal portions, each of which is assigned to each training subset. Step 2: The remaining (nN / m) samples in the subset are obtained by sampling with replacement from the original training set (excluding the training samples that were evenly distributed in the current subset), generating m training subsets of equal size. For example, this patent selects a total of 9,000 images as the training set, and needs to generate 3 sub-training sets, each with 4,500 images. First, the training set is evenly divided into 3 parts of data and distributed to each sub-training set. Each sub-training set has 3,000 images. The remaining 1,500 images are obtained by sampling with replacement from the original training set (excluding the 3,000 images evenly distributed in the current subset, and the remaining 6,000 images).
[0137] The Kappa value is then used to measure the differences between the base classifiers. The larger the Kappa value, the smaller the correlation between the classifiers and the more significant the ensemble effect. According to the Kappa value analysis, the differences are greatest when the three classifiers, KNN, SVM, and Bayes, are selected. Finally, the individual pigs are identified using a weighted voting method. This method assigns a weight to each base classifier, adds up the weighted results of the same identifications from the base classifiers, and selects the largest result as the final identity of the individual pig. The final decision function for the test sample x is shown in Formula (19).
[0138]
[0139] Among them, C x is the judgment value of sample x, d is the number of base classifiers, t ji is the value of the i-th base classifier classifying sample x into the j-th class, w i is the weight of the i-th base classifier, and its value is optimized by the improved cross-breeding algorithm.
[0140] The above examples are merely examples to illustrate the feasibility of the present invention, but are not limited thereto.
Claims
1. A method for identifying pigs in group farming based on feature fusion, characterized in that: The following steps are involved: Step 1: The overhead video of group-raised pigs is framed and the key frames are selected using the nearest neighbor pixel comparison method in the key area. After image enhancement, the improved watershed algorithm based on threshold optimization is used to segment the pigs, obtaining seven individual pig images. The threshold optimization uses the improved fruit fly optimization algorithm AOIES-FOA. Step 2: For each of the seven pig images, the sparse point multi-directional description scale-invariant feature transform (SMD-SIFT) algorithm was used to extract the local features of the pigs. The multi-block improved centrosymmetric local octet pattern algorithm (MB-ICSLOP) was used to extract the texture features of the pigs. The connected domain statistics algorithm based on spatial distribution information was used to extract the color region block features of the pigs. Step 3: After normalizing the three extracted features, each feature is assigned a weight and optimized using the improved hybrid breeding algorithm (IHBA). The weighted features are then serially fused, and finally PCA is used for dimensionality reduction to improve the recognition efficiency of individual pig images. The improved serial weighted fusion algorithm in step 3 specifically includes: 1) The feature vectors of the normalized SMD-SIFT feature, MB-ICSLOP feature, and the connected domain statistical feature based on spatial distribution information are defined as f1, f2, and f3 respectively; 2) Through F = [w1×f1,w2×f2,w3×f3] T Obtain the fused feature F, where w1, w2, and w3 are the weights of f1, f2, and f3, respectively, and optimize it using the improved hybrid breeding algorithm; 3) Serial fusion of weighted features yields 1174-dimensional features. However, the dimension is large and the classification speed is slow. PCA is used for dimensionality reduction to improve the classification speed. The improved hybrid breeding algorithm IHBA in step 3 specifically includes: 3.1) A random perturbation factor α is introduced into the original crossover operation. This factor uses formula (10) to generate random values to slightly perturb the individuals generated by crossover, and uses formula (11) to generate new individuals, thereby improving the activity of individuals and the local optimization ability of the algorithm. α=[max-rand()*(max-min)] (10) In formula (10)(11), For sterile individuals, To maintain individuality, is a sterile line individual, r2 and r3 are random numbers in [-1,1], and r2+r3≠0, α is a random perturbation factor, max is the maximum value of the required random value, which is 2, and min is the minimum value of the required random value, which is -2, that is, the range of α is (-2, -1, 0, 1, 2), [] indicates rounding, and the range of rand() is [0, 1]; 3.2) In order to address the shortcoming of the original self-intersection operation algorithm in that its optimization speed is not high, a larger initial step size is set in the early stage of the algorithm optimization according to formula (12). However, as the number of iterations increases, the search step size gradually decreases. As a result, the global search capability of the algorithm is improved due to the larger search range in the early stage, and the smaller search step size in the later stage improves the local optimization accuracy of the algorithm. New individuals are generated by self-intersection according to formula (13). In formulas (12) and (13), I c is the current number of iterations, c0 is the initial value of the control step factor c, represents the new individuals produced by self-pollination of the restorer line, is a randomly selected individual in the restoration line, x best is the current global optimal individual; In step 4, a weighted ensemble classifier based on the improved hybrid breeding algorithm is used for training. First, three different training subsets are generated from the data set using a proportional sampling method with replacement. The three classifiers with the largest differences are measured by the Kappa value and trained in parallel. Then, the improved hybrid breeding algorithm is used to optimize the weights of the classifiers to obtain the optimal weight combination. Finally, the identity of the individual pigs is identified by weighted voting.
2. A method for identifying pigs in groups based on feature fusion according to claim 1, characterized in that: The key frame selection by the nearest neighbor pixel comparison method in the key area in step 1 specifically includes: After dividing the group pig farming video into frames, two adjacent frames are taken out according to the frame order. The main purpose is to identify the identity of pigs in the drinking water area. The same drinking water area is selected in the two frames, and the pixel difference corresponding to the three RGB components of the area is calculated. If the pixel difference is less than the set threshold, the two frames are highly similar and the latter frame is discarded. Otherwise, the latter frame is saved, that is, the image with low similarity is used as the key frame.
3. The method for identifying pigs in group according to claim 1, characterized in that: The watershed algorithm based on improved threshold optimization in step 1 specifically includes: First, the improved fruit fly optimization algorithm is used to search for the optimal threshold and perform threshold segmentation to obtain a binary image. Then, morphological operations and distance transformations are used to obtain the background and foreground areas. The intersection of the background and foreground areas is marked. Finally, the watershed algorithm is used to further segment the image to obtain the final segmentation result. The improved fruit fly optimization algorithm AOIES-FOA specifically includes: 1) According to formula (1), the fixed step size of the original algorithm is improved to adjust the search step size according to the number of iterations, so that the algorithm has a larger search step size in the early stage of optimization to perform global search, avoiding falling into local optimality too early. In the later stage of optimization, the search step size decreases with the increase of the number of iterations, thereby improving the local search ability of the algorithm. In formula (1), D L is the search step length, D is the initial step length, I c is the current iteration number, I max is the maximum number of iterations, b is the offset; 2) Select a suitable fitness function to improve the optimization accuracy. The two-dimensional information total entropy and the two-dimensional inter-class variance of the image are two criteria for judging image segmentation. The weighted fusion of the two is selected as the concentration fitness function, as shown in formula (2): In formula (2), F(s,t) is the concentration fitness value, is the total two-dimensional information entropy of the image, O(s,t) is the two-dimensional inter-class variance of the image, S i is the flavor concentration judgment value, i is the current optimization number, ω is the weight value, and r is the coefficient.
4. The method for identifying pigs in group according to claim 1, characterized in that: The scale-invariant feature transformation algorithm for the multi-directional description of sparse points in step 2 specifically includes: 2.1) In order to expand the sparsity of key points and make the key points more evenly distributed, a 3*3 suppression area is set and the Harris response value R of all key points in the area is calculated according to formula (3): M , remove key points whose response values are less than the set threshold and retain the most stable key points: In formula (3), M is the covariance matrix, P is the image block, trace is the trace of the matrix, and I x is the gradient value of the key point along the x direction, I y is the gradient value of the key point along the y direction, R M is the Harris response value, k is the coefficient, and its value is 0.5; 2.2) Based on the original algorithm's description of key points, the grayscale change characteristics of diagonal pixels are added to facilitate the extraction of more directional features of individual pig key points and increase the detailed information of the features. The specific steps are as follows: I) Calculate the gradient of the two diagonal directions of the pixel (x, y) according to formula (4); G x (x,y)=I(x+1,y+1)-I(x-1,y-1),G y (x,y)=I(x-1,y+1)-I(x+1,y-1) (4) In formula (4), G x (x,y),G y (x,y) is the gradient in the two diagonal directions, and I(x,y) is the value of the pixel (x,y); II) Calculate the gradient magnitude M(x,y) and direction value θ(x,y) according to formula (5); III) Then the pixels in the 4×4 window are histogram-generated in 8 directions to form a 128-dimensional feature vector; 2.3) Concatenate the original SIFT feature vector and the feature vector obtained by calculating the diagonal pixel changes to obtain a 256-dimensional descriptor for the key point.
5. The method for identifying pigs in groups based on feature fusion according to claim 1, characterized in that: The multi-block improved central symmetric local eight-element pattern algorithm in step 2 specifically includes: 1) Slide a 9*9 window to extract features, divide the window into 9 sub-windows of 3*3 pixels, calculate the average value of each sub-window, and obtain a mean image block of 3*3 pixels; 2) MB-ICSLOP coding is performed on the mean image block. MB-ICSLOP uses two-bit binary coding and three-bit binary coding based on the comparison of the grayscale values of the central pixel and the adjacent pixels. It increases the grayscale value comparison between the neighboring pixels and the grayscale value comparison of the central symmetric pixels in the four diagonal directions, effectively extracting the texture features of subtle changes, which is conducive to the identification of individual pigs. Specifically, as shown in formulas (6)-(9): Where, s(i) = n(f(p 2i -p 2i+1 ),f(p 2i+1 -p 2i+2 ))2 i (7) t(i)=μ(f(p i -p c ),f(p i+4 -p c ),f(p i -p i+4 ))2 i (8) Where BM-ICSLOP(C) is the BM-ICSLOP code value of the current pixel C, s(i) is the code value of the neighborhood pixel value comparison, t(i) is the code value of the diagonal pixel value comparison, ν(a,b) represents a two-bit binary code value, μ(a,b,c) represents a three-bit binary code value, f(x) is the pixel comparison function, and p i is the neighborhood pixel value, p c is the center pixel value; 3) During feature extraction, an MB-ICSLOP operator can generate 150 patterns in a 9*9 pixel window. Therefore, a single pig image can extract 150-dimensional MB-ICSLOP features, reducing the feature dimension without losing detailed information.
6. The method for identifying pigs in group according to claim 1, characterized in that: The step 2 of extracting the color region block features of individual pigs using the connected domain statistical algorithm based on spatial distribution information specifically includes: The color histogram feature is a statistic of global color features, but lacks information about the spatial distribution of colors. To improve this, four statistical features of the connected regions formed by local color range values are used to describe the pixel distribution information of the color range values in the image. The specific steps are as follows: Define connected domain: If two pixels meet the eight-neighborhood adjacent characteristics and the pixel values are the same, then the two pixels are considered to belong to a connected domain; Divide the color values {0, 1, 2, ..., 255} in the R, G, and B components into 64 ranges in sequence, each with 4 color values. Find the connected domain image for each color range value according to the connected domain definition, and mark all connected domains in the image. Count the number of pixels CR1 of the largest connected domain, the number of pixels CR2 of the second largest connected domain, and the number N of all connected domains in each connected domain image. CR and the density of connected domains ρ CR , each connected domain image obtains 4-dimensional statistical features; By cascading the connected domain statistical features generated by the 64 color range values in each R, G, and B component, a 64*4*3=768-dimensional connected domain statistical feature can be obtained, which can better reflect the spatial information of the color.
7. The method for identifying pigs in group raising based on feature fusion according to claim 1, characterized in that: In step 4, a weighted ensemble classifier based on an improved hybrid breeding algorithm is used for training, which specifically includes: 4.1 Sampling the original training set proportionally with replacement to generate three training subsets of equal size to train the base classifier; 4.2 The Kappa value is used to measure the difference between the base classifiers. When KNN, SVM and Bayes are selected, the difference is the largest. 4.3 The identity of individual pigs is identified by weighted voting. Each base classifier is assigned a weight and optimized by the improved hybrid breeding algorithm. The same results identified by the base classifiers are weighted and summed, and the largest result is selected as the final identity of the individual pig.
8. The method for identifying pigs in group raising based on feature fusion according to claim 1, characterized in that: The proportional sampling with replacement in step 4 specifically includes: Proportional sampling with replacement is proposed to address the shortcoming of the original Bootstrap sampling technique, which may cause some training data in the original training set to never be extracted. Assume that the original training set has N samples, and m training subsets need to be generated. Each subset requires n training samples, where n>(N / m). The specific steps are as follows: Generate m parts of the original training set on average and distribute them to each training subset; The remaining (nN / m) samples in the subset are obtained by sampling with replacement on the original training set. The above original training set requires removing the training samples evenly distributed in the current subset, and finally generating m training subsets of the same size, so that all training data can be sampled for training.
Citation Information
Patent Citations
Method for identifying identity of pigs in a drinking area based on HOG block feature histogram fusion
CN112800968A
Computing method based on super-pixel image similarity
WO2022001571A1