An Automatic Detection Method for Ideal Standing Posture of Sheep Based on Computer Vision

Through deep learning technology and edge computing, combined with side view image processing and machine learning classifiers, we automatically detect the ideal standing posture of sheep, solving the problem of measuring fluctuations of sheep body ruler and the sensitivity of traditional technology to light and angle changes, and achieving efficient and accurate automatic measurement of sheep body ruler.

CN117576733BActive Publication Date: 2025-06-03NANJING AGRICULTURAL UNIVERSITY
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202311665095.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-06
Publication Date
2025-06-03
Estimated Expiration
2043-12-06

AI Technical Summary

Technical Problem

When the prior art automatically measures the sheep body ruler, the measurement value fluctuates due to changes in the sheep posture, and traditional image processing and machine learning technologies are sensitive to changes in light and angle, making it difficult to ensure the accuracy of the measurement.

Method used

Deep learning technology combined with edge computing, we automatically detect the ideal standing posture of the sheep through side viewing images, including collecting and preprocessing image data, extracting key points of the sheep body skeleton feature using the DeepLabCut model, and identifying the ideal standing posture through a machine learning classifier.

Benefits of technology

It realizes efficient, accurate and automated sheep ideal posture detection, supports high-precision automatic measurement of contactless sheep body rulers, and is suitable for the field of intelligent animal husbandry technology.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117576733B_ABST
    Figure CN117576733B_ABST
Patent Text Reader

Abstract

The present invention discloses an automatic detection method for the ideal standing posture of sheep based on computer vision, including: S1, collecting sheep body image data in a sheep farm and preprocessing the data; S2, using a deep learning model for key point detection to extract key points of the sheep body skeleton features; S3, defining the judgment criteria for the ideal standing posture of sheep according to the requirements of sheep body measurement; S4, initially designing 21 groups of image feature vectors for the judgment of the ideal standing posture of sheep according to the judgment criteria for the ideal standing posture of sheep; S5, training a classifier to identify sheep in the ideal standing posture. The present invention applies deep learning technology to the detection of the ideal standing posture of sheep, realizing efficient, accurate, and automatic detection of the ideal standing posture of sheep. The technology disclosed by the present invention can help the breeding industry quickly and accurately screen out sheep body images in the ideal standing posture, providing technical support for high-precision non-contact automatic measurement of sheep body size based on computer vision, and having broad application prospects in the field of intelligent technology for livestock breeding.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of intelligent sheep breeding, and specifically relates to a method for detecting the ideal standing posture of sheep by using computer vision, machine learning, and edge computing technologies. Background Art

[0002] The body measurement data of sheep can be used to evaluate the growth status, health status, and genetic characteristics of sheep. The non-contact sheep body measurement method based on computer vision saves time and reduces labor costs compared with traditional manual measurement. However, when using computer vision technology to automatically measure the body size of sheep, changes in the posture of sheep will cause large fluctuations in the measured values of sheep body size. If the sheep body captured by the camera is distorted, there are missing local areas, or the sheep is not in a standing posture, it will be difficult to ensure the accuracy of automatic sheep body size measurement.

[0003] Currently, the methods for detecting the ideal standing posture of animals mainly rely on traditional image processing and machine learning technologies. First, a large amount of image data of animals in a standing state is collected; then, image processing technology is used to extract the standing posture characteristics of animals; finally, a machine learning model is used to automatically classify and determine whether the standing posture of animals is ideal. The method for detecting the ideal standing posture of animals based on traditional image processing and machine learning technologies may have good effects in some scenarios, but there are also some limitations, such as being more sensitive to changes in factors such as light and angle. In addition, sheep are naturally timid and easily stressed. Therefore, it is very necessary to propose a method that can detect the ideal standing posture of sheep, which is the basis for non-contact automatic measurement of sheep body size based on computer vision technology. Summary of the Invention

[0004] Whether a sheep is in an ideal standing posture is a prerequisite for automatically measuring its body size. An efficient, accurate, and deployable method for automatically detecting the ideal standing posture of sheep on an edge computing platform is needed to achieve non-contact automatic measurement of sheep body size. The present invention aims to solve the problem of how to automatically judge whether a sheep in a video frame image is in an ideal standing posture.

[0005] (1) Technical Solution of the Present Invention

[0006] In view of the above problems, the present invention proposes a method for automatically detecting the ideal standing posture of sheep according to a side view image, which is characterized by including the following steps (S1 to S5):

[0007] S1. Collect sheep body image data in a sheep farm and preprocess the data;

[0008] S1-1. Collect side view images of the sheep body;

[0009] S1-2. Perform operations such as brightness and contrast adjustment, filtering, noise reduction, and edge enhancement on the collected side view images of the sheep body to construct a sheep side view image dataset DS;

[0010] S2. Use a key-point detection deep learning model to extract the key points of the sheep body skeleton features;

[0011] S2-1. Determine 9 key points P1 to P9 according to the sheep body skeleton features, where: P1 is located at the position of the sheep's skull, P2 is located at the position of the sheep's thoracic vertebrae, P3 is located at the position of the sheep's hip bone, P4 is located at the position of the sheep's humerus, P5 is located at the position of the sheep's femur, P6 and P7 are respectively located at the joints and metacarpal bones of the sheep's right front limb, and P8 and P9 are respectively located at the joints and metacarpal bones of the sheep's left front limb;

[0012] S2-2. Use the k-means clustering algorithm to randomly sample from the side view images obtained in step S1 to construct the data set DS_kp for the sheep body skeleton key point localization model, and divide DS_kp into a training set DS_kp_tr and a test set DS_kp_te according to the ratio of 8:2;

[0013] S2-3. Perform key point annotation on the images in DS_kp_tr, and generate a CSV file for each image containing the names, abscissas, ordinates and confidences of the key points;

[0014] S2-4. Use the loss function sigmoid_cross_entropy_loss of the feature map prediction branch and the loss function huber_loss of the offset position as the objective function to evaluate the difference between the predicted key points of the model and the annotated points. The calculation formula is as follows:

[0015]

[0016] Among them, P in sigmoid_cross_entropy_loss n represents the actual label, represents the predicted probability of the model; y in huber_loss i represents the actual label, represents the predicted probability of the model, and θ is a hyperparameter used to control the mean square error when the error is small and the absolute error when the error is large.

[0017] S2-5. Preferably, select the ResNet50 network as the Backbone of the DeepLabCut model and train the deep neural network;

[0018] S2-6. Input DS_kp_te divided in S2-2 into the trained DeepLabCut model for prediction to obtain the positions of the sheep body skeleton key points, and generate a CSV file containing the names, abscissas, ordinates and confidences of the key points;

[0019] S3. Define the judgment criteria for the ideal standing posture of sheep according to the requirements of sheep body measurement as follows:

[0020] (1) The head of the sheep should lean forward by a sufficient distance and not lower down;

[0021] (2) The entire back of the sheep should be basically parallel to the ground without excessive undulations;

[0022] (3) The front legs of the sheep should be separated by an appropriate distance without contact, and the angle with the ground must be within a certain range;

[0023] (4) The body of the sheep should be roughly at the center position of the picture, and based on this, design the eigenvector for judging the ideal standing posture of the sheep;

[0024] S4. According to the judgment criteria for the ideal standing posture of sheep, initially design 21 groups of image feature vectors for judging the ideal standing posture of sheep as follows: the ratio of the height difference between P1 and P2 to the height difference between P2 and P3; the horizontal distance between P2 and P3; the angle between P7, P4, and P9; the height of P1; the angle between the line segment P1P2 and the horizontal plane; the ratio of the heights of P1 and P2; the ratio of the length of the line segment P1P2 to the length of the line segment P2P3; the height difference between the height of P1 and the higher of the heights of P2 and P3; the vertical distance between P2 and P3; the ratio of the heights of P2 and P3; the average value of the abscissas of P3 and P4; the angle between the line segment P2P3 and the horizontal plane; the horizontal distance between P6 and P8; the horizontal distance between P7 and P9; the ratio of the length of the line segment P6P8 to the length of the line segment P7P9; the angle between P6, P4, and P8; the angle between the line segment P6P7 and the frontal plane; the angle between the line segment P8P9 and the frontal plane; the average value of the abscissas of P1 and P3; the abscissa of P4; the abscissa of P5;

[0025] S5. Train a classifier to identify sheep in the ideal standing posture;

[0026] S5-1. Input DS into the trained DeepLabCut model for prediction to obtain key point information. Manually annotate whether the standing posture of the sheep in each image in DS is ideal according to the judgment criteria for the ideal standing posture of sheep, merge the annotation results with the key point information, and thus construct the standing posture classification data set DS_sc, and divide DS_sc into a training set DS_sc_tr and a test set DS_sc_te according to a ratio of 9:1;

[0027] S5-2. Use the following mathematical formula to calculate the modulus length and dot product required for calculating the angle between vectors in the 21 groups of image feature vectors designed in S4: The formula for calculating the modulus length |a| of vector a is: Among them, x and y represent the components of vector a on the x and y axes; the dot product calculation formula of vector a and vector b is: a·b = |a|×|b|×cosθ, where θ is the included angle between vector a and b, and the value range is [0, π]; the cosine value cosθ of the included angle between vector a and b can be calculated through the moduli and dot product of vector a and b, and converting the cosine value to the corresponding angle θ is the included angle between vector a and b;

[0028] S5-3. Extract the 21 groups of image feature vectors preliminarily designed in step S4 from DS_sc_tr, and calculate the weights and correlations of the feature vectors;

[0029] S5-4. Use PCA (Principal Component Analysis) to reduce the dimension of the highly correlated feature vectors to obtain 17 groups of image feature vectors;

[0030] S5-5. Extract the 17 groups of image feature vectors obtained in S5-4 from DS_sc_tr, and input them into a machine learning classifier to classify and identify whether the sheep standing posture is ideal. Preferably, a random forest is selected as the classifier, and the grid search method is used for parameter tuning;

[0031] S5-6. Input DS_sc_te into the trained random forest model for prediction to achieve a rapid and accurate ideal standing posture screening process.

[0032] Advantages of the present invention

[0033] The present invention applies deep learning technology to the detection of the ideal standing posture of sheep and deploys it on an edge computing platform, realizing efficient, accurate, and automated automatic detection of the ideal standing posture of sheep bodies. The technology disclosed by the present invention can help the breeding industry quickly and accurately screen out sheep body images in the ideal standing posture, providing technical support for the high-precision non-contact automatic measurement of sheep body dimensions based on computer vision, and having a wide application prospect in the field of intelligent technology for livestock breeding. Description of the drawings

[0034] Figure 1 is the overall flowchart of the method for automatically detecting the ideal standing posture of sheep based on computer vision according to the present invention.

[0035] Figure 2 is the distribution diagram of the key points of the sheep body skeleton features according to the present invention.

[0036] Figure 3 is the working flowchart of the DeepLabCut algorithm according to the present invention.

[0037] Figure 4 is the working flowchart of the random forest (RF) algorithm of the invention.

[0038] Figure 5 is the schematic structural diagram of the device for automatically measuring the sheep body dimensions in the embodiment. Detailed implementation manners

[0039] The present invention will be further described below in conjunction with the accompanying drawings and embodiments. In the embodiments of the present invention, a method for automatically detecting the ideal standing posture of sheep based on computer vision is provided. This method collects image data on-site and performs preprocessing, uses a deep learning algorithm to extract the key points of the sheep body skeleton features, defines the ideal standing posture through these key points, and finally realizes the screening process of the ideal standing posture based on machine learning. The overall flowchart of this method is as Figure 1 shown, and mainly includes the following steps (S1 to S5):

[0040] S1. Collect the image data of the sheep body in the sheep farm and preprocess the data;

[0041] S1-1. Collect the side view images of the sheep body;

[0042] S1-2. Adjust the brightness and contrast of the images to ensure that the visual effects of the images are clearer; by using filters and noise reduction algorithms, the noise interference in the images is effectively reduced or eliminated; and then through means such as sharpening, smoothing, and enhancing edges, the details and clarity of the images are further optimized, and the image quality is improved;

[0043] S2. Use the key point detection deep learning model DeepLabCut to extract the key points of the sheep body skeleton features. The working process of the DeepLabCut algorithm is shown in Figure 2 ;

[0044] S2-1. The present invention mainly focuses on the key points of the head, front limbs and back regions, and ignores the key points of the tail and hind limb regions. According to the sheep body skeleton features, a total of 9 key points of the sheep body skeleton, namely P1-P9, are designed, as Figure 3 shown. Among them, P1 is located at the position of the sheep's skull, P2 is located at the position of the thoracic vertebrae of the sheep body, P3 is located at the position of the hip bone of the sheep body, P4 is located at the position of the humerus of the sheep body, P5 is located at the position of the femur of the sheep body, P6 and P7 are respectively located at the joints and metacarpal bones of the right front limb of the sheep body, and P8 and P9 are respectively located at the joints and metacarpal bones of the left front limb of the sheep body;

[0045] S2-2. Use the k-means clustering algorithm to randomly sample from the side view images obtained in step S1 to construct the dataset DS_kp for the sheep body skeleton key point positioning model, and divide DS_kp into a training set DS_kp_tr and a test set DS_kp_te according to the ratio of 8:2;

[0046] S2-3. Perform key point annotation on the images in DS_kp_tr, and generate a CSV file containing the name, abscissa, ordinate and confidence of each key point for each image;

[0047] S2-4. Use the loss function as the objective function to evaluate the difference between the model prediction and the label. There are mainly two loss functions in the DeepLabCut model, namely the sigmoid_cross_entropy_loss of the feature map part_pred prediction branch and the huber_loss of the offset position locref. The overall loss is the sum of the loss of the feature map part_pred prediction branch and the weighted offset position locref loss. The calculation formula is as follows:

[0048]

[0049] Among them, P in sigmoid_cross_entropy_loss n represents the actual label, represents the predicted probability of the model; y in huber_loss i represents the actual label, represents the predicted probability of the model, and θ is a hyperparameter used to control the use of mean squared error when the error is small and absolute error when the error is large.

[0050] S2-5. DeepLabCut provides a replaceable Backbone (main network) to balance speed and performance. Preferably, the ResNet50 network is selected for the training of the deep network. The number of iterations is set to 1000000, the batch_size is set to 8, and the snapshotindex is set to 100000. Among them, epoch represents the number of training iterations, batch_size represents the number of samples input at a time, and snapshotindex represents the frequency of automatically saving the model file.

[0051] S2-6. Input the DS_kp_te divided in S2-2 into the trained DeepLabCut model for prediction to obtain the positions of the sheep body skeleton key points, and generate a CSV file containing the names, abscissas, ordinates, and confidences of each key point;

[0052] S2-7. Set the confidence threshold to 0.9. Only when the confidence exceeds this threshold will the corresponding key points be displayed in the image; otherwise, these key points will not be presented in the image to ensure the correctness of the key point positions;

[0053] S3. Define the criteria for judging the ideal standing posture of the sheep according to the requirements of sheep body measurement as follows. If the image does not meet any of the following conditions, it is defined as a non-ideal standing posture:

[0054] (1) The head of the sheep should lean forward a sufficient distance and not lower;

[0055] (2) The entire back of the sheep should be basically parallel to the ground without excessive undulations.

[0056] (3) The front legs of the sheep should be separated by an appropriate distance without contact, and the angle with the ground must be within a certain range.

[0057] (4) The body of the sheep should be roughly at the center of the picture, and the eigenvector for judging the ideal standing posture of the sheep should be designed accordingly.

[0058] S4. To more comprehensively describe and quantify the ideal standing posture of the sheep, according to the judgment criteria for the ideal standing posture of the sheep, 21 groups of image eigenvectors for judging the ideal standing posture of the sheep are preliminarily designed as follows: the ratio of the height difference between P1 and P2 to the height difference between P2 and P3; the horizontal distance between P2 and P3; the included angle among P7, P4, and P9; the height of P1; the angle between the line segment P1P2 and the horizontal plane; the ratio of the heights of P1 and P2; the ratio of the length of the line segment P1P2 to the length of the line segment P2P3; the height difference between the height of P1 and the higher one of the heights of P2 and P3; the vertical distance between P2 and P3; the ratio of the heights of P2 and P3; the average value of the abscissas of P3 and P4; the angle between the line segment P2P3 and the horizontal plane; the horizontal distance between P6 and P8; the horizontal distance between P7 and P9; the ratio of the length of the line segment P6P8 to the length of the line segment P7P9; the included angle among P6, P4, and P8; the angle between the line segment P6P7 and the frontal vertical plane; the angle between the line segment P8P9 and the frontal vertical plane; the average value of the abscissas of P1 and P3; the abscissa of P4; the abscissa of P5.

[0059] S5. Train a classifier to identify sheep in the ideal standing posture.

[0060] S5-1. Input DS into the trained DeepLabCut model for prediction to obtain key point information. Manually annotate whether the standing posture of the sheep in each image in DS is ideal according to the judgment criteria for the ideal standing posture of the sheep. For the images that meet the ideal standing posture criteria, set their labels to 1; for the images that do not meet the criteria, set their labels to 0. Combine the annotation results with the key point information to construct the standing posture classification dataset DS_sc, and divide DS_sc into a training set DS_sc_tr and a test set DS_sc_te according to the ratio of 9:1.

[0061] S5-2. Calculate the modulus length and dot product required for calculating the included angle between vectors in the 21 groups of image eigenvectors designed in S4.

[0062] S5-2-1. The formula for calculating the modulus length |a| of vector a is: where x and y represent the components of vector a on the x and y axes.

[0063] S5-2-2. The formula for calculating the dot product of vector a and vector b is: a·b = |a| × |b| × cosθ, where θ is the included angle between vectors a and b, and the value range is [0, π].

[0064] S5-2-3. The cosine value cosθ of the angle between vectors a and b can be calculated through the magnitudes and dot product of vectors a and b, and the corresponding angle θ obtained by converting the cosine value is the angle between vectors a and b.

[0065] S5-3. Extract the 21 groups of image feature vectors preliminarily designed in step S4 from DS_sc_tr, and calculate the weights and correlations of the feature vectors.

[0066] S5-3-1. Calculate the weights and correlations between the feature vectors to obtain a feature weight matrix and a feature correlation matrix.

[0067] S5-3-2. Sort the feature weights to obtain a feature sorting index.

[0068] S5-3-3. Construct a confusion matrix between the features to measure the degree of mutual influence between the features, and display the result in the form of a heat map.

[0069] S5-4. Use PCA (Principal Component Analysis) to reduce the dimension of the highly correlated feature vectors to obtain 17 groups of image feature vectors.

[0070] S5-4-1. Centralize the feature vectors so that their mean value is zero.

[0071] S5-4-2. Calculate the covariance matrix between the centralized feature vectors.

[0072] S5-4-3. Calculate the eigenvectors and eigenvalues of the covariance matrix.

[0073] S5-4-4. Sort the eigenvectors in descending order of eigenvalues.

[0074] S4-4-5. According to the magnitudes of the eigenvalues, select the feature vectors ranked in the front and eliminate the feature vectors at the end to obtain the following 17 groups of image feature vectors: the height of P1; the angle between the line segment P1P2 and the horizontal plane; the ratio of the heights of P1 and P2; the ratio of the length of the line segment P1P2 to the length of the line segment P2P3; the height difference between the height of P1 and the higher of the heights of P2 and P3; the vertical distance between P2 and P3; the ratio of the heights of P2 and P3; the angle between the line segment P2P3 and the horizontal plane; the horizontal distance between P6 and P8; the horizontal distance between P7 and P9; the ratio of the length of the line segment P6P8 to the length of the line segment P7P9; the angle between P6, P4, and P8; the angle between the line segment P6P7 and the frontal vertical plane; the angle between the line segment P8P9 and the frontal vertical plane; the average value of the abscissas of P1 and P3; the abscissa of P4; the abscissa of P5.

[0075] S5-5. Preferably, the random forest (RF) is selected as the classifier for automatically detecting the ideal standing posture of sheep. Extract the 17 groups of image feature vectors obtained from S5-4 from DS_sc_tr and input them into the trained random forest model for prediction to achieve a rapid and accurate ideal standing posture screening process. The random forest workflow is as follows Figure 4 shown;

[0076] S5-5-1. Set the random number seed random_state to 42 to ensure that the random state is controlled and the results can be reproduced;

[0077] S5-5-2. Continuously adjust the various parameters of the random forest using the grid search method to make the classification results optimal;

[0078] S5-5-3. The evaluation metrics for testing are Precision, Recall, F1-Score, and AUC value;

[0079] S5-6. After completing the training of the random forest classifier, save the weight file of the model locally. Input DS_sc_te into the trained random forest model for testing to achieve a rapid and accurate ideal standing posture screening process;

[0080] Preferably, in this embodiment, the random forest is used as the classification algorithm, which can also be replaced by other machine learning algorithms, including but not limited to K-nearest neighbor, decision tree, naive Bayes, logistic regression, support vector machine, etc. Preferably, the ResNet50 backbone network of the DeepLabCut algorithm is used in this embodiment, and there are also other backbone networks available for replacement. In this embodiment, the optimal solution is selected by comparing with the existing data.

[0081] In the preferred embodiment, the applicant's invention patent (application number: CN202211018538.6) submitted to the State Intellectual Property Office in 2022 is used to collect sheep body image data. As Figure 5 shown, it mainly includes the mechanical structure and control components of the device, Figure 52 and 4 are respectively the entrance access control and the entrance passage fence; 1 and 3 are respectively the exit access control and the exit passage fence; 13 is the glass baffle on the side of the side-view image acquisition camera in the image acquisition room; 14 is the movable baffle of the image acquisition room. The movable baffle 14 can move in the direction close to or away from the glass baffle 13 to adjust the width of the image acquisition room, so as to meet the image acquisition requirements of sheep bodies of different sizes; 12 is an electric push rod, and its telescopic end is connected to the movable baffle 14. The telescopic movement of the electric push rod 12 drives the movable baffle 14 to move to adjust the width of the image acquisition room; 5 is the top-view camera support; 7 is the top-view camera, which is used to take the top view of the sheep; 6 is the side-view camera support; 8 is the side-view camera, which is used to take the side view image of the sheep body. The height of the side-view camera 8 is the same as the center point of the side-view image acquisition side glass baffle 13; 9-3 is the entrance photoelectric sensor, 9-2 is the photoelectric sensor of the movable baffle of the image acquisition room, 9-1 is the exit photoelectric sensor. When the photoelectric sensor is blocked, it means that the sheep is in the position where the corresponding photoelectric sensor is installed; 10 is the RFID reader, which is installed inside the movable baffle 14 of the image acquisition room and is used to record the identity information of the sheep located in the image acquisition room. The installation heights of the entrance photoelectric sensor 9-3, the photoelectric sensor 9-2 of the movable baffle of the image acquisition room, and the exit photoelectric sensor 9-1 are at the height of the sheep's abdomen. The photoelectric sensor 9-2 of the movable baffle of the image acquisition room is installed close to the exit access control 1 to ensure that the entrance access control 2 is triggered to close the signal after the sheep completely enters the image acquisition room. The exit photoelectric sensor 9-1 is installed at a position away from the exit access control 1 to ensure that the exit access control 1 is triggered to close the signal after the sheep completely leaves.

[0082] The embodiments of the present application have been described above in conjunction with the accompanying drawings. However, the present application is not limited to the above specific embodiments. The above specific embodiments are merely illustrative and not restrictive. Under the inspiration of the present application, those of ordinary skill in the art can also make many forms without departing from the purpose of the present application and the scope protected by the claims, and all of them belong to the protection scope of the present application.

Claims

1. An automatic method for detecting the ideal standing posture of sheep based on computer vision, characterized in that, the method comprises the following steps: S1. Collect sheep body image data in the sheep farm and preprocess the data; S2. Use a key point detection deep learning model to extract the key points of the sheep body skeleton features; the key points include: P1 is located at the position of the sheep's skull, P2 is located at the position of the sheep's thoracic vertebra, P3 is located at the position of the sheep's hip bone, P4 is located at the position of the sheep's humerus, P5 is located at the position of the sheep's femur, P6 and P7 are respectively located at the joints and metacarpal bones of the sheep's right front limb, and P8 and P9 are respectively located at the joints and metacarpal bones of the sheep's left front limb; S3. Define the judgment criteria for the ideal standing posture of sheep according to the requirements of sheep body measurement; S4. According to the judgment criteria for the ideal standing posture of sheep, design 21 groups of image feature vectors for judging the ideal standing posture of sheep as follows: the ratio of the height difference between P1 and P2 to the height difference between P2 and P3; the horizontal distance between P2 and P3; the angle between P7, P4, and P9; the height of P1; the angle between the line segment P1P2 and the horizontal plane; the ratio of the heights of P1 and P2; the ratio of the length of the line segment P1P2 to the length of the line segment P2P3; the height difference between the height of P1 and the higher of the heights of P2 and P3; the vertical distance between P2 and P3; the ratio of the heights of P2 and P3; the average value of the abscissas of P3 and P4; the angle between the line segment P2P3 and the horizontal plane; the horizontal distance between P6 and P8; the horizontal distance between P7 and P9; the ratio of the length of the line segment P6P8 to the length of the line segment P7P9; the angle between P6, P4, and P8; the angle between the line segment P6P7 and the frontal vertical plane; the angle between the line segment P8P9 and the frontal vertical plane; the average value of the abscissas of P1 and P3; the abscissa of P4; the abscissa of P5; S5. Train a classifier to identify sheep in the ideal standing posture.

2. The method according to claim 1, characterized in that, the preprocessing in S1 includes performing brightness, contrast adjustment, filtering, noise reduction, and edge enhancement operations.

3. The method according to claim 1, characterized in that, the specific steps of S2 are: S2-1. Determine 9 key points P1 to P9 according to the sheep body skeleton features; S2-2. Use the k-means clustering algorithm to randomly sample from the side view images obtained in step S1 to construct a data set DS_kp for the sheep body skeleton key point localization model, and divide DS_kp into a training set DS_kp_tr and a test set DS_kp_te according to a ratio of 8:2; S2-3. Perform key point annotation on the images in DS_kp_tr, and generate a CSV file containing the names, abscissas, ordinates, and confidences of each key point for each image; S2-4. Use the loss function sigmoid_cross_entropy_loss of the feature map prediction branch and the loss function huber_loss of the offset position as the objective function to evaluate the difference between the predicted key points and the annotated points of the model; S2-5. Select the ResNet50 network as the backbone network Backbone of the DeepLabCut model, and train the deep neural network; S2-6. Input the DS_kp_te divided in S2-2 into the trained DeepLabCut model for prediction to obtain the positions of the key points of the sheep body skeleton, and generate a CSV file containing the names, abscissas, ordinates, and confidence levels of each key point.

4. According to the method described in claim 3, wherein, in S2-4, the calculation formulas of the sigmoid_cross_entropy_loss of the feature map prediction branch and the huber_loss of the offset position are as follows: Among them, P in sigmoid_cross_entropy_loss n represents the actual label, and represents the predicted probability of the model; y in huber_loss i represents the actual label, and represents the predicted probability of the model. θ is a hyperparameter used to control the use of mean squared error when the error is small and absolute error when the error is large.

5. According to the method described in claim 3, wherein, the specific steps of S5 are: S5-1. Input DS into the trained DeepLabCut model for prediction to obtain key point information; manually annotate whether the standing postures of the sheep in each image in DS are ideal according to the ideal standing posture determination criteria of the sheep, and merge the annotation results with the key point information to construct a standing posture classification dataset DS_sc, and divide DS_sc into a training set DS_sc_tr and a test set DS_sc_te according to a ratio of 9:1; S5-2. Calculate the modulus length and dot product required to find the angle between vectors in the 21 groups of image feature vectors designed by S4 using the following mathematical formulas: The formula for calculating the modulus length |a| of vector a is: where x and y represent the components of vector a on the x and y axes; the formula for the dot product of vector a and vector b is: a·b = |a| × |b| × cosθ, where θ is the angle between vectors a and b, and the value range is [0, π]; the cosine value cosθ of the angle between vectors a and b can be calculated through the modulus lengths and dot product of vectors a and b, and converting the cosine value to the corresponding angle θ is the angle between vectors a and b; S5-3. Extract the 21 groups of image feature vectors designed in step S4 from DS_sc_tr, and calculate the weights and correlations of the feature vectors; S5-4. Perform dimensionality reduction on the highly correlated feature vectors using principal component analysis PCA to obtain 17 groups of image feature vectors; S5-5. Extract the 17 groups of image feature vectors obtained in S5-4 from DS_sc_tr, and input them into a machine learning classifier to classify and identify whether the standing posture of the sheep is ideal; S5-6. Input DS_sc_te into the trained random forest model for prediction to achieve a rapid and accurate ideal standing posture screening process.

6. According to the method described in claim 5, wherein in S5-5, a random forest is selected as the classifier, and the grid search method is used for parameter tuning.

7. According to the method described in claim 1, wherein in S3, the ideal standing posture determination criteria of the sheep are as follows: (1) The head of the sheep should lean forward and not lower; (2) The entire back of the sheep should be basically parallel to the ground; (3) The front limbs of the sheep should be separated and not in contact, and the angle with the ground must be within a certain range; (4) The body of the sheep should be at the center position of the picture.

8. According to the method described in claim 1, wherein in S1, sheep body image data is collected based on a device for automatically measuring sheep body dimensions, and the device includes: An exit access control (1) provided at the exit of the image acquisition room, an exit passage fence (3) outside the exit, and an exit photoelectric sensor (9-1) provided inside the exit passage fence (3); an entrance access control (2) provided at the entrance of the image acquisition room, an entrance passage fence (4) outside the entrance, and an entrance photoelectric sensor (9-3) provided inside the entrance passage fence (4); A side view camera (8) is provided on one side of the image acquisition room based on a side view camera bracket (6) for taking side view images of the sheep body; an overhead camera (7) is provided on the top of the image acquisition room based on an overhead camera bracket (5) for taking overhead views of the sheep. A glass baffle (13) is arranged on the side of the side-view camera (8) in the image acquisition room. On the opposite side of the glass baffle (13) is a movable baffle (14). The telescopic end of the electric push rod (12) is connected to the movable baffle (14); the movable baffle (14) moves in the direction of approaching or moving away from the glass baffle (13) under the action of the electric push rod (12) to adjust the width of the image acquisition room, so as to meet the image acquisition requirements of sheep bodies of different sizes; a movable baffle photoelectric sensor (9-2) is arranged on the inner side of the movable baffle (14); an RFID reader (10) is arranged on the inner side of the movable baffle (14) for recording the identity information of the sheep located in the image acquisition room; The processor automatically calculates and obtains the sheep body size data based on the image information acquired by the image acquisition room.

Citation Information

Patent Citations

  • Device and method for automatically measuring sheep body size from side-view and top-view dual-view images

    CN115396576B

  • Data processing, training and recognition method and device and storage medium

    CN111881705A

  • Deep learning-based thoracolumbar fracture recognition, segmentation, detection and positioning method

    CN114494192A