Live pig weight detection method and system based on back image recognition
By extracting eigenvalues such as shoulder width, hip width and abdominal width from the pig back images, and using convolutional neural network model for analysis and fitting, the problem of low accuracy of pig weight estimation in the prior art is solved, and higher estimation accuracy and better fault tolerance are achieved.
Patent Information
- Application Number
- CN202510660726.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-22
- Publication Date
- 2025-06-20
- Estimated Expiration
- 2045-05-22
AI Technical Summary
In the prior art, the accuracy of pig weight estimation is low, and it is impossible to effectively capture individual differences in pigs, resulting in large errors in weight estimation.
Eigenvalues such as shoulder width, hip width and abdominal width were extracted from the pig's back images, and the convolutional neural network model was used for analysis and fitting, and the pig's body weight was estimated.
It improves the accuracy of pig weight estimation, enhances the fault tolerance of non-ideal images, and adapts to different image acquisition conditions.
Smart Images

Figure CN120183003A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of pig breeding management, and specifically relates to a method and system for detecting pig weight based on back image recognition. Background Art
[0002] The weight of pigs is a key decision-making indicator in pig breeding, and is of great significance for disease early warning and treatment, nutritional status assessment, precise feeding, and slaughter decision-making. Traditional manual weighing methods have problems such as high stress, low efficiency, and high manual labor intensity, and are difficult to adapt to large-scale pig breeding.
[0003] In the prior art, computer vision has been used to estimate pig weight. For example, in the non-contact pig weight measurement method, system, electronic device and storage medium with the patent application number CN202310509165.0, weight characteristic parameters such as the body width of the pig are identified from the top-down depth image of the pig, and the weight characteristic parameters are input into a pre-trained AdaBoost regression model to estimate the pig weight.
[0004] Although this method can achieve non-contact measurement of pig weight, it uses the short side length of the minimum bounding rectangle in the back area as a unified body width index, resulting in the loss of the body shape structure characteristics of the pig and increasing the weight estimation error. For example, pigs with wide shoulders usually have well-developed muscles, and in fattening pigs, the abdominal width is used to reflect the fat content. When the short side lengths of the corresponding minimum bounding rectangles are the same or similar, the weight estimation model is likely to regard the two as the same input, reducing the accuracy of weight estimation.
[0005] Therefore, there is an urgent need for a method and system for estimating pig weight to solve the technical problem of low accuracy of pig weight estimation in the prior art. Summary of the Invention
[0006] The present invention provides a method and system for detecting pig weight based on back image recognition. By identifying and extracting the body size information of pigs from the back image, and using a convolutional neural network model to analyze and fit the body size information of pigs to estimate the pig weight, the purpose of increasing the proportion of effective images in a single captured image is achieved under the condition of realizing automatic pig weight estimation.
[0007] According to the first aspect of the present invention, the present invention claims a method for detecting pig weight based on back image recognition, including: Extracting the back area from the initial back image of the target pig to obtain the target back image; Extracting the eigenvalue of the target back image to obtain the target feature; Obtaining the target weight according to the output of the weight prediction model based on the target feature; The eigenvalue includes shoulder width, hip width and abdominal width, and the eigenvalue extraction method includes: Construct a coordinate system for the target back image and calculate the centroid coordinates of the back region; Construct the minimum bounding rectangle of the back region, draw a line parallel to the short side of the minimum bounding rectangle through the centroid to obtain a reference line; the reference line divides the back region into an upper region and a lower region; In the upper region and the lower region, respectively retrieve the maximum feature line parallel to the reference line and with the maximum distance between the two intersection points with the back contour; obtain the shoulder width according to the maximum distance between the corresponding intersection points in the upper region; obtain the hip width according to the maximum distance between the corresponding intersection points in the lower region; Obtain the abdominal region according to the back region between the maximum feature line in the lower region and the reference line; In the abdominal region, retrieve the minimum feature line parallel to the reference line and with the minimum distance between the two intersection points with the back contour, and obtain the abdominal width according to the distance between the intersection points of the minimum feature line and the back contour.
[0008] In an embodiment of the present application, the number of initial back images is greater than 1, and the method further includes: Respectively obtain the corresponding image confidence according to the confidence of the upper region, the confidence of the abdominal region and the confidence of the tail region corresponding to each initial back image; the tail region confidence is obtained according to the confidence of the region other than the abdominal region in the lower region; Respectively input the target features of each initial back image into the body weight prediction model to obtain the corresponding reference body weight; Calculate the target body weight according to the image confidence and reference body weight of all initial back images.
[0009] In an embodiment of the present application, the confidence includes a curvature component, and the method further includes: Respectively calculate the centroid coordinates of the upper region, the abdominal region and the tail region; Construct a line connecting the centroid of the upper region and the centroid of the tail region to obtain a first feature line; Construct a line connecting the centroid of the upper region and the centroid of the abdominal region to obtain a second feature line; Construct a line connecting the centroid of the tail region and the centroid of the abdominal region to obtain a third feature line; Obtain the curvature component of the upper region according to the included angle between the first feature line and the second feature line; Obtain the curvature component of the tail region according to the included angle between the first feature line and the third feature line; Obtain the curvature component of the abdominal region according to the included angle between the second feature line and the third feature line.
[0010] In an embodiment of the present application, the confidence level further includes an occlusion component, and the confidence level is further obtained by linearly weighting and calculating the curvature component and the occlusion component according to a preset weight.
[0011] In an embodiment of the present application, the method further includes: identifying key points corresponding to the target live pig in each of the initial back images; obtaining the target key point type and the corresponding number of key points according to the key point identification result; if the target key point type includes all preset key point types and 2 key points are identified for each type, setting the occlusion components corresponding to the upper region, the abdominal region, and the tail region of the corresponding initial back image to a preset maximum value; the preset key point types include shoulder key points, abdominal key points, and hip key points.
[0012] In an embodiment of the present application, the method further includes: setting the occlusion component of the image region corresponding to the preset key point type with 0 key points in the key point identification result to a preset minimum value; setting the occlusion component of the image region corresponding to the preset key point type with 2 key points in the key point identification result to a preset maximum value, and setting the occlusion component of the image region corresponding to the preset key point type with 1 key point in the key point identification result to a preset intermediate value.
[0013] In an embodiment of the present application, the weight prediction model is constructed and trained according to a support vector regression model.
[0014] According to the second aspect of the present invention, the present invention claims protection for a live pig weight detection system based on back image recognition, including: An image acquisition module: extracting a back region from an initial back image of a target live pig to obtain a target back image; A feature extraction module: extracting feature values of the target back image to obtain target features; the feature values include shoulder width, hip width, and abdominal width, and the feature extraction module includes: Constructing a coordinate system in the target back image and calculating the centroid coordinates of the back region; Constructing a minimum bounding rectangle of the back region, and constructing a line parallel to the short side of the minimum bounding rectangle through the centroid to obtain a reference line; the reference line divides the back region into an upper region and a lower region; In the upper region and the lower region, respectively retrieving the maximum feature line parallel to the reference line and having the maximum distance between two intersection points with the back contour; obtaining the shoulder width according to the maximum distance between the intersection points corresponding to the upper region; obtaining the hip width according to the maximum distance between the intersection points corresponding to the lower region; Obtaining the abdominal region according to the back region between the maximum feature line of the lower region and the reference line; Retrieve the minimum feature line parallel to the reference line in the abdominal region, with the minimum distance between the two intersection points with the back contour, and obtain the abdominal width based on the distance between the intersection points of the minimum feature line and the back contour. Weight prediction module: Obtain the target weight according to the output of the target feature in the weight prediction model.
[0015] In an embodiment of the present application, the number of initial back images is greater than 1, and the system further includes a confidence acquisition module: respectively obtain the corresponding image confidence according to the confidence of the upper region, the abdominal region, and the tail region corresponding to each initial back image; the tail region confidence is obtained according to the confidence of the region other than the abdominal region in the lower region. The weight prediction module also inputs the target feature of each initial back image into the weight prediction model respectively to obtain the corresponding reference weight; calculate the target weight according to the image confidence and the reference weight of all initial back images.
[0016] In an embodiment of the present application, the confidence includes a curvature component, and the confidence acquisition module further includes a curvature acquisition sub-module, and the curvature acquisition sub-module includes: Calculate the centroid coordinates of the upper region, the abdominal region, and the tail region respectively. Construct a line connecting the centroid of the upper region and the centroid of the tail region to obtain the first feature line. Construct a line connecting the centroid of the upper region and the centroid of the abdominal region to obtain the second feature line. Construct a line connecting the centroid of the tail region and the centroid of the abdominal region to obtain the third feature line. Obtain the curvature component of the upper region according to the included angle between the first feature line and the second feature line. Obtain the curvature component of the tail region according to the included angle between the first feature line and the third feature line. Obtain the curvature component of the abdominal region according to the included angle between the second feature line and the third feature line.
[0017] In an embodiment of the present application, the confidence acquisition module further includes an occlusion acquisition sub-module, and the confidence acquisition module further performs a linear weighted calculation on the output of the curvature acquisition sub-module and the output of the occlusion acquisition sub-module according to a preset weight.
[0018] In an embodiment of the present application, the occlusion acquisition sub-module further includes: identifying key points corresponding to the target live pig in each of the initial back images; obtaining the target key point type and the corresponding number of key points according to the key point recognition result; if the target key point type includes all preset key point types and 2 key points are recognized for each type, setting the occlusion degree components corresponding to the upper region, abdominal region, and tail region of the corresponding initial back image to the preset maximum value; the preset key point types include shoulder key points, abdominal key points, and hip key points.
[0019] In an embodiment of the present application, the occlusion acquisition sub-module further includes: setting the occlusion degree component of the image region corresponding to the preset key point type with 0 key points in the key point recognition result to the preset minimum value; setting the occlusion degree component of the image region corresponding to the preset key point type with 2 key points in the key point recognition result to the preset maximum value, and setting the occlusion degree component of the image region corresponding to the preset key point type with 1 key point in the key point recognition result to the preset intermediate value.
[0020] In an embodiment of the present application, the weight prediction model is constructed and trained according to the support vector regression model.
[0021] The present application has the following beneficial effects: 1. By extracting the shoulder width feature, abdominal body width feature, and hip width feature of the live pig from the back image of the live pig, the individual differences of different live pigs can be effectively captured. The target features accurately depict the development of the shoulders, abdomen, and hips of the target live pig, enabling the weight prediction model to deeply explore the correlation between the development of the shoulders, abdomen, and hips of the live pig and the weight, and improving the accuracy of the weight prediction model.
[0022] 2. When estimating the weight, by extracting the eigenvalue of multiple initial back images of the same target live pig, using the output of each eigenvalue in the weight prediction model as a reference for the estimated weight of the target live pig, and correcting the output result of the corresponding weight prediction model according to the image confidence of different regions in different initial images, the final target weight can be stably predicted, enhancing the recognition fault tolerance ability for non-ideal images. Especially when it is difficult to obtain an ideal back image of the target live pig, the accuracy of the weight estimation result of the target live pig is improved to adapt to different image acquisition conditions in the actual application scenario.
[0023] 3. According to the centroid of the upper region, the centroid of the abdominal region, and the centroid of the hip region, it can be quickly determined whether the target live pig has local bending. For example, when the live pig is walking in a straight line, due to the restriction of the head and neck, the swing range of the shoulders of the live pig is smaller than the swing range of the hips. Therefore, the confidence of the upper region is higher than the confidence of the abdominal region. This method not only has low judgment complexity, but also is less affected by image noise and has strong interpretability, effectively reducing the impact of local bending on the overall weight estimation.
[0024] 4. Use the recognition results of the key points on the shoulders, abdomen, and hips of the target live pig as the basis for judging whether there is occlusion. Under the condition that it conforms to the operation mechanism of the weight prediction model, reduce the probability that the image is misjudged as an invalid image due to the presence of only non-critical parts such as the tail, legs, and ears, and improve the utilization rate of the collected images.
[0025] 5. Construct a weight prediction model based on the SVR model. During the training process, by introducing positive example slack variables and negative example slack variables into the loss function, use the preset error threshold ε to assist the model to maintain the overall prediction stability in the face of small sample errors or outliers. The regularization term in the loss function also reduces the probability of the model overfitting, and expands the adaptability of different scales of live pig breeding scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The accompanying drawings here are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present disclosure, and are used together with the specification to explain the principles of the present disclosure.
[0027] Figure 1 It is a flowchart of a live pig weight detection method based on back image recognition according to an embodiment of the present application; Figure 2 It is a schematic diagram of target feature extraction according to an embodiment of the present application; Figure 3 It is a schematic diagram of the extraction of the curvature of the back region according to an embodiment of the present application; Figure 4 It is a schematic diagram of the structure of a live pig weight detection system based on back image recognition according to an embodiment of the present application; Figure 5 It is a schematic diagram of the structure of an electronic device according to an embodiment of the present application; Reference signs in the drawings: C - centroid, l0 - reference line, l1 - first maximum feature line, l2 - second maximum feature line, l3 - minimum feature line, E1 - first intersection point, E2 - second intersection point, A1 - third intersection point, A2 - fourth intersection point, B1 - fifth intersection point, B2 - sixth intersection point, C1 - centroid of the upper region, C2 - centroid of the abdominal region, C3 - centroid of the tail region, α1 - angle between the line connecting the centroid of the upper region and the centroid of the tail region and the line connecting the centroid of the upper region and the centroid of the abdominal region, α2 - angle between the line connecting the centroid of the upper region and the centroid of the tail region and the line connecting the centroid of the tail region and the centroid of the abdominal region, α3 - angle between the line connecting the centroid of the upper region and the centroid of the abdominal region and the line connecting the centroid of the tail region and the centroid of the abdominal region. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0028] The present invention provides a method and system for detecting the weight of live pigs based on back image recognition. To make the above objects, features, and advantages of the present application more obvious and understandable, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Usually, the components of the embodiments of the present application described and illustrated herein can be arranged and designed in various different configurations. Therefore, referring to terms such as "one embodiment", "some embodiments", "implementation manners", "embodiments", "schematic embodiments", "examples", "specific examples", or "some examples", etc., the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the present application to be protected, but only represents that the specific features, structures, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present invention. Moreover, the specific features, structures, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative efforts belong to the scope of protection of the present application.
[0029] It should be noted that similar reference numerals and letters denote similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of the present application, relational terms such as "first", "second", etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations.
[0030] According to the first aspect of the present invention, the present invention claims a method for detecting the weight of live pigs based on back image recognition. Referring to the attached Figure 1 figures, it includes: S1: By pre-setting a camera above the target pigsty area, the lens axis is perpendicular to the horizontal plane, the imaging plane covers the target recognition area, and the camera focuses on the target pigsty area. At a preset moment, the back image of the target live pig is collected.
[0031] It should be noted that the target pigsty area includes the movable area of the live pigs, such as the pigsty area, the aisle area between pigsties, etc. The target recognition area is not less than the minimum area that can completely collect a complete back image. In the initial back image, there may be only the back image of 1 live pig, or there may be the back images of multiple live pigs at the same time.
[0032] S2: Preprocess the collected back image of the target live pig to obtain the initial back image.
[0033] In this embodiment, the preprocessing includes grayscale processing, noise removal, contrast enhancement, and perspective transformation, although it is not limited thereto. The grayscale processing is used to convert the captured back image into a grayscale image to obtain the first back image. The noise removal is used to remove the image noise of the first back image to obtain the second back image. For example, the median filtering algorithm is used to remove salt-and-pepper noise, and the grayscale value of each pixel point in the first back image is replaced with the median of the grayscale values of the neighboring pixel points, so as to remove the noise while retaining the edge and detail information of the pig's back image and reducing the risk of blurring of key features such as hair texture. The contrast enhancement is used to enhance the contrast of the second back image to obtain the initial back image. For example, the adaptive histogram equalization algorithm is used to process the second back image, and the mapping relationship is dynamically adjusted according to the grayscale distribution of different regions of the second back image to reduce the influence of uneven illumination on the image recognition result.
[0034] It should be noted that the perspective transformation is used to convert the back image of the target pig into a top view. The perspective transformation matrix can be calculated by the getPerspectiveTransform function in OpenCV, and the image can be converted into a top view according to the perspective transformation matrix by using the warpPerspective function.
[0035] S3: Extract the back region from the initial back image of the target pig to obtain the target back image.
[0036] In this embodiment, step S3 further includes the following sub-steps: S31. Identify the region where the target pig is located in the initial back image to obtain the third back image. The initial back image is input into an image segmentation model to obtain the region where the target pig is located in the initial back image. The image segmentation model can be constructed by the threshold segmentation method, or based on a convolutional neural network model, or constructed by other feasible methods. S32. Screen the back region of the target pig from the third back image to obtain the target back image.
[0037] It should be noted that when there are images of multiple pigs in the initial back image at the same time, step S31 further includes determining the position of the target pig in the initial back image to obtain the region where the target pig is located. For example, the position of the target pig in the initial back image can be located by the target tracking algorithm, or the target pig can be located with the assistance of an ear tag, or it can be manually located, or other feasible methods.
[0038] It should be noted that the third back image includes the head, body, and tail of the target live pig. The area where the body is located is screened out from the third back image to obtain the target back image. Step S32 further includes the following sub-steps: S321. Perform morphological opening operation on the third back image to remove the protruding parts of the head and tail. S322. Apply morphological erosion operation to erode the third back image after removing the head and tail to remove interference information such as hair on the edge of the back contour. S323. Use dilation operation to fill the third back image after erosion processing. The dilation operation is used to repair the holes that appear during the erosion operation. S324. Based on the initial back image, set the pixel points in the corresponding area of the third back image obtained after the dilation operation to white, and the remaining parts to black, to obtain the binary image of the back of the target live pig, that is, the target back image.
[0039] S4: Extract the feature values of the target back image to obtain target features.
[0040] In this embodiment, step S4 further includes the following sub-steps: S41. Establish a coordinate system in the fourth back image. S42. Calculate the target features respectively according to the coordinate system.
[0041] It should be noted that when constructing the coordinate system, any pixel point in the target back image can be used as the origin of the coordinate system. After presetting the positive direction of the x-axis and the positive direction of the y-axis, the coordinates of each pixel point can be determined.
[0042] It should be noted that the feature values include shoulder width, hip width, and abdominal width, and of course, it can be not limited to this.
[0043] In this embodiment, the feature values are area, perimeter, body length, hip width, abdominal width, shoulder width, and the curvature of the posture. Step S42 further includes: S421. Count the number of pixel points in the white area as the area. S422. Obtain the back contour of the target live pig according to the white area, calculate the distances between adjacent points in the back contour respectively, and calculate the perimeter according to the sum of the distances between all adjacent points. S423. Construct the minimum circumscribed rectangle of the white area in the target back image. The minimum circumscribed rectangle is a rectangle that can completely contain the white area and has the smallest area. S424. Take the length of the major axis of the minimum circumscribed rectangle as the body length. S425. Calculate the centroid coordinates of the white area in the target back image. Denote the centroid as C, and the centroid coordinates as (C x , C y ), that is, the abscissa of the centroid is C x , and the ordinate is C yThe target back image can be input into the moments function of OpenCV to output the centroid coordinates. S426: Construct a line parallel to the short side of the minimum circumscribed rectangle through the centroid to obtain a reference line. The reference line divides the back region into an upper region and a lower region. The upper region is the region where the scapula of the target live pig is located. The lower region is the region where the abdomen and buttocks of the target live pig are located. Classification marking can be performed manually, or based on a neural network model for the two regions, or other feasible methods. S427: Obtain the shoulder width from the upper region, and obtain the hip width and the abdominal width from the lower region. S428: Perform an ellipse fitting operation on the back contour to obtain a target ellipse; calculate the eccentricity of the target ellipse to obtain the curvature, so as to measure the bending degree of the posture of the target live pig. For the same live pig, the closer the eccentricity is to 0, the greater the bending degree of the posture of the corresponding target live pig.
[0044] It should be noted that the ellipse fitting of the back contour can be performed according to the least squares method. Taking the fitEllipse function in OpenCV as an example, the construction of the target ellipse will be described. Input the positions of all pixel points of the back contour into the fitEllipse function, and calculate the eccentricity, that is, the bending degree component of the posture, according to the major axis length and minor axis length output by the fitEllipse function. The calculation method of the eccentricity E includes: ; where a represents half of the major axis length of the target ellipse, that is, the semi-major axis length; b represents half of the minor axis length of the target ellipse, that is, the semi-minor axis length.
[0045] It should be noted that step S428 further includes the following sub-steps: S4281: Retrieve the maximum feature line parallel to the reference line in the upper region and with the maximum distance between the two intersection points with the back contour to obtain the first maximum feature line. Obtain the shoulder width according to the distance between the corresponding intersection points of the first maximum feature line and the back contour. S4282: Retrieve the maximum feature line parallel to the reference line in the lower region and with the maximum distance between the two intersection points with the back contour to obtain the second maximum feature line. Obtain the hip width according to the distance between the corresponding intersection points of the second maximum feature line and the back contour. S4283: Obtain the abdominal region according to the back region between the second maximum feature line and the reference line. S4284: Retrieve the minimum feature line parallel to the reference line in the abdominal region and with the minimum distance between the two intersection points with the back contour, and obtain the abdominal width according to the distance between the intersection points of the minimum feature line and the back contour.
[0046] In this embodiment, referring to the appendix Figure 2As shown, place the target back image in the first quadrant of the coordinate system. Take the lower left corner pixel point of the target back image as the origin of the coordinate system, with the positive x-axis direction horizontally to the right and the positive y-axis direction vertically upward. The position of each pixel point is represented by integer coordinates. The expression of the reference line l0 is y = C y , the first maximum feature line is l1, the second maximum feature line is l2, and the minimum feature line is l3. Among them, the first maximum feature line l1 intersects the back contour at the first intersection point E1 and the second intersection point E2, the second maximum feature line l2 intersects the back contour at the third intersection point A1 and the fourth intersection point A2, and the minimum feature line l3 intersects the back contour at the fifth intersection point B1 and the sixth intersection point B2. Denote the coordinates of the first intersection point E1 as (x e1 , y e ), the coordinates of the second intersection point E2 as (x e2 , y e ), the coordinates of the third intersection point A1 as (x a1 , y a ), the coordinates of the fourth intersection point A2 as (x a2 , y a ), the coordinates of the fifth intersection point B1 as (x b1 , y b ), and the coordinates of the sixth intersection point B2 as (x b2 , y b ). Thus, it can be known that the shoulder width is equal to |x e1 - x e2 |, the hip width is equal to |x a1 - x a2 |, and the abdominal width is equal to |x b1 - x b2 |.
[0047] S5: Input the target feature into the weight prediction model to obtain the target weight of the target live pig.
[0048] It should be noted that the sample back images and corresponding actual weights of the sample live pigs in the farm are collected in advance. The collected sample back images are expanded by increasing or decreasing different light intensities, rotating, etc. to obtain the training image set of the weight prediction model. Perform the operations of the above steps S2 - S4 on each training image in the training image set respectively to obtain the corresponding training features. The training features of all images and the corresponding actual weights constitute the training data set of the weight prediction model.
[0049] It should be noted that the weight prediction model is constructed based on the Support Vector Regression (hereinafter referred to as SVR) model. The weight prediction model f can be expressed as: ; Among them, x represents the target feature; ω represents the weight vector of the target feature; b represents the bias term; φ represents a kernel function that maps the target feature to a high-dimensional feature space, such as a linear kernel function, a polynomial kernel function, and a sigmoid kernel function, etc.
[0050] In this embodiment, the loss function O of the weight prediction model can be expressed as: ; ; ; Among them, RT represents the regularization term, which controls the complexity of the model by minimizing the L2 norm of the weight vector ω; C represents the preset penalty parameter, and the larger the value of the preset penalty parameter, the more severe the penalty for the prediction error; represents the positive example slack variable of sample i, that is, the error when the predicted value is lower than the actual value; represents the negative example slack variable of sample i, that is, the error when the predicted value is higher than the actual value. Only when the prediction error exceeds the preset error threshold ε, the positive example slack variable and the negative example slack variable will be greater than 0, otherwise, their values are 0. n represents the number of samples.
[0051] It should be noted that in the actual breeding process, although the image acquisition process is standardized, due to factors such as individual posture differences, occlusion, and illumination, the collected images may have a certain degree of deviation or outliers. In the training process of the SVR model, by introducing positive example slack variables and negative example slack variables into the loss function, and using the preset error threshold ε to assist the model to maintain the overall prediction stability in the face of small sample errors or outliers. The regularization term in the loss function also reduces the probability of the model overfitting, expanding the adaptability of different scales of pig breeding scenarios.
[0052] It should be noted that the coefficient of determination, mean absolute error, and mean square error are used as performance evaluation indicators of the weight prediction model, and the grid search and cross-validation methods are used to optimize the selection of model hyperparameters, compare the model performances of different hyperparameter value combinations, and select the model with the optimal performance as the final weight prediction model.
[0053] In this embodiment, by extracting the shoulder width feature, abdominal body width feature, and hip width feature of the pig from the back image of the pig, the individual differences of different pigs can be effectively captured. The target feature accurately depicts the development of the shoulders, abdomen, and hips of the target pig, enabling the weight prediction model to deeply explore the correlation between the development of the shoulders, abdomen, and hips of the pig and the weight, and improving the accuracy of the weight prediction model.
[0054] In addition, the shoulder width, abdominal body width, and hip width are finely adjusted by eccentricity to improve the ability of the body weight prediction model to identify non-uniform changes in different parts and the ability to supplement errors when the live pig has a posture bend, thereby improving the prediction accuracy of the body weight prediction model.
[0055] In a feasible implementation, the number of initial back images is greater than 1, and the method further includes obtaining the image confidence of each initial back image, and calculating the target body weight according to the body weight prediction result corresponding to each initial back image and the image confidence.
[0056] In this implementation, the confidence of the upper region, the confidence of the abdominal region, and the confidence of the tail region corresponding to each initial back image are obtained respectively, and the image confidence is obtained according to the confidence of the upper region, the confidence of the abdominal region, and the confidence of the tail region of the same initial back image. The target features of each initial back image are respectively input into the body weight prediction model to obtain the corresponding reference body weight. The target body weight is calculated according to the image confidence and the reference body weight of all initial back images.
[0057] It should be noted that the tail region is the region other than the abdominal region in the lower region.
[0058] It should be noted that the confidence is obtained according to the reliability of the features extracted from this image region for estimating the body weight of the live pig. For example, the clarity, occlusion degree, and deformation degree of the region image of the corresponding image region. When calculating the image confidence of each initial back image, weights can be set according to the importance of the upper region, the abdominal region, and the tail region, and the image confidence is calculated by linearly weighting the confidence of the upper region, the confidence of the abdominal region, and the confidence of the tail region.
[0059] It should be noted that the value range of the confidence is [0, 1]. That is, when the value of the confidence is 0, it means that the features of this image region cannot be used to estimate the body weight of the live pig, and when the value of the confidence is about 1, it means that the reliability of the features of this image region for estimating the body weight of the live pig is greater.
[0060] In this implementation, the weight values corresponding to the confidence of the upper region, the confidence of the abdominal region, and the confidence of the tail region are all 1, that is, the image confidence is the sum of the confidence of the upper region, the confidence of the abdominal region, and the confidence of the tail region. The calculation method of the target body weight W includes: ; where m represents the number of initial back images, c j represents the image confidence corresponding to the j-th initial back image, and w j represents the reference body weight corresponding to the j-th initial back image.
[0061] It should be noted that when estimating the weight, the eigenvalue extraction is performed on multiple initial back images of the same target live pig, and the output of each eigenvalue in the weight prediction model is used as a reference for the estimated weight of the target live pig. The output results of the corresponding weight prediction model are corrected according to the image confidence degrees of different regions in different initial images, so as to stably predict the final target weight, enhance the recognition fault tolerance ability for non-ideal images, especially when it is difficult to obtain an ideal back image of the target live pig, the accuracy of the weight estimation result of the target live pig is improved to adapt to different image acquisition conditions in the actual application scenario. For example, the image clarity of the upper region in the first initial back image is poor, and there is occlusion in the tail region of the second initial back image.
[0062] In this embodiment, the confidence degree includes a curvature component and an occlusion component, and of course, it may not be limited to this. The confidence degree of the upper region can be obtained by linearly weighting and calculating the curvature component and the occlusion component according to a preset weight. The confidence degrees of the abdominal region and the tail region are similar to this and will not be described in detail here.
[0063] In this embodiment, when the curvature of the upper region of the target live pig is larger, it indicates that the probability of error between the shoulder width extracted in the upper region and the actual situation is larger, and the reliability of using the shoulder width extracted in the upper region to estimate the weight of the live pig is lower. Correspondingly, when calculating the confidence degree, a curvature component with a smaller value is adopted. When the curvature of the upper region of the target live pig is smaller, it indicates that the probability of error between the shoulder width extracted in the upper region and the actual situation is smaller, and the reliability of using the shoulder width extracted in the upper region to estimate the weight of the live pig is higher. Correspondingly, when calculating the confidence degree, a curvature component with a higher value is adopted.
[0064] In this embodiment, referring to the appendix Figure 3 As shown, the method further includes: calculating the centroid coordinates of the upper region, and recording the coordinates of the centroid C1 as (C 1x , C 1y ). Calculating the centroid coordinates of the abdominal region, and recording the coordinates of the centroid C2 as (C 2x , C 2y ). Calculating the centroid coordinates of the tail region, and recording the coordinates of the centroid C3 as (C 3x , C 3yConstruct the line connecting the centroid of the upper region and the centroid of the tail region to obtain the first feature line l4. Construct the line connecting the centroid of the upper region and the centroid of the abdominal region to obtain the second feature line l5. Construct the line connecting the centroid of the tail region and the centroid of the abdominal region to obtain the third feature line l6. Obtain the curvature component of the upper region according to the angle α1 between the first feature line l4 and the second feature line l5. Obtain the curvature component of the tail region according to the angle α2 between the first feature line l4 and the third feature line l6. Obtain the curvature component of the abdominal region according to the angle α3 between the second feature line l5 and the third feature line l6.
[0065] It should be noted that the first feature line l4 is used to describe the overall back posture of the target live pig, and the second feature line l5 is used to describe the shoulder back posture of the target live pig. When the value of the angle α1 between the two is larger, it indicates that the shoulder curvature of the target live pig is larger, and a smaller curvature component value is correspondingly adopted; when the value of the angle α1 between the two is smaller, it indicates that the shoulder curvature of the target live pig is smaller, and a larger curvature component value is correspondingly adopted. The third feature line l6 is used to describe the overall back posture of the target live pig. When the value of the angle α2 is larger, it indicates that the hip curvature of the target live pig is larger, and a smaller curvature component value is correspondingly adopted; when the value of the angle α2 is smaller, it indicates that the hip curvature of the target live pig is smaller, and a larger curvature component value is correspondingly adopted. When the value of the angle α3 is larger, it indicates that the abdominal curvature of the target live pig is smaller, and a larger curvature component value is correspondingly adopted; when the value of the angle α3 is smaller, it indicates that the abdominal curvature of the target live pig is larger, and a smaller curvature component value is correspondingly adopted. When and only when the first feature line l4, the second feature line l5, and the third feature line l6 coincide, there is no curvature in the posture of the target live pig.
[0066] It should be noted that according to the centroid of the upper region, the centroid of the abdominal region, and the centroid of the hip region, it can be quickly determined whether there is local curvature in the target live pig. For example, when the live pig is walking in a straight line, due to the restriction of the head and neck, the swing range of the shoulder of the live pig is smaller than the swing range of the hip. Therefore, the confidence level of the upper region is higher than that of the abdominal region. This method not only has a low judgment complexity but also is less affected by image noise.
[0067] It should be noted that for an image region with a greater degree of occlusion, a smaller value of the occlusion degree component is correspondingly adopted, and for an image region with a greater degree of occlusion, a smaller value of the occlusion degree component is correspondingly adopted. The occlusion degree component can judge whether there is occlusion through image recognition methods such as whether the contour region is connected, judging whether there is a sudden change in the edge based on contour analysis, and judging whether there is a color sudden change in the contour boundary based on optical flow, etc. If there is occlusion, it indicates that the probability of error in the live pig weight estimated according to this image increases, and the occlusion degree component of the corresponding image can be set to 0. If there is no occlusion, the occlusion degree component of the corresponding image can be set to 1.
[0068] In this embodiment, the method further includes identifying the bone key points corresponding to the target live pigs in each of the initial back images through a neural network model. The occlusion component is obtained according to the bone key point type and the number of corresponding types. The preset types of the bone key points include shoulder key points, abdominal key points, and hip key points, and of course, it may not be limited to this.
[0069] It should be noted that the value range of the occlusion component can be set in advance. For example, the preset minimum value is set to 0, the preset maximum value is set to 1, and the preset intermediate value is set to 0.5.
[0070] In a feasible embodiment, if the image recognition result includes all preset types and the number of bone key points corresponding to each type is 2, the corresponding image is regarded as not occluded, and the occlusion components in the upper region, abdominal region, and tail region of the corresponding image are all set to the preset maximum value, that is, the value is 1; if the number of bone key points of the preset type in the image recognition result is less than 2, the corresponding image is regarded as occluded, and the occlusion components in the upper region, abdominal region, and tail region of the corresponding image are all set to the preset minimum value, that is, the value is 0.
[0071] In another feasible embodiment, if the image recognition result includes all preset types and the number of bone key points corresponding to each type is 2, the corresponding image is regarded as not occluded, and the occlusion components in the upper region, abdominal region, and tail region of the corresponding image are all set to the preset maximum value, that is, the value is 1. If the number of bone key points of the preset type in the image recognition result is less than 2, the corresponding image is regarded as occluded, the occlusion component of the region where the preset type with the number of bone key points less than 2 in the recognition result is located is set to the preset minimum value, that is, the value is 0, and the occlusion component of the region where the preset type with the number of bone key points equal to 2 in the recognition result is located is set to the preset maximum value, that is, the value is 1.
[0072] It should be noted that when the weight prediction model estimates the weight of the target live pig, the source of feature extraction is the back image of the target live pig. Since the back of the live pig is flat and wide, and the image is mainly taken from above the pigsty in a top-down view, when the back image of the target live pig is occluded, it is mainly occluded by other live pigs from the side, and the occluded parts are concentrated on the edge of the back image, and there are very few occlusions that change the connectivity of the back image. Using the recognition results of the shoulder key points, abdominal key points, and hip key points of the target live pig as the judgment basis for whether there is occlusion, under the condition that it conforms to the operation mechanism of the weight prediction model, it reduces the probability that the image is misjudged as an invalid image due to the presence of occlusions in only non-critical parts such as the tail, legs, and ears, and improves the utilization rate of the collected images.
[0073] In another feasible embodiment, if the image recognition result includes all preset types and the number of skeletal key points corresponding to each type is 2, the corresponding image is regarded as not occluded, and the occlusion degree components in the upper region, abdominal region, and tail region of the corresponding image are all set to the preset maximum value, that is, the value is 1. If the number of skeletal key points of a preset type in the image recognition result is less than 2, the corresponding image is regarded as occluded. The occlusion degree component of the region where the preset type with the number of skeletal key points equal to 0 in the recognition result is set to the preset minimum value, that is, the value is 0; the occlusion degree component of the region where the preset type with the number of skeletal key points equal to 1 in the recognition result is set to the preset intermediate value, that is, the value is 0.5; and the occlusion degree component of the region where the preset type with the number of skeletal key points equal to 2 in the recognition result is set to the preset maximum value, that is, the value is 0.
[0074] It should be noted that, for example, if the neural network model recognizes 2 shoulder key points in the initial back image, the occlusion degree component of the upper region corresponding to the initial back image is set to 1; if the neural network model recognizes 1 abdominal key point in the initial back image, the occlusion degree component of the abdominal region corresponding to the initial back image is set to 0.5; if the neural network model does not recognize hip key points in the initial back image, the occlusion degree component of the tail region corresponding to the initial back image is set to 0.
[0075] According to the second aspect of the present invention, the present invention claims a live pig weight detection system based on back image recognition. Referring to the attached Figure 4 As shown, it includes: Image acquisition module: Extract the back region from the initial back image of the target live pig to obtain the target back image; Feature extraction module: Extract the feature values of the target back image to obtain the target features; the feature values include shoulder width, hip width, and abdominal width. The feature extraction module includes: Construct a coordinate system in the target back image and calculate the centroid coordinates of the back region; Construct the minimum bounding rectangle of the back region, and draw a line parallel to the short side of the minimum bounding rectangle through the centroid to obtain the reference line; the reference line divides the back region into an upper region and a lower region; In the upper region and the lower region, respectively retrieve the maximum feature line parallel to the reference line and with the maximum distance between the two intersection points with the back contour; obtain the shoulder width according to the maximum distance between the intersection points corresponding to the upper region; obtain the hip width according to the maximum distance between the intersection points corresponding to the lower region; Obtain the abdominal region according to the back region between the maximum feature line in the lower region and the reference line; Retrieve the minimum feature line parallel to the reference line in the abdominal region and with the minimum distance between the two intersection points with the back contour, and obtain the abdominal width based on the distance between the intersection points of the minimum feature line and the back contour. Weight prediction module: Obtain the target weight according to the output of the target feature in the weight prediction model.
[0076] In a feasible implementation, the number of initial back images is greater than 1, and the system further includes a confidence acquisition module: respectively obtain the corresponding image confidence according to the confidence of the upper region, the confidence of the abdominal region, and the confidence of the tail region corresponding to each initial back image; the tail region confidence is obtained according to the confidence of the region other than the abdominal region in the lower region. The weight prediction module also inputs the target feature of each initial back image into the weight prediction model respectively to obtain the corresponding reference weight; calculate the target weight according to the image confidence and reference weight of all initial back images.
[0077] In a feasible implementation, the confidence includes a curvature component, and the confidence acquisition module further includes a curvature acquisition sub-module, and the curvature acquisition sub-module includes: Calculate the centroid coordinates of the upper region, the abdominal region, and the tail region respectively. Construct a line connecting the centroid of the upper region and the centroid of the tail region to obtain the first feature line. Construct a line connecting the centroid of the upper region and the centroid of the abdominal region to obtain the second feature line. Construct a line connecting the centroid of the tail region and the centroid of the abdominal region to obtain the third feature line. Obtain the curvature component of the upper region according to the angle between the first feature line and the second feature line. Obtain the curvature component of the tail region according to the angle between the first feature line and the third feature line. Obtain the curvature component of the abdominal region according to the angle between the second feature line and the third feature line.
[0078] In a feasible implementation, the confidence acquisition module further includes an occlusion acquisition sub-module, and the confidence acquisition module further performs a linear weighted calculation on the output of the curvature acquisition sub-module and the output of the occlusion acquisition sub-module according to a preset weight.
[0079] In a feasible implementation, the occlusion acquisition sub-module further includes: identifying key points corresponding to the target live pigs in each of the initial back images; obtaining the target key point types and the corresponding number of key points according to the key point identification results; if the target key point types include all the preset key point types and 2 key points are identified for each type, setting the occlusion degree components corresponding to the upper region, abdominal region, and tail region of the corresponding initial back image to the preset maximum value; the preset key point types include shoulder key points, abdominal key points, and hip key points.
[0080] In a feasible implementation, the occlusion acquisition sub-module further includes: setting the occlusion degree component of the image region corresponding to the preset key point type with 0 key points in the key point identification results to the preset minimum value; setting the occlusion degree component of the image region corresponding to the preset key point type with 2 key points in the key point identification results to the preset maximum value, and setting the occlusion degree component of the image region corresponding to the preset key point type with 1 key point in the key point identification results to the preset intermediate value.
[0081] In a feasible implementation, the weight prediction model is constructed and trained based on a support vector regression model.
[0082] Refer to the attached Figure 5 As shown in the figure, an embodiment of the present application provides an electronic device, including: a processor and a memory. The processor and the memory are interconnected and communicate with each other through a communication bus and / or other forms of connection mechanisms (not marked). The memory stores a computer program executable by the processor. When the computing device runs, the processor executes the computer program to execute the system in any optional implementation manner of the above embodiments.
[0083] An embodiment of the present application provides a storage medium. When the computer program is executed by the processor, it executes the system in any optional implementation manner of the above embodiments. Among them, the storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (abbreviated as SRAM), electrically erasable programmable read-only memory (abbreviated as EEPROM), erasable programmable read-only memory (abbreviated as EPROM), programmable read-only memory (abbreviated as PROM), read-only memory (abbreviated as ROM), magnetic memory, flash memory, a magnetic disk, or an optical disc.
[0084] In the embodiments provided in the present application, it should be understood that the disclosed system can be implemented in other ways. The system embodiments described above are only illustrative. For example, the division of the modules is only a logical function division. In actual implementation, there can be other division methods. For another example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the couplings, direct couplings, or communication connections shown or discussed between each other can be through some communication interfaces. The indirect couplings or communication connections of the systems or units can be in electrical, mechanical, or other forms.
[0085] In addition, the units described as separate components may or may not be physically separated. The components shown as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0086] Furthermore, the functional modules in each embodiment of the present application can be integrated together to form an independent part, or each module can exist alone, or two or more modules can be integrated to form an independent part.
[0087] Flowcharts are used herein to illustrate the steps of the methods of the embodiments of the present disclosure. It should be understood that the previous or subsequent steps do not necessarily need to be carried out precisely in order. On the contrary, they can be carried out in reverse order or evaluated simultaneously. At the same time, other operations can also be added to these processes.
[0088] Unless otherwise defined, all terms used herein have the same meaning as commonly understood by those of ordinary skill in the art to which this disclosure belongs. It should also be understood that terms such as those defined in a general dictionary should be interpreted as having a meaning consistent with their meaning in the context of the relevant art, and should not be interpreted in an idealized or overly formal sense, unless specifically defined as such herein.
[0089] The above has introduced in detail a method and system for detecting the weight of live pigs based on back image recognition. Specific examples are used herein to elaborate on the principles and implementation manners of the present application. The descriptions of the above embodiments are only the embodiments of the present application, and are only used to help understand a method and system for detecting the weight of live pigs based on back image recognition of the present application, and do not limit the protection scope of the present application; at the same time, for those skilled in the art, the present application can have various changes and modifications. Any modification and equivalent replacement made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method for detecting the weight of live pigs based on back image recognition, characterized in that, Including: Extract the back region from the initial back image of the target live pig to obtain the target back image; Extract the eigenvalue of the target back image to obtain the target feature; Obtain the target weight according to the output of the weight prediction model based on the target feature; The eigenvalues include shoulder width, hip width, and abdominal width, and the eigenvalue extraction method includes: Construct a coordinate system in the target back image and calculate the centroid coordinates of the back region; Construct the minimum bounding rectangle of the back region, and construct a line parallel to the short side of the minimum bounding rectangle passing through the centroid to obtain the reference line; the reference line divides the back region into an upper region and a lower region; In the upper region and the lower region, respectively retrieve the maximum feature line parallel to the reference line and with the maximum distance between the two intersection points with the back contour; obtain the shoulder width according to the maximum distance between the corresponding intersection points in the upper region; obtain the hip width according to the maximum distance between the corresponding intersection points in the lower region; Obtain the abdominal region according to the back region between the maximum feature line in the lower region and the reference line; Retrieve the minimum feature line parallel to the reference line and with the minimum distance between the two intersection points with the back contour in the abdominal region, and obtain the abdominal width according to the distance between the intersection points of the minimum feature line and the back contour.
2. The method for detecting the weight of live pigs based on back image recognition according to claim 1, characterized in that, The number of initial back images is greater than 1, and the method further includes: Obtain the corresponding image confidence according to the confidence of the upper region, the confidence of the abdominal region, and the confidence of the tail region corresponding to each initial back image respectively; the confidence of the tail region is obtained according to the confidence of the region other than the abdominal region in the lower region; Input the target feature of each initial back image into the weight prediction model respectively to obtain the corresponding reference weight; Calculate the target weight according to the image confidence and the reference weight of all initial back images.
3. The method for detecting the weight of live pigs based on back image recognition according to claim 2, characterized in that, The confidence includes a curvature component, and the method further includes: Calculate the centroid coordinates of the upper region, the abdominal region, and the tail region respectively; Construct a line connecting the centroid of the upper region and the centroid of the tail region to obtain the first feature line; Construct a line connecting the centroid of the upper region and the centroid of the abdominal region to obtain the second feature line; Construct a line connecting the centroid of the tail region and the centroid of the abdominal region to obtain the third feature line; Obtain the curvature component of the upper region according to the included angle between the first feature line and the second feature line; Obtain the curvature component of the tail region according to the included angle between the first feature line and the third feature line; Obtain the curvature component of the abdominal region according to the included angle between the second feature line and the third feature line.
4. The method for detecting the weight of live pigs based on back image recognition according to claim 3, characterized in that, The confidence further includes an occlusion component, and the confidence is also obtained by linearly weighting the curvature component and the occlusion component according to a preset weight.
5. The method for detecting the weight of live pigs based on back image recognition according to claim 4, characterized in that, The method further includes: identifying the key points corresponding to the target live pig in each initial back image; obtaining the target key point type and the corresponding number of key points according to the key point recognition result; if the target key point type includes all preset key point types and 2 key points are recognized for each type, set the occlusion components corresponding to the upper region, the abdominal region, and the tail region of the corresponding initial back image to the preset maximum value; the preset key point types include shoulder key points, abdominal key points, and hip key points.
6. The method for detecting the weight of live pigs based on back image recognition according to claim 5, characterized in that, The method further includes: setting the occlusion degree component of the image region corresponding to the preset key point type with 0 key points in the key point recognition result to a preset minimum value; setting the occlusion degree component of the image region corresponding to the preset key point type with 2 key points in the key point recognition result to a preset maximum value, and setting the occlusion degree component of the image region corresponding to the preset key point type with 1 key point in the key point recognition result to a preset intermediate value.
7. The method for detecting the weight of live pigs based on back image recognition according to any one of claims 1-6, characterized in that, The weight prediction model is constructed and trained according to a support vector regression model.
8. A system for detecting the weight of live pigs based on back image recognition, characterized in that, It includes: An image acquisition module: extracting a back region from an initial back image of a target live pig to obtain a target back image; A feature extraction module: extracting feature values of the target back image to obtain target features; The feature values include shoulder width, hip width, and abdominal width, and the feature extraction module includes: Constructing a coordinate system in the target back image and calculating the centroid coordinates of the back region; Constructing a minimum bounding rectangle of the back region, and constructing a straight line parallel to the short side of the minimum bounding rectangle through the centroid to obtain a reference line; the reference line divides the back region into an upper region and a lower region; In the upper region and the lower region, respectively retrieving the maximum feature line parallel to the reference line and with the maximum distance between the two intersection points with the back contour; obtaining the shoulder width according to the maximum distance between the corresponding intersection points in the upper region; obtaining the hip width according to the maximum distance between the corresponding intersection points in the lower region; Obtaining an abdominal region according to the back region between the maximum feature line in the lower region and the reference line; Retrieving the minimum feature line parallel to the reference line and with the minimum distance between the two intersection points with the back contour in the abdominal region, and obtaining the abdominal width according to the distance between the intersection points of the minimum feature line and the back contour; A weight prediction module: obtaining the target weight according to the output of the weight prediction model based on the target features.
Citation Information
Patent Citations
Non-contact body weight measurement method and system for live pigs, electronic equipment and storage medium
CN116485823A
Livestock weight estimation method, device and equipment and computer readable storage medium
CN111243005A
Construction method of live pig body composition prediction model based on machine vision and machine learning
CN118097364A
Non-contact body weight measuring method based on two-dimensional pig contour image information
CN119360040A
Method and device for providing animal entity status information based on image
US20240358002A1
Cited By
Sow hip region image processing method and system based on computer vision
CN120452026A