A non-contact cattle weight measurement method based on target detection network model YOLOv8
Through the YOLOv8 model, the body ruler parameters are extracted, and the regression model is established, which solves the pressure and labor consumption problems of traditional cattle weight measurement methods, and realizes high-precision and automated cattle weight measurement, which improves breeding benefits.
Patent Information
- Application Number
- CN202311807863.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-26
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2043-12-26
AI Technical Summary
Traditional cattle weight measurement methods have the influence of pressure on cattle and the labor consumption, and the accuracy needs to be improved. The existing automation methods have manual intervention in the morphological feature extraction process, and the whole process cannot be automated.
Using the YOLOv8-based object detection network model, the pose and identity information of cows are collected through video, combined with background subtraction and edge extraction algorithms, the body ruler parameters are extracted, and a regression model is established for weight prediction.
Contactless and automated cattle weight measurement is achieved, with high accuracy and low mean square error between weight prediction and actual weight, which reduces the workload of breeding workers and improves breeding benefits.
Smart Images

Figure CN117765329B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of cattle weight target detection, and in particular relates to a non-contact cattle weight measurement method based on a target detection network model YOLOv8. Background Art
[0002] Live weight measurement is one of the most important indicators of livestock growth. It can clearly reflect the growth of livestock and affect feed intake, feed efficiency, lactation and other aspects. Therefore, the weight of cattle should be monitored regularly to better understand the growth and development of yaks and improve the breeding and feeding management level of farms. Traditionally, the weight of cattle is measured by scales, which will cause stress to cattle. According to the weighing records of experimental farms, each weighing may cause the cows to lose 2 to 10 kg due to stress and may affect the feed intake in the next three days. At the same time, due to the large size of cattle, this will also cause danger to the measurement personnel. At present, there are weight measurement models based on multi-sensors and deep learning models, including 2D and 3D aspects, which can reduce the pressure and labor consumption during weight measurement. Previous studies have shown that the morphological characteristics of cattle, such as width, height, etc., can predict weight. The researchers developed a regression model to predict the weight of cattle, which analyzes the correlation between weight and measurements obtained from 2D or 3D images. These studies all involve manual intervention in the process of extracting cattle morphological features, and the entire process is not automated, which consumes more labor and the accuracy needs to be improved. Therefore, it is urgent to develop a more accurate and automated method that can reduce the workload of breeding workers while predicting cattle weight, improving breeding results and reducing breeding costs. Summary of the invention
[0003] The purpose of the present invention is to overcome the shortcomings of the prior art, and provide a non-contact cattle weight measurement method based on the target detection network model YOLOv8. Firstly, by collecting cattle individual information videos and converting them into image frames, marking the normal posture and abnormal posture features of the cattle in the image, and establishing a cattle posture recognition model based on YOLOv8; the identity information of the cattle in the image is matched one by one, and an individual cattle recognition model is established based on YOLOv8; the body size parameters of the cattle are extracted by using algorithms such as background subtraction and edge extraction, and a plurality of body size parameters are combined to establish a regression model of cattle weight and body size parameters, and the model is used to predict the weight of the cattle; the present invention can timely and effectively measure the individual weight of the cattle, the performance index of the regression model of the cattle weight and body size parameters is excellent, and the mean square error between the predicted weight and the actual weight is extremely low, so that the management personnel can timely and accurately understand the cattle weight information and make corresponding processing, improve the cattle breeding efficiency, and has an excellent promotion and application prospect.
[0004] In order to achieve the above technical effects, the following technical solutions are adopted:
[0005] A non-contact cattle weight measurement method based on the target detection network model YOLOv8 comprises the following steps:
[0006] Step S1: Establishment of cow posture recognition model
[0007] Step S11: Use an image acquisition device to collect video data, and continuously collect video data of the upper back of the cow and video data of the left and right sides of the cow;
[0008] Step S12: Preliminary screening of the collected video data of the upper back of the cow and the video data of the left and right sides of the cow is performed to extract the cow posture image frame by frame;
[0009] Step S13: manually identify the cow posture images extracted in step S12, mark the cow posture categories, and convert all image annotations into storage labels in YOLO format;
[0010] Step S14: randomly divide the images with the labeled cow posture category into a training set and a test set according to the proportion;
[0011] Step S15: inputting the training set obtained in step S14 into the YOLOv8 network model to train the cattle posture recognition model, thereby obtaining a trained cattle posture recognition model;
[0012] Step S16: input the test set obtained in step S14 into the trained cattle posture recognition model, verify the model, and output the verification result to obtain the final cattle posture recognition model;
[0013] Step S2: Establishment of cattle individual identification model
[0014] Step S21: Use an image acquisition device to collect video data, and continuously collect video data of individual cattle identities;
[0015] Step S22: preliminarily screening the collected cattle individual identity video data, and extracting cattle individual identity images frame by frame;
[0016] Step S23: manually identify the cattle individual identity images extracted in step S22, mark the cattle individual identity information, and convert all image annotations into storage labels in YOLO format;
[0017] Step S24: randomly dividing the images with the identities of individual cows into a training set and a test set according to a certain proportion;
[0018] Step S25: inputting the training set obtained in step S24 into the YOLOv8 network model to train the cattle individual identity recognition model, thereby obtaining a trained cattle individual identity recognition model;
[0019] Step S26: inputting the test set obtained in step S24 into the trained cattle individual identity recognition model, verifying the model, and outputting the verification result to obtain the final cattle individual identity recognition model;
[0020] Step S3: Extraction of cattle body size parameter features
[0021] Use image acquisition equipment to collect video data of cattle that need to be tested for weight, continuously collect video data of the upper back of the cattle, video data of the left and right sides of the cattle, and video data of the individual identity of the cattle; extract the cattle posture image and the individual identity image of the cattle frame by frame;
[0022] First, the cow posture image is input into the established cow posture recognition model to recognize the cow posture. When the cow in the cow posture image is recognized as a normal posture, its posture image or the cow individual identity image is transmitted to the cow individual identity recognition model to perform individual identity recognition on the cow. After the cow individual identity recognition is completed, the image data of the upper back and the left and right sides of the specific cow are input into the cow body size parameter feature extraction module, including the following steps:
[0023] Step S31: Define the key points of the neck and tail
[0024] Define the cow's head on the left and the tail on the right as the positive direction, and obtain the cow's upper back image contour from the top perspective. In the left half of the cow's upper back contour, if the curvature change of the cow's back contour curve at two upper and lower points is greater than the curvature change of other nearby positions, and the body width of these two points is also smaller than the body width of other nearby positions, then these two points are defined as the upper neck key point a1 and the lower neck key point A1;
[0025] In the right half of the upper back contour of the cow, if the curvature change of the cow's contour curve at two points is greater than the curvature change of other nearby positions, and the body width of the two points is smaller than the left body width and larger than the right body width, then the two points are defined as the key point a on the tail n+1 and the key point A under the tail n+1 ;
[0026] Step S32: Extraction of cattle body size parameter features
[0027] Adjust the key points a1 on the neck and A1 on the lower neck to form a vertical line L1, and adjust the key points a1 on the tail to form a vertical line L1. n+1 and the key point A under the tail n+1 Adjust to form a vertical line L n+1 ;
[0028] Inside the outline of the cow's upper back, between the vertical lines L1 and L n+1 Set n-1 parallel lines L1 and L n+1 The vertical lines L2, L3, L4…Ln , vertical line L1 and vertical line L n+1 The distance between them is divided into n parts, among which the intersection point of vertical line L2 and the upper part of the cow's back contour is a2, the intersection point of vertical line L2 and the lower part of the cow's back contour is A2, the intersection point of vertical line L3 and the upper part of the cow's back contour is a3, the intersection point of vertical line L3 and the lower part of the cow's back contour is A3, the intersection point of vertical line L4 and the upper part of the cow's back contour is a4, the intersection point of vertical line L4 and the lower part of the cow's back contour is A4, and so on. n The intersection point with the upper part of the cow's back contour is a n , vertical line L n The intersection point with the lower part of the cow's back outline is A n ;
[0029] Calculate the vertical lines L1, L2, L3, L4...L n , L n+1 The lengths are recorded as L1, L2, L3, L4…L n , L n+1 ;
[0030] The maximum width of the cow's back is defined as the cow's body width, recorded as L n+2 ;
[0031] Calculate vertical line L1 and vertical line L n+1 The horizontal distance length, recorded as L n+3 ;
[0032] In the left and right side image data of the cow, define the cow's head on the left and the tail on the right as the positive direction, identify the highest point of the cow's back and the lowest point of the cow's hoof, take the difference to get the cow's body height, and record it as L n+4 ;
[0033] Calculate the area of the trapezoid formed by a1, a2, A1, A2, and record it as S1; calculate the area of the trapezoid formed by a2, a3, A2, A3, and record it as S2; calculate the area of the trapezoid formed by a3, a4, A3, A4, and record it as S3; and so on. n-1 , a n , A n-1 , A n The area of the trapezoid formed is recorded as S n-1 ; Calculate a n , a n+1 , A n , A n+1 The area of the trapezoid formed is recorded as S n ;
[0034] Calculate the upper and lower horizontal tangents and vertical lines L1 and L2 at the maximum width of the cow's back contour n+1The area of the rectangle enclosed by the intersection of the extended lines is recorded as S n+1 ;
[0035] Step S33: Determine the comprehensive combination index of cattle body size parameters and establish a regression model for the comprehensive combination index and cattle weight prediction
[0036] Determine the comprehensive combined index S of cattle body size parameters according to the following formula g :
[0037] S g =S1+S2+S3+S4+…+S n +S n+1 *L n+4 ;
[0038] Among them, n≥4;
[0039] Comprehensive index S of cattle body size parameters based on a single picture g ; Calculate the comprehensive combined index S of cattle body size parameters for 10-20 pictures g (average);
[0040] The actual weight of the cow and S g The relationship between the average and the predicted weight of cattle was analyzed by regression analysis to establish the comprehensive index S of cattle body size parameters. g (average) between the fitted regression models;
[0041] The actual weight of k cattle and the predicted weight of cattle are used to calculate the root mean square error of weight to evaluate the performance of the regression model, k ≥ 16; if the root mean square error of weight is less than 20kg, the predictive regression model is output for cattle weight prediction.
[0042] Furthermore, the image acquisition device in step S11 and step S21 is an acquisition device with an uninterrupted power supply and a storage system; the video data of the upper back of the cow is collected by the acquisition device placed directly above the cowshed, the video data of the left and right sides of the cow is collected by the acquisition device placed on the side of the trough, and the video data of the individual identity of the cow is collected by the acquisition device placed directly above the cowshed and the acquisition device placed on the side of the trough; there are 3-8 cows in the cowshed, and the acquisition time is 7-14d;
[0043] Furthermore, in step S13, the cow posture categories are divided into normal and abnormal postures, and the cow posture category determination method is: if the angle between the cow's neck and trunk in the top perspective image of the cow's back does not exceed 5 degrees, then the posture is considered to be a normal posture, otherwise it is an abnormal posture; if the cow's four limbs are standing on the ground at the same time in the left and right side images of the cow, and the angle between the cow's front two hooves and the angle between the cow's hind two hooves do not exceed 5 degrees, then the posture is considered to be a normal posture, otherwise it is an abnormal posture.
[0044] Furthermore, in step S14, the data ratio of the training set and the test set is 7-5:3-5.
[0045] Furthermore, the information contained in the cattle individual identity image in step S23 is: determining the cattle individual identity by identifying the cattle head and neck features or identifying cattle individual identity specific information; the marking cattle individual identity information is to number different cattle individuals for future use.
[0046] Furthermore, in step S24, the data ratio of the training set and the test set is 7-5:3-5.
[0047] Furthermore, the image acquisition device in step S3 is an acquisition device with an uninterrupted power supply and a storage system; the video data of the upper back of the cow is collected by the acquisition device placed directly above the cowshed, the video data of the left and right sides of the cow is collected by the acquisition device placed on the side of the trough, and the video data of the individual identity of the cow is collected by the acquisition device placed directly above the cowshed and the acquisition device placed on the side of the trough; there are 3-8 cows in the cowshed, and the acquisition time is 7-14d;
[0048] Furthermore, the specific method for obtaining the image contour of the upper back of the cow from the top perspective in step S31 is:
[0049] Read the timestamp on the image of the cow in normal posture, and use the YOLOv8 algorithm to detect whether there is a background without interference within 5s-20s before and after the time. If it exists, use the background as background image 1. If not, expand the search time range until background image 1 is found. At the same time, use image processing technology to extract the ground background color and automatically create a background image 2 containing less information. Subtract the background of the cow image in normal posture from background image 1 and background image 2 respectively, and then fuse the two background-subtracted images to obtain the final binary image.
[0050] The Canny edge extraction algorithm is used to extract the edge of the binary image to obtain the edge contour image of the cow.
[0051] Furthermore, in step S32, a machine vision algorithm is used to automatically complete the calculation and extraction of body size parameters throughout the entire process.
[0052] Furthermore, the regression model fitted in step S33 is:
[0053] Predicted cattle weight T (kg) = 11.15S g (Average)-36.96.
[0054] Furthermore, the cattle individual identity specific information includes tags, seals, colors, marks, and numbers on the cattle.
[0055] The beneficial effects of the present invention are:
[0056] 1. The present invention extracts the characteristics of cattle from two perspectives, top and side, with richer data and higher weight measurement accuracy;
[0057] 2. The present invention identifies the posture information of the cow by distinguishing the angle between the cow's neck and body. It is a contactless identification method. At the same time, the recognition angle of the cow's posture is the same as the contour extraction angle, which is conducive to feature extraction of the cow. The recognition process is simple and the recognition accuracy is high.
[0058] 3. Compared with the existing methods, the present invention divides the posture of cattle into normal posture and abnormal posture, so that no manual selection is required during the image processing process, the process is fully automated, and weight measurement is more convenient;
[0059] 4. The present invention identifies the individual identity information of cattle by distinguishing the characteristics of the head and neck of cattle or identifying the specific information of the individual identity of cattle. It is a contactless identification method with a simple identification process and high identification accuracy.
[0060] 5. The present invention can realize real-time measurement of cattle weight, meet the need of obtaining weight at any time, and provide data support for refined breeding;
[0061] 6. The present invention has the advantages of good stability and strong anti-interference ability. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. The drawings in the following description are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0063] Figure 1 This is a flow chart of non-contact measurement of cattle weight according to an embodiment of the present invention;
[0064] Figure 2 This is a schematic diagram of the definition of the back posture of a cow according to an embodiment of the present invention;
[0065] Figure 3 This is a schematic diagram of the side posture definition of a cow according to an embodiment of the present invention;
[0066] Figure 4 This is a schematic diagram of the body size parameters of the back of a cow according to an embodiment of the present invention;
[0067] Figure 5 This is a schematic diagram of body dimension parameters of a cow from the side according to an embodiment of the present invention;
[0068] Figure 6This is a flow chart of cattle posture recognition according to an embodiment of the present invention;
[0069] Figure 7 This is a flow chart of cattle individual identification according to an embodiment of the present invention;
[0070] Figure 8 This is a regression fitting curve diagram of the predicted body weight and body size parameters of cattle according to an embodiment of the present invention. DETAILED DESCRIPTION
[0071] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0072] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.
[0073] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations and / or combinations thereof.
[0074] Embodiment 1:
[0075] like Figure 1 , which is a flow chart of non-contact measurement of cattle weight according to an embodiment of the present invention;
[0076] like Figure 6 As shown, the method for recognizing the posture of a cow comprises the following steps:
[0077] S1: Use two image acquisition devices with uninterruptible power supply and local storage card to collect video data. Place one device directly above the cowshed and the other device on the side of the trough to ensure that the camera covers the entire cowshed. The video data of the cow's back is collected by the acquisition device placed directly above the cowshed, and the video data of the cow's left and right sides is collected by the acquisition device placed on the side of the trough. There are 6 cows in each cowshed, and the relevant video data of the cows is obtained 24 hours a day for 7 consecutive days.
[0078] S2: Perform a preliminary screening of the collected videos, use VSPlayer video editing software to extract cow posture images frame by frame, and save them in the cow posture image folder in picture format, a total of 4000 images;
[0079] S3: Use the image annotation tool to process the cow posture image obtained in S2, manually identify the category of the cow posture, and select the category to be marked. There are 2 categories in total, namely normal and abnormal postures;
[0080] The method for determining the type of cow posture is as follows: Figure 2 As shown in , if the angle between the neck and trunk of the cow in the top view image of the cow's back does not exceed 5 degrees, the posture is considered normal, otherwise it is abnormal; Figure 3 As shown, when the cow's four limbs are standing on the ground at the same time in the left and right side images of the cow, and the angle between the cow's front two hooves and the angle between the cow's back two hooves do not exceed 5 degrees, the posture is considered to be normal, otherwise it is an abnormal posture.
[0081] After all images are labeled, click to convert to YOLO format storage labels; the data information of the storage labels is the category, the position of the center pixel of the labeled target box in the image, and the size of the labeled box from left to right;
[0082] S4: The 4000 annotated cow posture images are randomly divided into training set and test set in a ratio of 7:3. The training set has 2800 images and the test set has 1200 images, and there is no overlap between the training set and the test set images.
[0083] S5: Build the operating environment required for YOLOv8;
[0084] S6: Input the training set obtained in S4 into YOLOv8 to train the cow posture recognition model;
[0085] S7: Input the test set into the trained model, verify the model, and output the verification result to obtain the final cow posture recognition model.
[0086] Embodiment 2:
[0087] like Figure 7 As shown, the cattle individual identification method comprises the following steps:
[0088] S1: Use two uninterruptible power supply and local storage card image acquisition devices to collect video data. Place one device directly above the cowshed and the other device on the side of the trough to ensure that the camera covers the entire cowshed. The image acquisition device is an uninterruptible power supply device with a storage system. The video data of individual cattle identities is collected by the acquisition device placed directly above the cowshed and the acquisition device placed on the side of the trough. There are 6 cows in each cowshed, and the relevant video data of the cattle is obtained 24 hours a day for 7 consecutive days.
[0089] S2: Perform a preliminary screening of the collected videos, extract individual cattle identity images frame by frame, and save them in the individual cattle identity image folder in picture format, a total of 4000 pictures;
[0090] S3: Use image annotation tools to process the cattle individual identity image obtained in S2, and manually identify the cattle individual identity information, and determine the cattle individual identity by identifying the cattle head and neck features or identifying cattle individual identity specific information; cattle individual identity specific information includes cattle labels, seals, colors, marks, numbers, etc.; select the identity category to be marked, a total of 6 categories, namely cow1 to cow6;
[0091] After all images are annotated, click to convert to YOLO format storage labels. The data information of the storage labels is from left to right: category, the position of the center pixel of the box of the annotated target in the image, and the size of the annotated box;
[0092] S4: The 4,000 labeled cattle individual identity images were randomly divided into a training set and a test set in a ratio of 7:3. The training set contained 2,800 images and the test set contained 1,200 images, and there was no overlap between the training set and the test set images.
[0093] S5: Build the environment required for YOLOv8.
[0094] S6: Input the training set into YOLOv8 to train the cattle individual recognition model;
[0095] S7: Input the test set into the trained model, verify the model, and output the verification result to obtain the final cattle individual recognition model.
[0096] Embodiment 3:
[0097] like Figure 1 As shown:
[0098] An image acquisition device with an uninterrupted power supply and a storage system is used to collect video data of cattle that need to be tested for weight, and video data of the upper back of the cattle, video data of the left and right sides of the cattle, and video data of the individual identity of the cattle are collected continuously; the video data of the upper back of the cattle is collected by a collection device placed directly above the cowshed, the video data of the left and right sides of the cattle is collected by a collection device placed on the side of the trough, and the video data of the individual identity of the cattle is collected by a collection device placed directly above the cowshed and a collection device placed on the side of the trough; there are 3-8 cows in the cowshed, and the collection time is 7-14 days; the posture image of the cattle and the individual identity image of the cattle are extracted frame by frame;
[0099] First, the cow posture image is input into the established cow posture recognition model to recognize the cow posture. When the cow in the cow posture image is recognized as a normal posture, its posture image or the cow individual identity image is transmitted to the cow individual identity recognition model to perform individual identity recognition on the cow. After the cow individual identity recognition is completed, the image data of the upper back and the left and right sides of the specific cow are input into the cow body size parameter feature extraction module, including the following steps:
[0100] (1) Define the key points of the neck and tail
[0101] Define the cow's head on the left and the tail on the right as the positive direction, and get the image outline of the cow's back from the top perspective:
[0102] Read the timestamp on the image of the cow in normal posture, and use the YOLOv8 algorithm to detect whether there is a background without interference within 5s-20s before and after the time. If it exists, use the background as background image 1. If not, expand the search time range until background image 1 is found. At the same time, use image processing technology to extract the ground background color and automatically create a background image 2 containing less information. Subtract the background of the cow image in normal posture from background image 1 and background image 2 respectively, and then fuse the two background-subtracted images to obtain the final binary image.
[0103] Use the Canny edge extraction algorithm to extract the edge of the binary image and obtain the edge contour image of the cow;
[0104] like Figure 4 As shown:
[0105] In the left half of the upper back contour of the cow, if the curvature change of the cow's back contour curve at two points is greater than the curvature change of other nearby positions, and the body width of the two points is also smaller than the body width of other nearby positions, then the two points are defined as the upper neck key point a1 and the lower neck key point A1;
[0106] In the right half of the upper back contour of the cow, if the curvature change of the cow's contour curve at two points is greater than the curvature change at other nearby positions, and the body width at these two points is smaller than the left body width and larger than the right body width, then these two points are defined as the upper tail key point a5 and the lower tail key point A5;
[0107] (2) Extraction of cattle body size parameters
[0108] Adjust the key point a1 on the neck and the key point A1 on the neck to form a vertical line L1, and adjust the key point a5 on the tail and the key point A5 on the tail to form a vertical line L5;
[0109] In the upper back contour of the cow, three vertical lines L2, L3, and L4 are set between the vertical line L1 and the vertical line L5 and are parallel to the vertical line L1 and the vertical line L5, and the distance between the vertical line L1 and the vertical line L5 is equally divided into four parts, wherein the intersection point of the vertical line L2 and the upper half of the cow back contour is a2, the intersection point of the vertical line L2 and the lower half of the cow back contour is A2, the intersection point of the vertical line L3 and the upper half of the cow back contour is a3, the intersection point of the vertical line L3 and the lower half of the cow back contour is A3, the intersection point of the vertical line L4 and the upper half of the cow back contour is a4, and the intersection point of the vertical line L4 and the lower half of the cow back contour is A4;
[0110] Calculate the lengths of the vertical lines L1, L2, L3, and L4 and record them as L1, L2, L3, and L4 respectively;
[0111] The maximum width of the cow's back contour is defined as the cow's body width, recorded as L6;
[0112] Calculate the horizontal distance between vertical line L1 and vertical line L5 and record it as L7;
[0113] like Figure 5 As shown, in the left and right side image data of the cow, the cow head is defined as the left and the tail is defined as the positive direction, the highest point M of the cow's back and the lowest point N of the cow's hoof are identified, and the difference is taken to obtain the body height of the cow, which is recorded as L8;
[0114] Calculate the area of the trapezoid formed by a1, a2, A1, A2, and record it as S1; calculate the area of the trapezoid formed by a2, a3, A2, A3, and record it as S2; calculate the area of the trapezoid formed by a3, a4, A3, A4, and record it as S3; calculate the area of the trapezoid formed by a4, a5, A4, A5, and record it as S4;
[0115] Calculate the area of the rectangle formed by the intersection of the upper and lower horizontal tangent lines of the maximum width of the cow's back contour and the vertical line L1 and the extension of the vertical line L5, and record it as S5;
[0116] The machine vision algorithm is used to automatically complete the calculation and extraction of the above body size parameters throughout the entire process;
[0117] (3) Determination of comprehensive combined index of cattle body size parameters and establishment of regression model of comprehensive combined index and cattle weight prediction
[0118] Determine the comprehensive combined index S of cattle body size parameters according to the following formula g :
[0119] S g =S1+S2+S3+S4+S5*L8;
[0120] Comprehensive index S of cattle body size parameters based on a single picture of a single cattle g; Calculate the comprehensive combined index S of the body size parameters of 20 pictures of a single cow g (average);
[0121] The actual weight of the cow and S g The relationship between the average and the predicted weight of cattle was analyzed by regression analysis to establish the comprehensive index S of cattle body size parameters. g (average) between the fitted regression models;
[0122] like Figure 8 As shown, the regression model is:
[0123] Predicted cattle weight T (kg) = 11.15S g (Average)-36.96.
[0124] The root mean square error of body weight was calculated using the actual body weight of k individual cattle and the predicted body weight of cattle to evaluate the performance of the regression model, k ≥ 16;
[0125] The regression model in this embodiment uses the weights of 16 cattle individuals to calculate the root mean square error of the weight, and the root mean square error of the weight is only 1.93 kg, and the performance index of cattle weight measurement is excellent.
[0126] In summary, the present invention discloses a non-contact cattle weight measurement method based on the target detection network model YOLOv8. Firstly, by collecting cattle individual information videos and converting them into image frames, marking the normal posture and abnormal posture features of the cattle in the image, and establishing a cattle posture recognition model based on YOLOv8; the identity information of the cattle in the image is matched one by one, and an individual cattle recognition model is established based on YOLOv8; the body size parameters of the cattle are extracted by using algorithms such as background subtraction and edge extraction, and a plurality of body size parameters are combined to establish a regression model of cattle weight and body size parameters, and the weight of the cattle is predicted by using the model; the present invention can timely and effectively measure the individual weight of the cattle, the performance index of the regression model of the cattle weight and body size parameters is excellent, and the mean square error between the predicted weight and the actual weight is extremely low, so that the management personnel can timely and accurately understand the cattle weight information and make corresponding processing, thereby improving the cattle breeding efficiency, and has an excellent promotion and application prospect.
[0127] At this point, those skilled in the art recognize that, although the embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived based on the contents disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and recognized as covering all such other variations or modifications.
Claims
1. A non-contact cattle weight measurement method based on the target detection network model YOLOv8, characterized in that: The measuring method comprises the following steps: Step S1: Establishment of cow posture recognition model Step S11: Use an image acquisition device to collect video data, and continuously collect video data of the upper back of the cow and video data of the left and right sides of the cow; Step S12: Preliminary screening of the collected video data of the upper back of the cow and the video data of the left and right sides of the cow is performed to extract the cow posture image frame by frame; Step S13: manually identify the cow posture images extracted in step S12, mark the cow posture categories, and convert all image annotations into storage labels in YOLO format; Step S14: randomly divide the images with the labeled cow posture category into a training set and a test set according to the proportion; Step S15: inputting the training set obtained in step S14 into the YOLOv8 network model to train the cattle posture recognition model, thereby obtaining a trained cattle posture recognition model; Step S16: input the test set obtained in step S14 into the trained cattle posture recognition model, verify the model, and output the verification result to obtain the final cattle posture recognition model; Step S2: Establishment of cattle individual identification model Step S21: Use an image acquisition device to collect video data, and continuously collect video data of individual cattle identities; Step S22: preliminarily screening the collected cattle individual identity video data, and extracting cattle individual identity images frame by frame; Step S23: manually identify the cattle individual identity images extracted in step S22, mark the cattle individual identity information, and convert all image annotations into storage labels in YOLO format; Step S24: randomly dividing the images with the identities of individual cows into a training set and a test set according to a certain proportion; Step S25: inputting the training set obtained in step S24 into the YOLOv8 network model to train the cattle individual identity recognition model, thereby obtaining a trained cattle individual identity recognition model; Step S26: inputting the test set obtained in step S24 into the trained cattle individual identity recognition model, verifying the model, and outputting the verification result to obtain the final cattle individual identity recognition model; Step S3: Extraction of cattle body size parameter features Use image acquisition equipment to collect video data of cattle that need to be tested for weight, continuously collect video data of the upper back of the cattle, video data of the left and right sides of the cattle, and video data of the individual identity of the cattle; extract the cattle posture image and the individual identity image of the cattle frame by frame; First, the cow posture image is input into the established cow posture recognition model to recognize the cow posture. When the cow in the cow posture image is recognized as a normal posture, its posture image or the cow individual identity image is transmitted to the cow individual identity recognition model to perform individual identity recognition on the cow. After the cow individual identity recognition is completed, the image data of the upper back and the left and right sides of the specific cow are input into the cow body size parameter feature extraction module, including the following steps: Step S31: Define the key points of the neck and tail Define the cow's head on the left and the tail on the right as the positive direction, and obtain the cow's upper back image contour from the top perspective. In the left half of the cow's upper back contour, if the curvature change of the cow's back contour curve at two upper and lower points is greater than the curvature change of other nearby positions, and the body width of these two points is also smaller than the body width of other nearby positions, then these two points are defined as the upper neck key point a1 and the lower neck key point A1; In the right half of the upper back contour of the cow, if the curvature change of the cow's contour curve at two points is greater than the curvature change of other nearby positions, and the body width of the two points is smaller than the left body width and larger than the right body width, then the two points are defined as the key point a on the tail n+1 and the key point A under the tail n+1 ; Step S32: Extraction of cattle body size parameter features Adjust the key points a1 on the neck and A1 on the lower neck to form a vertical line L1, and adjust the key points a1 on the tail to form a vertical line L1. n+1 and the key point A under the tail n+1 Adjust to form a vertical line L n+1 ; Inside the outline of the cow's upper back, between the vertical lines L1 and L n+1 Set n-1 parallel lines L1 and L n+1 The vertical lines L2, L3, L4…L n , vertical line L1 and vertical line L n+1 The distance between them is divided into n parts, among which the intersection point of vertical line L2 and the upper part of the cow's back contour is a2, the intersection point of vertical line L2 and the lower part of the cow's back contour is A2, the intersection point of vertical line L3 and the upper part of the cow's back contour is a3, the intersection point of vertical line L3 and the lower part of the cow's back contour is A3, the intersection point of vertical line L4 and the upper part of the cow's back contour is a4, the intersection point of vertical line L4 and the lower part of the cow's back contour is A4, and so on. n The intersection point with the upper part of the cow's back contour is a n , vertical line L n The intersection point with the lower part of the cow's back outline is A n ; In the left and right side image data of the cow, define the cow's head on the left and the tail on the right as the positive direction, identify the highest point of the cow's back and the lowest point of the cow's hoof, take the difference to get the cow's body height, and record it as L n+4 ; Calculate the area of the trapezoid formed by a1, a2, A1, A2, and record it as S1; calculate the area of the trapezoid formed by a2, a3, A2, A3, and record it as S2; calculate the area of the trapezoid formed by a3, a4, A3, A4, and record it as S3; and so on. n-1 , a n , A n-1 , A n The area of the trapezoid formed is recorded as S n-1 ; Calculate a n , a n+1 , A n , A n+1 The area of the trapezoid formed is recorded as S n ; Calculate the upper and lower horizontal tangents and vertical lines L1 and L2 at the maximum width of the cow's back contour n+1 The area of the rectangle enclosed by the intersection of the extended lines is recorded as S n+1 ; Step S33: Determine the comprehensive combination index of cattle body size parameters and establish a regression model for the comprehensive combination index and cattle weight prediction Determine the comprehensive combined index S of cattle body size parameters according to the following formula g : S g =S1+S2+S3+S4+…+S n +S n+1 *L n+4 ; Among them, n≥4; Comprehensive combination index S of cattle body size parameters based on a single picture g ; Calculate the comprehensive combined index S of cattle body size parameters of multiple pictures g The average value of The actual weight of the cow and S g The relationship between the average values of the predicted weight and the body size parameters of cattle was analyzed by regression analysis to establish a comprehensive combined index S g The regression model fitted between the mean values of The root mean square error of body weight was calculated using the actual body weight of k individual cattle and the predicted body weight of cattle to evaluate the performance of the regression model, k ≥ 16; If the RMS error of body weight is less than 20 kg, the prediction regression model is output for cattle weight prediction; In step S32, the machine vision algorithm is used to automatically complete the calculation and extraction of body size parameters throughout the entire process; The regression model fitted in step S33 is: Predicted cattle weight T (kg) = 11.15S g -36.96; The specific method for obtaining the image contour of the cow's upper back from the top perspective in step S31 is: Read the timestamp on the image of the cow in normal posture, and use the YOLOv8 algorithm to detect whether there is a background without interference within 5s to 20s before and after the time. If it exists, use the background as background image 1. If not, expand the search time range until background image 1 is found. At the same time, use image processing technology to extract the ground background color and automatically create a background image 2 containing less information. Subtract the background of the cow image in normal posture from background image 1 and background image 2 respectively, and then fuse the two background-subtracted images to obtain the final binary image. The Canny edge extraction algorithm is used to extract the edge of the binary image to obtain the edge contour image of the cow.
2. A non-contact cattle weight measurement method based on the target detection network model YOLOv8 as claimed in claim 1, characterized in that: The image acquisition device in step S11 and step S21 is an acquisition device with an uninterrupted power supply and a storage system; the video data of the upper back of the cow is collected by the acquisition device placed directly above the cowshed, the video data of the left and right sides of the cow is collected by the acquisition device placed on the side of the trough, and the video data of the individual identity of the cow is collected by the acquisition device placed directly above the cowshed and the acquisition device placed on the side of the trough; there are 3 to 8 cows in the cowshed, and the acquisition time is 7 to 14 days.
3. A non-contact cattle weight measurement method based on the target detection network model YOLOv8 as claimed in claim 1, characterized in that: In step S13, the cow posture categories are divided into normal and abnormal postures, and the cow posture category determination method is: if the angle between the cow's neck and trunk in the top view image of the cow's back does not exceed 5 degrees, then the posture is considered to be a normal posture, otherwise it is an abnormal posture; if the cow's four limbs are standing on the ground at the same time in the left and right side images of the cow, and the angle between the cow's front two hooves and the angle between the cow's rear two hooves do not exceed 5 degrees, then the posture is considered to be a normal posture, otherwise it is an abnormal posture.
4. A non-contact cattle weight measurement method based on the target detection network model YOLOv8 as claimed in claim 1, characterized in that: In step S14, the ratio of the number of data in the training set to that in the test set is 5-7:3-5.
5. A non-contact cattle weight measurement method based on the target detection network model YOLOv8 as claimed in claim 1, characterized in that: The information contained in the cattle individual identity image in step S23 is: determining the cattle individual identity by identifying the cattle head and neck features or identifying the cattle individual identity specific information; the marking cattle individual identity information is to number different cattle individuals for future use.
6. A non-contact cattle weight measurement method based on the target detection network model YOLOv8 as claimed in claim 1, characterized in that: In step S24, the ratio of the number of data in the training set to that in the test set is 5-7:3-5.
7. A non-contact cattle weight measurement method based on the target detection network model YOLOv8 as claimed in claim 1, characterized in that: The image acquisition device in step S3 is an acquisition device with an uninterrupted power supply and a storage system; the video data of the upper back of the cow is collected by the acquisition device placed directly above the cowshed, the video data of the left and right sides of the cow is collected by the acquisition device placed on the side of the trough, and the video data of the individual identity of the cow is collected by the acquisition device placed directly above the cowshed and the acquisition device placed on the side of the trough; there are 3 to 8 cows in the cowshed, and the acquisition time is 7 to 14 days.
8. A non-contact cattle weight measurement method based on the target detection network model YOLOv8 as claimed in claim 5, characterized in that: The cattle individual identity specific information includes tags, seals, colors, marks, and numbers on the cattle.
