Method for determining the weight and size of a pig

By using a structural adaptive coordinate system and radial distortion correction technology, the systematic deviation problem of pig weight and body size measurement methods under non-fixed viewing angles and lens distortion was solved, and stable and reliable body size and weight measurement was achieved.

CN122176759APending Publication Date: 2026-06-09SICHUAN AGRI UNIV

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SICHUAN AGRI UNIV
Filing Date
2026-05-12
Publication Date
2026-06-09

AI Technical Summary

Technical Problem

Existing methods for measuring pig weight and body size are difficult to achieve accurate measurements under non-fixed viewing angles and lens distortion conditions, leading to systematic biases. Furthermore, traditional methods rely on fixed camera positions and calibration plates, making them unsuitable for complex working conditions.

Method used

By employing a structural adaptive coordinate system and radial distortion correction technology, combined with straight segment detection and logarithmic domain observation, self-calibration is performed through the railing structure, reducing dependence on fixed camera positions and calibration plates, and maintaining the stability of scale conversion under lens distortion.

Benefits of technology

Stable body size and weight measurements were achieved under non-fixed viewing angle and lens distortion conditions, reducing systematic bias and improving measurement reliability and repeatability. Measurement quality was ensured through sparse anomaly modeling and uncertainty assessment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122176759A_ABST
    Figure CN122176759A_ABST
Patent Text Reader

Abstract

The application discloses a pig weight and body size measuring method, and belongs to the field of pig weight and body size measuring. The method comprises the following steps: collecting a back video above a cage scale and frame extraction to obtain a video frame set; constructing a structure adaptive coordinate corresponding to each video frame; initializing distortion parameters and scale parameters; performing body size measurement; if the distortion parameters and the scale parameters are converged, performing weight measurement, and calculating a weight uncertainty approximation and an abnormality proportion; if the weight uncertainty approximation or the abnormality proportion is greater than a corresponding threshold, performing re-measurement, otherwise, taking a segment-level body size and an observed weight of a current round as final pig body size and weight; if the distortion parameters or the scale parameters are not converged, sequentially updating the distortion parameters and the scale parameters, and returning to perform body size measurement again according to the updated distortion parameters and the scale parameters. The application solves the problems of scale calibration difficulty, unfixed visual angle and scale drift in the prior art, and the problems of systematic deviation of body size / weight.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of pig weight and body size measurement, and particularly relates to a method for measuring pig weight and body size. Background Technology

[0002] In 2D video of the back of a cage-like structure, the cage's frame is often not fully covered, rendering traditional corner calibration / homography calibration unusable. Furthermore, the actual acquisition angle is sometimes directly overhead, sometimes significantly oblique, and is not fixed, causing the assumptions of a "global constant" or "fixed-direction progressive scale field" to no longer apply to pixel-to-millimeter ratios. Simultaneously, the lens may exhibit radial distortion, causing straight structures such as railings to bend, further introducing systematic errors. Existing methods generally rely on complete calibration boards / depth / multi-viewpoints or fixed camera positions, which are difficult to adapt to the above-mentioned working conditions. Summary of the Invention

[0003] In view of the above-mentioned shortcomings in the prior art, the present invention provides a method for measuring pig weight and body size, which solves the problems of difficult scale calibration, inconsistent viewing angle and scale drift in the existing methods, resulting in systematic deviations in body size / weight.

[0004] To achieve the above-mentioned objectives, the technical solution adopted by this invention is: a method for measuring pig weight and body size, comprising: The video of the top back of the cage is captured and the frames are extracted to obtain a video frame set; Segmentation and detection are performed on each video frame in the video frame set to obtain the pig back mask and fence mask corresponding to each video frame; Based on the pig back mask and fence mask corresponding to each video frame, the fence direction is estimated using a straight line segment detection algorithm, and the adaptive coordinates of the structure corresponding to each video frame are constructed. Initialize distortion and scaling parameters; Volume scale calculation: Extract the railing edge point set of each video frame based on structural adaptive coordinates; remove distortion from the railing edge point set of each video frame according to the distortion parameters to obtain the structural point set of each video frame; calculate the logarithmic domain observation based on the structural point set and scale parameters of each video frame, and obtain the current scale mapping; obtain the frame-level volume scale and segment-level volume scale based on the current scale mapping. The loss function is calculated based on logarithmic domain observations, and the convergence of distortion parameters and scale parameters is determined based on the loss function. If convergence is achieved, the weight is calculated based on frame-level body size. Otherwise, the distortion parameters and scale parameters are updated sequentially, and the body size is recalculated based on the updated distortion parameters and scale parameters. The weight calculation is as follows: based on frame-level body size, frame-level weight observation is constructed using the integral moment of the width function; and the observed weight is obtained based on the frame-level weight observation; the weight uncertainty approximation and the abnormality ratio are calculated. If the weight uncertainty approximation or the abnormality ratio is greater than the corresponding threshold, a new video of the back of the cage is collected to remeasure the body size and weight; otherwise, the segment-level body size is used as the final pig body size, and the observed weight is used as the final pig weight.

[0005] The beneficial effects of this invention are as follows: Utilizing the railing structure as a measurement reference and constructing an adaptive coordinate system enables self-calibration for non-fixed viewpoints and scale drift, reducing reliance on fixed camera positions, calibration boards, or complete scene borders, and minimizing systematic deviations in body size / weight at the source. By incorporating radial distortion parameters and scale mapping into a unified optimization framework, and through joint correction using railing linearity constraints and dual-scale observation, the stability and repeatability of scale conversion can be maintained even under conditions of lens distortion and slight installation offset. At the body size end, a segment-level body size is formed using a width function and robust statistics, suppressing the impact of posture curvature, motion blur, and sporadic segmentation errors on the results. At the weight end, sparse anomaly modeling and uncertainty assessment are introduced, and retesting is triggered when anomalies / uncertainties exceed the threshold, achieving measurement quality self-checking and risk control, and improving the reliability of field applications.

[0006] Furthermore, the expression for the structural adaptive coordinates corresponding to each video frame is:

[0007]

[0008]

[0009] in, These are the coordinates along the railing direction in the structural adaptive coordinate system. for Normalized unit vector; For video frames The corresponding unit vector of the main direction of the railing; For video frames; For transpose; These are the pixel coordinates in the image coordinate system. The principal point of the image serves as the origin; The coordinates of the vertical railing direction in the structural adaptive coordinate system; for The normal unit vector obtained by rotating 90° clockwise; For video frames The Y-axis component of the corresponding main direction unit vector of the railing; For video frames The X-axis component of the corresponding main direction unit vector of the railing.

[0010] The beneficial effects of the above-mentioned further scheme are as follows: by projecting image points onto a structural coordinate system aligned with the main direction of the railing, the subsequent width measurement and scale modeling maintain a consistent reference direction under different camera positions and postures, reducing the inconsistency of direction caused by camera roll / tilt, thereby improving the stability and reproducibility of railing feature extraction and scale estimation.

[0011] Furthermore, the expression for the structure point set of each video frame is:

[0012]

[0013] in, These are the coordinates of the pixel after distortion correction; For the relative principal point of the distortion domain To translate the coordinates; The principal point of the image serves as the origin; The relative principal point of the pixel in the distortion domain To translate the coordinates; These are distortion parameters; This is the radius distance from the pixel in the distortion domain to the principal point; These are the coordinates of the distorted pixel. It is an L2 norm.

[0014] The beneficial effects of the above-mentioned further scheme are as follows: by using one-parameter radial distortion correction to uniformly map the edge points of the railing to the distortion correction domain, the railing is closer to a straight line in the distortion correction domain, thereby enhancing the usability of straight line fitting and point-to-line residuals, reducing the scale estimation bias caused by lens distortion, and improving adaptability under different lens / installation conditions.

[0015] Furthermore, the calculation of logarithmic domain observations based on the structural point set and scale parameters of each video frame, and the obtaining of the current scale mapping, specifically involves: Based on the structural point set of each video frame, the pixel width and pixel spacing of the railings in each video frame are measured, and the observation equations for the pixel width and pixel spacing in each video frame are established:

[0016]

[0017]

[0018] in, This represents the actual width of the railing; It is a scaling function; For video frames The corresponding pixel width of the railing; The coordinates are perpendicular to the railing direction; For pixel width observation noise; This represents the actual spacing between the railings; For video frames The corresponding pixel spacing of the railings; Pixel pitch observation noise; For the intercept term; The coefficient of the linear term; The coefficient of the quadratic term; Based on the pixel width observation equation and pixel spacing observation equation corresponding to each video frame, and according to a preset valid judgment criterion, a valid pixel width observation set is obtained from the video frame set. and effective pixel spacing observation set :

[0019] Observations on effective pixel width respectively and effective pixel spacing observation set Taking the logarithm of the pixel width observation equation and the pixel pitch observation equation for each effective video frame and applying additive noise approximation, we obtain the effective pixel width observation set. Logarithmic domain observations corresponding to each valid video frame and effective pixel spacing observation set Logarithmic domain observations corresponding to each valid video frame :

[0020]

[0021]

[0022] in, For the logarithmic domain observations corresponding to the railing width observations; It is a logarithmic function of the scale; For logarithmic domain noise; These are the logarithmic domain observations corresponding to the interval observations; For logarithmic domain noise; By parametrically fitting the logarithmic scaling function, we obtain the scaling parameters corresponding to the logarithmic function:

[0023] in, This is the intercept term corresponding to the logarithmic function; The coefficient of the linear term corresponding to the logarithmic function; The coefficients of the quadratic term corresponding to the logarithmic function; The current scale mapping is obtained based on the scale parameter corresponding to the logarithmic function.

[0024] The beneficial effects of the above-mentioned further scheme are as follows: by simultaneously introducing two types of scale observations, namely the actual width and the actual spacing of the railing, the observability of scale mapping is improved and the risk of degradation of a single observation is reduced; furthermore, multiplicative noise is approximately transformed into additive noise in the logarithmic domain, which makes it easier to obtain stable scale parameter estimates by using weighted least squares, so that scale drift can still be robustly solved under conditions such as occlusion and sharpness fluctuations.

[0025] Furthermore, the expression for the current scale mapping is:

[0026] in, This is the current scale mapping.

[0027] The beneficial effects of the above-mentioned further scheme are as follows: by representing the scale mapping as a continuous function of the coordinates along the vertical railing direction, the pixel scale difference at different cross-sectional positions can be compensated, and the scale factor can be guaranteed to be positive and change smoothly, thereby realizing the modeling and correction of spatial non-uniform scale drift and improving the consistency of body size conversion.

[0028] Furthermore, the expressions for obtaining the frame-level volume scale and the segment-level volume scale are as follows:

[0029]

[0030]

[0031]

[0032] in, For segmental body length; For video frame sets Find the median; For video frames Body length; The width is at the fragment level; For video frames Body width; For quantile operators; It is a function for pixel width; These are normalized parameters along the pig's body axis; The first on the central axis Normalized position parameters corresponding to each sampling point; The first on the central axis +1 normalized position parameters corresponding to sampling points; For video frames The first on the central axis +1 sampling point's two-dimensional coordinates; For video frames The first on the central axis Two-dimensional coordinates of each sampling point; To normalize the parameters along the pig's body axis Mapped to vertical railing direction coordinates The function; It is an L2 norm; For the index of discrete sampling points; The width of the cross-section is in pixels.

[0033] The beneficial effects of the above-mentioned further scheme are as follows: by obtaining the body length by integrating along the central axis and obtaining the body width by quantile statistics, and by using median fusion within the segment, the influence of pig body bending posture, local occlusion and individual abnormal frames on body size can be effectively suppressed; at the same time, the profiled description of the width function can make full use of shape information and improve the robustness and stability of body size estimation against segmentation noise.

[0034] Furthermore, the expression for the loss function is:

[0035]

[0036]

[0037] in, The loss function; It is a linear loss; This represents the loss from dual-scale observations. These are distortion parameters; This is the intercept term corresponding to the logarithmic function; The coefficient of the linear term corresponding to the logarithmic function; The coefficients of the quadratic term corresponding to the logarithmic function; For video frames; For railing index; For video frames No. The straight line obtained by fitting the root railing; For the pixel index after distortion removal from the structural point set; For pixels to the straight line orthogonal distance; For the first point in the structure point set Each pixel after distortion removal; The weighting coefficient for the observed width of the railing; The coordinates are perpendicular to the railing direction; The set of observations for effective pixel width; Observation weights for pixel width; for The logarithmic domain observations corresponding to the observations of the width of the lower railing; This is the weighting coefficient for the spacing observation width; This is the effective pixel spacing observation set; Pixel spacing observation weights; for The logarithmic domain observations corresponding to the spacing observations below.

[0038] The beneficial effects of the above-mentioned further scheme are as follows: by unifying the railing linearity loss and the dual-scale observation loss into the same objective function, and introducing weights and effective observation set screening for different frames / different observations, physical scale constraints can be used while ensuring geometric consistency, avoiding local optima or uncontrolled scale drift caused by relying on a single constraint, thereby improving the accuracy and stability of the joint estimation of distortion and scale.

[0039] Furthermore, the sequential updating of distortion parameters and scale parameters specifically involves: With the scale parameter fixed, a one-dimensional search is performed to find the distortion parameter values ​​that minimize the loss function, resulting in the updated distortion parameters. With the distortion parameters fixed, the scale parameters that minimize the loss function are obtained based on the closed-form solution, resulting in the updated scale parameters.

[0040] The beneficial effects of the above-mentioned further scheme are as follows: by adopting an alternating optimization strategy of "one-dimensional search for distortion parameters with fixed scale parameters + closed-loop solution to update scale parameters with fixed distortion parameters", the high-dimensional nonlinear joint optimization is decomposed into easily solvable subproblems, which not only improves computational efficiency but also facilitates convergence and stability; at the same time, the closed-loop solution update reduces the sensitivity to hyperparameters such as initial values ​​and learning rates, making it easier for engineering deployment.

[0041] Furthermore, the obtained observed body weight is specifically as follows: Based on the frame-level volume scale, frame-level volume observations are constructed using the integral moment of the width function:

[0042]

[0043] in, For video frames The constructed body weight observation; These are the regression coefficients; These are the regression coefficients; The frame-level volume length; These are the regression coefficients; It is a first-order integral moment characteristic; These are the regression coefficients; It is a second-order integral moment characteristic; For video frames Location The pixel width of the pig's body at that location; These are normalized positional parameters along the pig's body axis. right Perform robust modeling:

[0044] in, This is the estimated value of the true body weight at the fragment level; For video frames sparse anomaly offset terms; Gaussian observation noise; Assumptions regarding noise distribution; For video frames The observed variance; Based on robust modeling results and frame-level weight observations, the observed weight is obtained:

[0045]

[0046] in, It is the L1 canonical strength.

[0047] The beneficial effects of the above-mentioned further scheme are as follows: by constructing weight observation based on the integral moment of the width function, the weight representation is expanded from a single size to a shape distribution feature, which improves the ability to express individual differences; further, by introducing a sparse anomaly offset term into the frame-level weight observation and using L1 regularization to achieve soft threshold suppression, the influence of sparse interference frames such as railing obstruction and people entering the frame can be automatically weakened, thereby obtaining a more stable and interference-resistant observed weight.

[0048] Furthermore, the expressions for the approximate weight uncertainty and the anomaly ratio are as follows:

[0049]

[0050] in, This is an approximation of the uncertainty in body weight. For video frames The observed variance; This is an abnormal proportion; The number of frames participating in the fusion; This is an indicator function; it returns 1 if the condition is true, and 0 otherwise. For video frames The sparse anomaly offset term.

[0051] The beneficial effects of the above-mentioned further solutions are as follows: by providing quantitative indicators of the approximate uncertainty of weight and the proportion of anomalies, the measurement quality of the current segment can be self-assessed; when the uncertainty or the proportion of anomalies exceeds the threshold, a retest is triggered, which can avoid outputting low-confidence results in complex field environments, realize the "interpretable confidence + quality control" closed loop, and improve the reliability of the system in actual production applications. Attached Figure Description

[0052] Figure 1 This is a flowchart of the method of the present invention.

[0053] Figure 2 This is a diagram illustrating the simulation results of multi-frame segmentation and "robust fusion" of the present invention. Detailed Implementation

[0054] The specific embodiments of the present invention are described below to enable those skilled in the art to understand the present invention. However, it should be understood that the present invention is not limited to the scope of the specific embodiments. For those skilled in the art, various changes are obvious as long as they are within the spirit and scope of the present invention as defined and determined by the appended claims. All inventions utilizing the concept of the present invention are protected.

[0055] like Figure 1 As shown, in one embodiment of the present invention, a method for measuring the weight and body size of a pig includes: The video of the top back of the cage is captured and the frames are extracted to obtain a video frame set; Segmentation and detection are performed on each video frame in the video frame set to obtain the pig back mask and fence mask corresponding to each video frame; Based on the pig back mask and fence mask corresponding to each video frame, the fence direction is estimated using a straight line segment detection algorithm, and the adaptive coordinates of the structure corresponding to each video frame are constructed. Initialize distortion and scaling parameters; Volume scale calculation: Extract the railing edge point set of each video frame based on structural adaptive coordinates; remove distortion from the railing edge point set of each video frame according to the distortion parameters to obtain the structural point set of each video frame; calculate the logarithmic domain observation based on the structural point set and scale parameters of each video frame, and obtain the current scale mapping; obtain the frame-level volume scale and segment-level volume scale based on the current scale mapping. The loss function is calculated based on logarithmic domain observations, and the convergence of distortion parameters and scale parameters is determined based on the loss function. If convergence is achieved, the weight is calculated based on frame-level body size. Otherwise, the distortion parameters and scale parameters are updated sequentially, and the body size is recalculated based on the updated distortion parameters and scale parameters. The weight calculation is as follows: based on frame-level body size, frame-level weight observation is constructed using the integral moment of the width function; and the observed weight is obtained based on the frame-level weight observation; the weight uncertainty approximation and the abnormality ratio are calculated. If the weight uncertainty approximation or the abnormality ratio is greater than the corresponding threshold, a new video of the back of the cage is collected to remeasure the body size and weight; otherwise, the segment-level body size is used as the final pig body size, and the observed weight is used as the final pig weight.

[0056] In this embodiment, the present invention utilizes long-term existing and measurable structural elements in the cage as "metric evidence", changes the scale calibration from "border / calibration plate dependence" to "railing structure self-calibration", and simultaneously estimates them in a unified optimizable model.

[0057] The expression for the structural adaptive coordinates corresponding to each video frame is:

[0058]

[0059]

[0060] in, These are the coordinates along the railing direction in the structural adaptive coordinate system. for Normalized unit vector; For video frames The corresponding unit vector of the main direction of the railing; For video frames; For transpose; These are the pixel coordinates in the image coordinate system. The principal point of the image serves as the origin; The coordinates of the vertical railing direction in the structural adaptive coordinate system; for The normal unit vector obtained by rotating 90° clockwise; For video frames The Y-axis component of the corresponding main direction unit vector of the railing; For video frames The X-axis component of the corresponding main direction unit vector of the railing.

[0061] In this embodiment, the main direction of the railing is the dominant direction vector of the railing line segment in the current frame image coordinate system. Line segment detection (such as LSD / Hough) is performed using railing masks / edge points. The detected line segments are then clustered / statistically analyzed by principal direction (e.g., peak values ​​of direction histogram or first principal component of PCA) to obtain unit vectors.

[0062] In this embodiment, a structural adaptive coordinate system bound to the railing direction is proposed, so that the scale model can be used in different top / slant views.

[0063] For video frames From the railing cover Estimate the unit vector of the principal direction of the railing (or the set of points on the railing edge). (Can be obtained from Hough / LSD line segment statistics), construct an orthogonal basis. and ; Image principal point Let the origin be any pixel. Define the structure coordinates:

[0064] in, The "vertical railing direction coordinates" remain consistent with the cage-like structure across videos at different oblique angles, thus uniformly representing scale drift as... Avoid relying on fixed image rows / columns.

[0065] The expression for the structure point set of each video frame is:

[0066]

[0067] in, These are the coordinates of the pixel after distortion correction; For the relative principal point of the distortion domain To translate the coordinates; The principal point of the image serves as the origin; The relative principal point of the pixel in the distortion domain To translate the coordinates; These are distortion parameters; This is the radius distance from the pixel in the distortion domain to the principal point; These are the coordinates of the distorted pixel. It is an L2 norm.

[0068] In this embodiment, to eliminate structural bending errors caused by lens distortion, a one-parameter radial distortion correction mapping is used. Let the coordinates of the distorted pixels be... After distortion correction, it becomes ; These are parameters to be estimated. All subsequent railing straightness constraints and width / spacing measurements will be performed in the distortion-free domain.

[0069] The calculation of logarithmic domain observations based on the structural point set and scale parameters of each video frame, and the resulting current scale mapping, are as follows: Based on the structural point set of each video frame, the pixel width and pixel spacing of the railings in each video frame are measured, and the observation equations for the pixel width and pixel spacing in each video frame are established:

[0070]

[0071]

[0072] in, This represents the actual width of the railing; It is a scaling function; For video frames The corresponding pixel width of the railing; The coordinates are perpendicular to the railing direction; For pixel width observation noise; This represents the actual spacing between the railings; For video frames The corresponding pixel spacing of the railings; Pixel pitch observation noise; For the intercept term; The coefficient of the linear term; The coefficient of the quadratic term; Based on the pixel width observation equation and pixel spacing observation equation corresponding to each video frame, and according to a preset valid judgment criterion, a valid pixel width observation set is obtained from the video frame set. and effective pixel spacing observation set :

[0073] Observations on effective pixel width respectively and effective pixel spacing observation set Taking the logarithm of the pixel width observation equation and the pixel pitch observation equation for each effective video frame and applying additive noise approximation, we obtain the effective pixel width observation set. Logarithmic domain observations corresponding to each valid video frame and effective pixel spacing observation set Logarithmic domain observations corresponding to each valid video frame :

[0074]

[0075]

[0076] in, For the logarithmic domain observations corresponding to the railing width observations; It is a logarithmic function of the scale; For logarithmic domain noise; These are the logarithmic domain observations corresponding to the interval observations; For logarithmic domain noise; By parametrically fitting the logarithmic scaling function, we obtain the scaling parameters corresponding to the logarithmic function:

[0077] in, This is the intercept term corresponding to the logarithmic function; The coefficient of the linear term corresponding to the logarithmic function; The coefficients of the quadratic term corresponding to the logarithmic function; The current scale mapping is obtained based on the scale parameter corresponding to the logarithmic function.

[0078] In this embodiment, the effective pixel width observation set is obtained. and effective pixel spacing observation set In this case, whether a frame is valid can be determined by observation quality score + threshold screening. For width observation: a valid frame is one where the number / coverage of railing edge points meets the standard, the run-length distribution in the hurdle direction is stable (low variance / coefficient of variation), and the width consistency of multiple railings in the same frame is good; for spacing observation: a valid frame is one where a sufficient number of parallel railing lines can be detected, the adjacent spacing distribution is unimodal with low variance, and the point-to-line residual / RMS is small.

[0079] In this embodiment, the scale logarithmic function This facilitates the transformation of multiplicative scaling errors into additive residuals for weighted least squares estimation, while ensuring... >0.

[0080] In this embodiment, the actual width of the railing... Compared to the actual spacing (center-to-center distance between adjacent railings) It can be measured in mm in one go. In the distortion-free domain, and in structural coordinates... Measured for the independent variable: ①Pin width of railing (px): can be concealed by the railing membrane Robust statistics of the horizontal run-length of the location were obtained; ②Pinpoint spacing of railings (px): can be obtained from the projection peak spacing of the center line set of the railing or the distance between adjacent straight lines.

[0081] The expression for the current scale mapping is:

[0082] in, This is the current scale mapping.

[0083] In this embodiment, before each round of body size measurement / scale estimation begins, the scale function can have a set of known initial estimates (which may come from the results of the previous round or engineering default values), and the current round obtains a new estimate based on the current valid observations. , , This represents the scale parameter after this round of updates (which may differ from the initial value), used to update the scale mapping.

[0084] The expressions for obtaining frame-level and segment-level volume scales are as follows:

[0085]

[0086]

[0087]

[0088] in, For segmental body length; For video frame sets Find the median; For video frames Body length; The width is at the fragment level; For video frames Body width; For quantile operators; It is a function for pixel width; These are normalized parameters along the pig's body axis; The first on the central axis Normalized position parameters corresponding to each sampling point; The first on the central axis +1 normalized position parameters corresponding to sampling points; For video frames The first on the central axis +1 sampling point's two-dimensional coordinates; For video frames The first on the central axis Two-dimensional coordinates of each sampling point; To normalize the parameters along the pig's body axis Mapped to vertical railing direction coordinates The function; It is an L2 norm; For the index of discrete sampling points; The width of the cross-section is in pixels.

[0089] In this embodiment, instead of directly using area / bounding frame, a width function that varies with arc length parameter (posture de-bending) is constructed and combined with the previous self-correcting scale mapping to convert it into a millimeter scale.

[0090] An adaptive structural coordinate system, bound to the railing orientation, is proposed, allowing the scale model to be used across different top / bottom views. A pig back mask is obtained in the distortion-free domain. Extract the central axis ( (This is a normalized parameter for arc length), and the intersection of the normal profile at the central axis and the boundary is used to obtain the pixel width of the profile. (px). Mapping the profile points to structural coordinates yields... , converting to millimeters using scale mapping.

[0091] The expression for the loss function is:

[0092]

[0093]

[0094] in, The loss function; It is a linear loss; This represents the loss from dual-scale observations. These are distortion parameters; This is the intercept term corresponding to the logarithmic function; The coefficient of the linear term corresponding to the logarithmic function; The coefficients of the quadratic term corresponding to the logarithmic function; For video frames; For railing index; For video frames No. The straight line obtained by fitting the root railing; For the pixel index after distortion removal from the structural point set; For pixels to the straight line orthogonal distance; For the first point in the structure point set Each pixel after distortion removal; The weighting coefficient for the observed width of the railing; The coordinates are perpendicular to the railing direction; The set of observations for effective pixel width; Observation weights for pixel width; for The logarithmic domain observations corresponding to the observations of the width of the lower railing; This is the weighting coefficient for the spacing observation width; This is the effective pixel spacing observation set; Pixel spacing observation weights; for The logarithmic domain observations corresponding to the spacing observations below.

[0095] In this embodiment, Transforming "railway straightness" into a distortion parameter Optimizable constraints.

[0096] In this embodiment, The observation weights are determined by factors such as sharpness, occlusion rate, run-length variance, and linear fitting residuals.

[0097] The process of sequentially updating distortion parameters and scale parameters is as follows: With the scale parameter fixed, a one-dimensional search is performed to find the distortion parameter values ​​that minimize the loss function, resulting in the updated distortion parameters. With the distortion parameters fixed, the scale parameters that minimize the loss function are obtained based on the closed-form solution, resulting in the updated scale parameters.

[0098] In this embodiment, a stable solution can be achieved through alternating minimization: ① Fixed scale parameter: The remaining variable is a one-dimensional distortion parameter, which can be minimized using a grid search / golden section loss function (calculating the linear residual and scale residual each time).

[0099] ② Fixed distortion parameters: For the scale parameter, use weighted least squares, closed-form solution:

[0100] in, ; This is the concatenated weighted diagonal matrix; This is the spliced ​​observation vector.

[0101] The obtained observed body weight is specifically as follows: Based on the frame-level volume scale, frame-level volume observations are constructed using the integral moment of the width function:

[0102]

[0103] in, For video frames The constructed body weight observation; These are the regression coefficients; These are the regression coefficients; The frame-level volume length; These are the regression coefficients; It is a first-order integral moment characteristic; These are the regression coefficients; It is a second-order integral moment characteristic; For video frames Location The pixel width of the pig's body at that location; These are normalized positional parameters along the pig's body axis. right Perform robust modeling:

[0104] in, This is the estimated value of the true body weight at the fragment level; For video frames sparse anomaly offset terms; Gaussian observation noise; Assumptions regarding noise distribution; For video frames The observed variance; Based on robust modeling results and frame-level weight observations, the observed weight is obtained:

[0105]

[0106] in, It is the L1 canonical strength.

[0107] In this embodiment, the regression coefficient , , and Obtained through offline training; frame-level observation variance It can be estimated from the training residual model or mask quality index.

[0108] In this embodiment, the impact of on-camera interference / abnormal frames is modeled as a sparse offset. :

[0109] right Applying Laplace priors This yields the maximum posterior equivalence optimization:

[0110] Alternating minimization yields closed-form updates: ① Given Update outliers (soft thresholds):

[0111] ② Given Updated weight (minimum variance fusion):

[0112] The approximate expressions for the weight uncertainty and the anomaly ratio are as follows:

[0113]

[0114] in, This is an approximation of the uncertainty in body weight. For video frames The observed variance; This is an abnormal proportion; The number of frames participating in the fusion; This is an indicator function; it returns 1 if the condition is true, and 0 otherwise. For video frames The sparse anomaly offset term.

[0115] In this embodiment, real production videos may contain personnel or tools appearing in the frame, and factors such as occlusion, reflection, and railing adhesion may cause minor frame segmentation distortions, leading to abrupt changes in frame-level features. Simply using threshold removal or empirical weighting is insufficient to provide the optimal update formula, uncertainty, and retesting rules. This invention explicitly models "interference" as sparse outliers and derives a soft threshold anomaly correction and weighted closed-form fusion formula within a maximum a posteriori framework. This achieves "soft suppression" of the statistical significance of outlier frames while simultaneously outputting auditable uncertainty and retesting decisions.

[0116] In this embodiment, Figure 2 This diagram illustrates how the segmentation results of a pig are displayed when there is occlusion and pose changes in different video frames, and how the final fusion effect is visualized. Grayscale and texture are used to distinguish different semantic elements: highlighted white lines (diagonal stripes) represent reference railings used for scale conversion; light gray filled areas represent the pig segmentation mask; dark gray or black areas represent the background and obstacles (including foreground occlusion, non-target structures, and other railings). The weight values ​​in the diagram are simulated predictions, used to reflect the estimation fluctuations caused by occlusion and the stability after fusion.

[0117] D (Original Frames): Four original grayscale images (at different times, poses, and occlusion conditions) selected from the same video sequence, used to compare and display the appearance differences and occlusion degree of the input frames.

[0118] EH (Single Frame Result): The visualization result of 4 single-frame segmentation corresponding to AD. The figure shows the pig body segmentation mask (light gray) and the reference fence marker (highlighted line) overlaid, and the weight estimate of the frame is marked to illustrate that the estimate will fluctuate with occlusion and pose changes under single-frame conditions.

[0119] I (Fusion Result): Example of output after robust multi-frame fusion. The figure retains the pig body segmentation mask, reference fence markers, and fused weight labels to demonstrate that the fused result is more stable and has stronger resistance to occlusion.

[0120] Figure 2 This is a simulation diagram used to display the results; in the actual system, the reference railing and obstacle areas are automatically detected and segmented by the algorithm on the original video frames, and used for scale conversion and multi-frame robust fusion calculation.

Claims

1. A method for measuring the weight and body size of pigs, characterized in that, include: The video of the top back of the cage is captured and the frames are extracted to obtain a video frame set; Segmentation and detection are performed on each video frame in the video frame set to obtain the pig back mask and fence mask corresponding to each video frame; Based on the pig back mask and fence mask corresponding to each video frame, the fence direction is estimated using a straight line segment detection algorithm, and the adaptive coordinates of the structure corresponding to each video frame are constructed. Initialize distortion and scaling parameters; Volume scale calculation: Extract the railing edge point set of each video frame based on structural adaptive coordinates; remove distortion from the railing edge point set of each video frame according to the distortion parameters to obtain the structural point set of each video frame; calculate the logarithmic domain observation based on the structural point set and scale parameters of each video frame, and obtain the current scale mapping; obtain the frame-level volume scale and segment-level volume scale based on the current scale mapping. The loss function is calculated based on logarithmic domain observations, and the convergence of distortion parameters and scale parameters is determined based on the loss function. If convergence is achieved, the weight is calculated based on frame-level body size. Otherwise, the distortion parameters and scale parameters are updated sequentially, and the body size is recalculated based on the updated distortion parameters and scale parameters. The weight measurement is based on frame-level body size and uses the integral moment of the width function to construct frame-level weight observation. The observed weight is obtained based on frame-level weight observations; Calculate the approximate weight uncertainty and the abnormal proportion. If the approximate weight uncertainty or the abnormal proportion is greater than the corresponding threshold, return to collect a new video of the back of the cage scale for remeasurement of body size and weight. Otherwise, use the segment-level body size as the final pig body size and the observed weight as the final pig weight.

2. The method for measuring pig weight and body size according to claim 1, characterized in that, The expression for the structural adaptive coordinates corresponding to each video frame is: in, These are the coordinates along the railing direction in the structural adaptive coordinate system. for Normalized unit vector; For video frames The corresponding unit vector of the main direction of the railing; For video frames; For transpose; These are the pixel coordinates in the image coordinate system. The principal point of the image serves as the origin; The coordinates of the vertical railing direction in the structural adaptive coordinate system; for The normal unit vector obtained by rotating 90° clockwise; For video frames The Y-axis component of the corresponding main direction unit vector of the railing; For video frames The X-axis component of the corresponding main direction unit vector of the railing.

3. The method for measuring pig weight and body size according to claim 1, characterized in that, The expression for the structure point set of each video frame is: in, These are the coordinates of the pixel after distortion correction; For the relative principal point of the distortion domain To translate the coordinates; The principal point of the image serves as the origin; The relative principal point of the pixel in the distortion domain To translate the coordinates; These are distortion parameters; This is the radius distance from the pixel in the distortion domain to the principal point; These are the coordinates of the distorted pixel. It is an L2 norm.

4. The method for measuring pig weight and body size according to claim 1, characterized in that, The calculation of logarithmic domain observations based on the structural point set and scale parameters of each video frame, and the resulting current scale mapping, are as follows: Based on the structural point set of each video frame, the pixel width and pixel spacing of the railings in each video frame are measured, and the observation equations for the pixel width and pixel spacing in each video frame are established: in, This represents the actual width of the railing; It is a scaling function; For video frames The corresponding pixel width of the railing; The coordinates are perpendicular to the railing direction; For pixel width observation noise; This represents the actual spacing between the railings; For video frames The corresponding pixel spacing of the railings; Pixel pitch observation noise; For the intercept term; The coefficient of the linear term; The coefficient of the quadratic term; Based on the pixel width observation equation and pixel spacing observation equation corresponding to each video frame, and according to a preset valid judgment criterion, a valid pixel width observation set is obtained from the video frame set. and effective pixel spacing observation set : Observations on effective pixel width respectively and effective pixel spacing observation set Taking the logarithm of the pixel width observation equation and the pixel pitch observation equation for each effective video frame and applying additive noise approximation, we obtain the effective pixel width observation set. Logarithmic domain observations corresponding to each valid video frame and effective pixel spacing observation set Logarithmic domain observations corresponding to each valid video frame : in, For the logarithmic domain observations corresponding to the railing width observations; It is a logarithmic function of the scale; For logarithmic domain noise; These are the logarithmic domain observations corresponding to the interval observations; For logarithmic domain noise; By parametrically fitting the logarithmic scaling function, we obtain the scaling parameters corresponding to the logarithmic function: in, This is the intercept term corresponding to the logarithmic function; The coefficient of the linear term corresponding to the logarithmic function; The coefficients of the quadratic term corresponding to the logarithmic function; The current scale mapping is obtained based on the scale parameter corresponding to the logarithmic function.

5. The method for measuring pig weight and body size according to claim 4, characterized in that, The expression for the current scale mapping is: in, This is the current scale mapping.

6. The method for measuring pig weight and body size according to claim 1, characterized in that, The expressions for obtaining frame-level and segment-level volume scales are as follows: in, For segmental body length; For video frame sets Find the median; For video frames Body length; The width is at the fragment level; For video frames Body width; For quantile operators; It is a function for pixel width; These are normalized parameters along the pig's body axis; The first on the central axis Normalized position parameters corresponding to each sampling point; The first on the central axis +1 normalized position parameters corresponding to sampling points; For video frames The first on the central axis +1 sampling point's two-dimensional coordinates; For video frames The first on the central axis Two-dimensional coordinates of each sampling point; To normalize the parameters along the pig's body axis Mapped to vertical railing direction coordinates The function; It is an L2 norm; For the index of discrete sampling points; The width of the cross-section is in pixels.

7. The method for measuring pig weight and body size according to claim 1, characterized in that, The expression for the loss function is: in, The loss function; It is a linear loss; This represents the loss from dual-scale observations. These are distortion parameters; This is the intercept term corresponding to the logarithmic function; The coefficient of the linear term corresponding to the logarithmic function; The coefficients of the quadratic term corresponding to the logarithmic function; For video frames; For railing index; For video frames No. The straight line obtained by fitting the root railing; For the pixel index after distortion removal from the structural point set; For pixels to the straight line orthogonal distance; For the first point in the structure point set Each pixel after distortion removal; The weighting coefficient for the observed width of the railing; The coordinates are perpendicular to the railing direction; The set of observations for effective pixel width; Observation weights for pixel width; for The logarithmic domain observations corresponding to the observations of the width of the lower railing; This is the weighting coefficient for the spacing observation width; This is the effective pixel spacing observation set; Pixel spacing observation weights; for The logarithmic domain observations corresponding to the spacing observations below.

8. The method for measuring pig weight and body size according to claim 1, characterized in that, The process of sequentially updating distortion parameters and scale parameters is as follows: With the scale parameter fixed, a one-dimensional search is performed to find the distortion parameter values ​​that minimize the loss function, resulting in the updated distortion parameters. With the distortion parameters fixed, the scale parameters that minimize the loss function are obtained based on the closed-form solution, resulting in the updated scale parameters.

9. The method for measuring pig weight and body size according to claim 1, characterized in that, The obtained observed body weight is specifically as follows: Based on the frame-level volume scale, frame-level volume observations are constructed using the integral moment of the width function: in, For video frames The constructed body weight observation; These are the regression coefficients; These are the regression coefficients; The frame-level volume length; These are the regression coefficients; It is a first-order integral moment characteristic; These are the regression coefficients; It is a second-order integral moment characteristic; For video frames Location The pixel width of the pig's body at that location; These are normalized positional parameters along the pig's body axis. right Perform robust modeling: in, This is the estimated value of the true body weight at the fragment level; For video frames sparse anomaly offset terms; Gaussian observation noise; Assumptions regarding noise distribution; For video frames The observed variance; Based on robust modeling results and frame-level weight observations, the observed weight is obtained: in, It is the L1 canonical strength.

10. The method for measuring pig weight and body size according to claim 1, characterized in that, The approximate expressions for the weight uncertainty and the anomaly ratio are as follows: in, This is an approximation of the uncertainty in body weight. For video frames The observed variance; This is an abnormal proportion; The number of frames participating in the fusion; This is an indicator function; it returns 1 if the condition is true, and 0 otherwise. For video frames The sparse anomaly offset term.