A method and device for measuring the body size of a buffalo based on a monocular camera and a medium
By using a monocular camera-based method to measure the body size of buffaloes, and employing Vision Transformer networks and multi-scale depth estimation, a non-contact and accurate measurement of the body size of buffaloes in the Binlang River was achieved. This method solves the problems of expensive equipment and large errors in traditional measurement methods, and improves measurement efficiency and accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SOUTHWEST FORESTRY UNIVERSITY
- Filing Date
- 2025-11-11
- Publication Date
- 2026-04-21
AI Technical Summary
Existing methods for measuring the body size of buffalo are not suitable for the Binlangjiang buffalo, and traditional measurement methods require expensive equipment and are prone to measurement errors, which affect population spread and the protection of germplasm resources.
A monocular camera-based body size measurement method was adopted. Image data was acquired and preprocessed, and the Vision Transformer feature extraction network was used to extract global features of the bovine body, identify key feature points, and convert them into three-dimensional world coordinates through multi-scale depth estimation and camera calibration. Finally, parameters such as body height, cross height, body oblique length, chest circumference and abdominal circumference were calculated.
This method enables non-contact and precise measurement of buffalo body size, improves the accuracy of feature point identification and depth information estimation, avoids stress reactions and safety hazards, enhances measurement efficiency, and provides technical support for germplasm resource protection.
Smart Images

Figure CN121120754B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of body size measurement of water buffalo in Binlangjiang, specifically to a method, device, and medium for measuring the body size of water buffalo based on a monocular camera. Background Technology
[0002] Long-term closed breeding and acclimatization have resulted in the Binlangjiang water buffalo having a strong adaptability to the specific ecological environment of its production area. However, its low level of selective breeding has limited the spread and growth of the population. Currently, it is mainly produced in the upper reaches of the Binlangjiang River in Tengchong, Yunnan Province, with scattered distribution in various townships throughout the county. The current population is only slightly over 4,000 head, a relatively small number. To ensure the sustainable development of animal husbandry and maintain the genetic resources of the Binlangjiang buffalo, conservation efforts are crucial.
[0003] Currently, with the development of computer vision and deep learning, non-contact measurement methods have emerged, using LiDAR to collect point cloud data or multi-camera data for 3D reconstruction. However, these methods require expensive equipment and complex installation and debugging. Furthermore, the Binlangjiang water buffalo is entirely blackish-gray, making existing measurement methods difficult to apply and prone to significant measurement errors. Summary of the Invention
[0004] In view of the above problems, the present invention provides a method, device and medium for measuring the body size of buffalo based on a monocular camera.
[0005] To achieve the above objectives, in a first aspect, this application provides a method for measuring the body size of a buffalo based on a monocular camera, comprising:
[0006] The raw image data acquired by the monocular camera is obtained, and the raw image data is preprocessed to obtain a standardized image. The preprocessing includes size adjustment and image filling.
[0007] The standardized image is input into the Vision Transformer feature extraction network, and global features of the cow are extracted through block embedding and multi-head attention mechanism to generate a global feature map of the cow.
[0008] Based on the global feature map of the bovine body, point identification was performed to obtain feature points, including the highest point of the withers, the cruciate point, the anterior edge of the shoulder, the posterior edge of the ischial tuberosity, the posterior edge of the withers, the thoracic base point, the lumbar vertebra point, the abdominal base point, and the ground plane point. The pixel coordinates of each feature point were obtained by Gaussian heatmap regression.
[0009] Multi-scale depth estimation is performed on the global feature map of the bovine body. Multiple feature layers with different resolutions are extracted, and the depth information estimation image is output after channel adjustment, feature recombination and fusion.
[0010] Image is estimated based on the pixel coordinates and depth information of feature points, and the two-dimensional pixel coordinates are converted into three-dimensional world coordinates through camera calibration parameters;
[0011] Based on three-dimensional world coordinates, body size parameters are calculated, including body height, cross height, body oblique length, chest circumference, and abdominal circumference. Body height is the vertical distance between the highest point of the withers and the ground plane. Cross height is the vertical distance between the cross point and the ground plane. Body oblique length is the straight-line distance between the anterior edge of the shoulder and the posterior edge of the ischial tuberosity. Chest circumference is the circumference enclosed by the posterior edge of the withers and the base of the chest. Abdominal circumference is the circumference enclosed by the lumbar vertebra and the abdominal base.
[0012] Output measurement results including body size parameters.
[0013] In some embodiments, raw image data acquired by a monocular camera is obtained, and the raw image data is preprocessed to obtain a standardized image. The preprocessing includes resizing and image padding, including:
[0014] The original image data is scaled to a target size of 518×518 pixels using bilinear interpolation.
[0015] The scaled image is then symmetrically filled while maintaining the aspect ratio of the cow's body to obtain the first filled image.
[0016] The pixel values of the first filled image are converted to the [0,1] interval by normalization processing to obtain the second filled image;
[0017] The second filled image is divided into blocks, resulting in 37×37 image blocks;
[0018] Each image patch is flattened into a 1024-dimensional vector and positional encoding is added to obtain the initial normalized image;
[0019] CLS classification markers are added before the initial normalized image to form a normalized image of 1370×1024.
[0020] In some embodiments, a standardized image is input into a Vision Transformer feature extraction network, and global features of the bovine body are extracted through block embedding and multi-head attention mechanisms to generate a global feature map of the bovine body, including:
[0021] The standardized image is input into a linear projection layer for feature space transformation to obtain a block feature sequence;
[0022] The block feature sequence is input into a multi-layer Transformer encoder. Each layer calculates the inter-block association weights through a multi-head self-attention mechanism and performs layer normalization and residual connection on the attention weighting results.
[0023] Feature transformation is performed using a feedforward neural network to extract the feature vector corresponding to the classification label output by the last layer of the Transformer encoder;
[0024] The feature vectors corresponding to the classification labels are reshaped into a three-dimensional tensor form of a global feature map of the bovine body.
[0025] In some embodiments, a Transformer encoder includes multiple Transformer encoding layers;
[0026] The block feature sequence is input into a multi-layer Transformer encoder. Each layer calculates the inter-block association weights through a multi-head self-attention mechanism and performs layer normalization and residual connections on the attention weighting results, including:
[0027] The block feature sequence is input into the current Transformer encoding layer, and a query vector, key vector, and value vector are generated through linear transformation.
[0028] Calculate the dot product of the query vector and the key vector, scale it, and then apply the softmax function to obtain the attention weight matrix;
[0029] The value vector is weighted and summed using the attention weight matrix to obtain the output features of the multi-head attention mechanism;
[0030] The output features of the multi-head attention mechanism are residually concatenated with the block feature sequence to obtain the feature information after residual concatenation.
[0031] The feature information after residual connection is subjected to layer normalization to obtain the intermediate features of the current Transformer coding layer.
[0032] The intermediate features are input into the feedforward neural network for nonlinear transformation, and residual connection and layer normalization are performed again.
[0033] The updated feature sequence processed by the current Transformer encoding layer is used as the input of the next Transformer encoding layer.
[0034] Repeat the above steps until the last Transformer coding layer;
[0035] Extract the feature vector corresponding to the classification label output by the last Transformer encoder layer, including:
[0036] The feature vectors corresponding to the classification labels in the updated feature sequence output by the last Transformer encoding layer are separated and denoted as classification label features;
[0037] The classification label features are input into a feedforward neural network for nonlinear transformation. The feedforward neural network contains two fully connected layers and an activation function.
[0038] The output features of the first fully connected layer are subjected to a dimensionality expansion transformation to obtain the expanded features.
[0039] The expanded features are input into the second fully connected layer for dimensionality compression and restoration to obtain the compressed features.
[0040] The compressed features are nonlinearly mapped by an activation function to obtain the transformed classification label features, which are the feature vectors corresponding to the final classification labels.
[0041] In some embodiments, feature points are identified based on the global feature map of the bovine body, including:
[0042] The global feature map of the bovine body is input into the feature point localization network, which contains multiple convolutional layers and upsampling layers.
[0043] The first convolutional layer performs shallow feature extraction on the global feature map of the bovine body to obtain the initial feature map;
[0044] The initial feature map is sequentially fed into multiple subsequent convolutional layers for deep feature extraction, resulting in a multi-scale feature map.
[0045] Upsampling is performed on the multi-scale feature map to restore its spatial resolution, resulting in the upsampled feature map.
[0046] The upsampled feature map is fused with the initial feature map to obtain the enhanced feature map.
[0047] Feature weights are calculated on the enhanced feature map using a spatial attention mechanism algorithm. The spatial attention mechanism algorithm is configured to highlight the feature responses of key parts of the bovine body, resulting in an attention-weighted feature map.
[0048] A feature point heatmap is generated by channel compression of the attention-weighted feature map through a 1×1 convolutional layer.
[0049] The peak points are located on the feature point heatmap using a non-maximum suppression algorithm, and these peak points are used as feature points.
[0050] In some embodiments, obtaining the pixel coordinates of each feature point through Gaussian heatmap regression includes:
[0051] Input the feature point heatmap into the Gaussian kernel function processing module to generate a corresponding Gaussian distribution heatmap for each feature point;
[0052] Calculate the probability value of each pixel in the Gaussian distribution heatmap one by one to generate a probability distribution map;
[0053] Locate the probability peak point corresponding to the current feature point on the probability distribution map, and use the pixel coordinates of the probability peak point as the initial pixel coordinates;
[0054] A sub-pixel level coordinate correction algorithm is used to finely adjust the initial pixel coordinates, including:
[0055] Based on the probability value distribution of the neighborhood of the probability peak point, the sub-pixel offset is calculated by fitting a quadratic surface;
[0056] Add the initial pixel coordinates to the sub-pixel offset to obtain the corrected pixel coordinates of the current feature point;
[0057] Repeat the above steps until the pixel coordinates of all feature points have been calculated.
[0058] In some embodiments, multi-scale depth estimation is performed on the global feature map of the bovine body, extracting multiple feature layers of different resolutions, and outputting a depth information estimation image after channel adjustment, feature recombination, and fusion, including:
[0059] The global feature map of the bovine body is input into the depth estimation network, which contains parallel first feature extraction branch, second feature extraction branch, and third feature extraction branch.
[0060] The first feature extraction branch performs full-resolution processing on the global feature map of the bovine body, preserving the original spatial size, to obtain a high-resolution feature layer.
[0061] The global feature map of the bovine body is downsampled through the second feature extraction branch to obtain a medium-resolution feature layer.
[0062] The global feature map of the bovine body is downsampled twice by the third feature extraction branch to obtain a low-resolution feature layer.
[0063] The number of channels in the high-resolution feature layer, medium-resolution feature layer, and low-resolution feature layer is adjusted to make the channel dimensions of the high-resolution feature layer, medium-resolution feature layer, and low-resolution feature layer consistent.
[0064] The high-resolution feature layer, medium-resolution feature layer and low-resolution feature layer after channel adjustment are input into the feature recombination module. Through cross-resolution feature interaction, feature information complementarity is achieved to obtain the recombined multi-resolution feature layer.
[0065] In the feature fusion stage, the recombined multi-resolution feature layers are weighted and fused to obtain a fused feature map;
[0066] By progressively upsampling and fusing feature maps through deconvolution operations, the original input size is restored, and the depth information is output as an estimated image.
[0067] In some embodiments, the channel-adjusted high-resolution feature layer, medium-resolution feature layer, and low-resolution feature layer are input into the feature recombining module. Feature information complementarity is achieved through cross-resolution feature interaction to obtain a recombined multi-resolution feature layer, including:
[0068] The high-resolution feature layer is enhanced by local feature enhancement through 3×3 convolution, resulting in an enhanced high-resolution feature layer.
[0069] The medium-resolution feature layer is upsampled by 2 times and then added element-wise to the enhanced high-resolution feature layer to obtain the first-level fusion feature layer.
[0070] After upsampling the low-resolution feature layer by 4 times, the feature response is adjusted through the channel attention module to obtain the adjusted low-resolution feature layer;
[0071] The adjusted low-resolution feature layer is then combined with the first-level fused feature layer through a channel stitching operation to obtain the stitched feature layer.
[0072] The concatenated feature layers are compressed by 1×1 convolution to obtain a recombined feature layer with a balanced number of channels.
[0073] A spatial attention mechanism algorithm is applied to the recombined feature layer for weighting, highlighting the complementary information between cross-resolution features, and the spatial attention-weighted recombined feature layer is output as the final recombined multi-resolution feature layer.
[0074] In some embodiments, the image is estimated based on the pixel coordinates and depth information of feature points, and the two-dimensional pixel coordinates are converted into three-dimensional world coordinates using camera calibration parameters, including:
[0075] Establish a camera imaging geometric model and obtain the pre-calibrated camera intrinsic parameter matrix and camera extrinsic parameter matrix;
[0076] The pixel coordinates of the feature points are represented as two-dimensional pixel coordinates;
[0077] Estimate the depth value in the image based on the depth information, and determine the Z-axis coordinate of each feature point in the camera coordinate system;
[0078] The three-dimensional coordinates of the feature points in the camera coordinate system are calculated based on the pre-calibrated camera intrinsic parameter matrix and Z-axis coordinates, and through the perspective projection inverse transformation function.
[0079] The 3D coordinates in the camera coordinate system are transformed to the world coordinate system using a pre-calibrated camera extrinsic parameter matrix to obtain the transformed 3D coordinates.
[0080] The transformed 3D coordinates are then scaled to obtain 3D world coordinates.
[0081] In some embodiments, the volume scale parameters are calculated based on three-dimensional world coordinates, including:
[0082] A body size parameter calculation model is established, which includes modules for calculating body height, cross-shaped height, body oblique length, chest circumference, and abdominal circumference.
[0083] Obtain the 3D world coordinates of each feature point;
[0084] Input the three-dimensional world coordinates of the feature points corresponding to the body height into the body height calculation module, and calculate the vertical distance between the highest point of the withers and the ground plane as the body height value;
[0085] Input the three-dimensional world coordinates of the feature point corresponding to the cross height into the cross height calculation module, and calculate the vertical distance between the cross point and the ground plane point as the cross height value.
[0086] Input the three-dimensional world coordinates of the feature points corresponding to the body oblique length into the body oblique length calculation module, and calculate the straight-line distance between the anterior edge of the shoulder and the posterior edge of the ischial tuberosity as the body oblique length value.
[0087] Input the three-dimensional world coordinates of the feature points corresponding to the chest circumference into the chest circumference calculation module, and use the perimeter formed by the rear edge of the withers and the chest base point as the chest circumference value;
[0088] Input the three-dimensional world coordinates of the feature points corresponding to the waist circumference into the waist circumference calculation module to calculate the waist circumference as the perimeter enclosed by the lumbar vertebra point and the abdominal floor point.
[0089] The height, length, chest circumference, and abdominal circumference values are processed by moving average filtering to output the final body size parameters.
[0090] In a second aspect, the present invention also provides a body size measuring device for buffalo based on a monocular camera, applicable to the method described in the first aspect.
[0091] In a third aspect, the present invention also provides a computer-readable storage medium having computer program instructions stored thereon, the computer program instructions implementing the method described in the first aspect when executed by a processor.
[0092] Unlike existing technologies, the above technical solution obtains standardized images by acquiring raw image data from a monocular camera and preprocessing it. The standardized images are then input into a Vision Transformer feature extraction network, which extracts global bovine body features through block embedding and multi-head attention mechanisms. Based on the global bovine body feature map, point recognition is performed to obtain the pixel coordinates of feature points, including the highest point of the withers and the cross point. Multi-scale depth estimation is performed on the global bovine body feature map to output a depth information estimation image. Based on the pixel coordinates of the feature points and the depth information estimation image, the two-dimensional pixel coordinates are converted to three-dimensional world coordinates using camera calibration parameters. Finally, based on the three-dimensional world coordinates, body size parameters including body height, cross height, body oblique length, chest circumference, and abdominal circumference are calculated and output as the measurement results. This technical solution employs a monocular camera for non-contact measurement, avoiding the stress and safety hazards associated with traditional contact measurements, making it particularly suitable for the Binlangjiang water buffalo. By combining a Vision Transformer network with a multi-head attention mechanism, it effectively extracts global features of the buffalo body, improving the accuracy of feature point recognition. A multi-scale depth estimation method, combined with feature maps of different resolutions, significantly enhances the accuracy of depth information estimation. Through 3D world coordinate transformation and geometric calculations, it achieves precise measurement of key body size parameters such as height, body length, and chest circumference. The entire measurement process is highly automated, significantly improving measurement efficiency and providing reliable technical support for the conservation and breeding of Binlangjiang water buffalo germplasm resources.
[0093] The above description of the invention is merely an overview of the technical solution of this application. In order to enable those skilled in the art to better understand the technical solution of this application and to implement it based on the description and drawings, and to make the above-mentioned objectives and other objectives, features and advantages of this application easier to understand, the following description is provided in conjunction with the specific embodiments and drawings of this application. Attached Figure Description
[0094] The accompanying drawings are only used to illustrate the principles, implementation methods, applications, features, and effects of specific embodiments of the present invention and other related contents, and should not be considered as limitations on this application.
[0095] In the accompanying drawings of the instruction manual:
[0096] Figure 1 This is a schematic diagram illustrating the acquisition of a side view image of a cow as described in a specific implementation method. Detailed Implementation
[0097] To illustrate the possible application scenarios, technical principles, implementable specific solutions, and achievable objectives and effects of this application in detail, the following description, in conjunction with the listed specific embodiments and accompanying drawings, provides a detailed explanation. The embodiments described herein are merely illustrative of the technical solutions of this application and are therefore intended to limit the scope of protection of this application.
[0098] In this document, the term "embodiment" means that a specific feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The term "embodiment" appearing in various places throughout the specification does not necessarily refer to the same embodiment, nor does it specifically limit its independence or connection with other embodiments. In principle, in this application, as long as there are no technical contradictions or conflicts, the technical features mentioned in each embodiment can be combined in any way to form corresponding implementable technical solutions.
[0099] Unless otherwise defined, the technical terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the use of related terms herein is merely for the purpose of describing particular embodiments and is not intended to limit this application.
[0100] In the description of this application, the term "and / or" is used to describe the logical relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A exists, B exists, and A and B exist simultaneously. Additionally, the character " / " in this document generally indicates that the preceding and following objects have an "or" logical relationship.
[0101] In this application, terms such as “first” and “second” are used only to distinguish one entity or operation from another, and do not necessarily require or imply any actual quantity, hierarchy or order relationship between these entities or operations.
[0102] Without further limitations, the use of terms such as “comprising,” “including,” “having,” or other similar open-ended expressions in this application is intended to cover non-exclusive inclusion, which does not exclude the presence of additional elements in a process, method, or product that includes the stated elements, such that a process, method, or product that includes a list of elements may include not only those defined elements but also other elements not expressly listed, or elements inherent to such a process, method, or product.
[0103] The processor described in the embodiments of this application can be implemented by hardware, firmware, software, or a combination thereof. It can be a circuit, one or more of an application-specific integrated circuit (ASIC), a digital signal processor (DSP), a digital signal processing device (DSPD), a programmable logic device (PLD), a field-programmable gate array (FPGA), a central processing unit (CPU), a controller, a microcontroller, or a microprocessor. It also includes other physical, biological, or chemical structures that can implement the same or equivalent functions as the processors listed above, such as biological neurons, quantum computing units, DNA computing units, etc., so that the processor can execute some or all of the steps in the computer program or method involved in the various embodiments of this application, or any combination of the steps mentioned therein.
[0104] Please see Figure 1 In a first aspect, this embodiment provides a method for measuring the body size of a buffalo based on a monocular camera, including:
[0105] The raw image data acquired by the monocular camera is obtained, and the raw image data is preprocessed to obtain a standardized image. The preprocessing includes size adjustment and image filling.
[0106] The standardized image is input into the Vision Transformer feature extraction network, and global features of the cow are extracted through block embedding and multi-head attention mechanism to generate a global feature map of the cow.
[0107] Based on the global feature map of the bovine body, point identification was performed to obtain feature points, including the highest point of the withers, the cruciate point, the anterior edge of the shoulder, the posterior edge of the ischial tuberosity, the posterior edge of the withers, the thoracic base point, the lumbar vertebra point, the abdominal base point, and the ground plane point. The pixel coordinates of each feature point were obtained by Gaussian heatmap regression.
[0108] Multi-scale depth estimation is performed on the global feature map of the bovine body. Multiple feature layers with different resolutions are extracted, and the depth information estimation image is output after channel adjustment, feature recombination and fusion.
[0109] Image is estimated based on the pixel coordinates and depth information of feature points, and the two-dimensional pixel coordinates are converted into three-dimensional world coordinates through camera calibration parameters;
[0110] Based on three-dimensional world coordinates, body size parameters are calculated, including body height, cross height, body oblique length, chest circumference, and abdominal circumference. Body height is the vertical distance between the highest point of the withers and the ground plane. Cross height is the vertical distance between the cross point and the ground plane. Body oblique length is the straight-line distance between the anterior edge of the shoulder and the posterior edge of the ischial tuberosity. Chest circumference is the circumference enclosed by the posterior edge of the withers and the base of the chest. Abdominal circumference is the circumference enclosed by the lumbar vertebra and the abdominal base.
[0111] Output measurement results including body size parameters.
[0112] In this embodiment, a monocular camera refers to a fixed-focus imaging device installed on the side of the measurement channel, used to acquire a complete image of the cow's side profile. The monocular camera is mounted on the front side of the body size measurement channel, with appropriate adjustments to the height and distance to ensure a complete image of the cow's side profile is captured. Figure 1 As shown.
[0113] Standardized images refer to input data that has been uniformly resized to 518×518 pixels and edge-padded to ensure that the feature extraction network receives input of a uniform specification. Patch embedding in the Vision Transformer feature extraction network refers to the process of segmenting the image into 37×37 pixel local patches and linearly mapping them to 1024-dimensional vectors. The feature extraction module's structural diagram specifically uses the Vision Transformer (ViT) model. Specifically, the image of the cow's side profile is scaled and padded to a 518×518 pixel image. The resized image is divided into a series of 37×37 pixel image patches, each of which is linearly transformed and flattened into a 1024-dimensional vector. This step is called the PatchEmbedding layer, which maps the pixel values of the cow's side profile image into a 1369×1024 matrix, where each column represents an image patch, for a total of 1369 patch-sized images. Each image patch's flattened vector is then appended with a positional code of the same dimension. The entire image is then appended with a 1024-dimensional CLS token, ultimately forming a 1370×1024 matrix. This matrix is represented as... .
[0114] The multi-head attention mechanism captures the associated features of different parts of the cow's body by computing multiple sets of self-attention weights in parallel. Specifically, the Transformer encoder's multi-head attention mechanism is used to calculate the similarity between input sequences to capture the contextual relationships in the image. Each head is an independent self-attention module, and each head has its own... , which are learnable parameters. These represent Query, Key, and Value, respectively. The calculation process is as follows:
[0115] enter After three fully connected layers, their weights are learnable, as expressed by the following formula:
[0116] ;
[0117] In the above formula, For query vector, For key vectors, For value vectors, The weights of the query vector, The weights of the key vectors, The weight of the value.
[0118] The self-attention of each head through and The dot product between them is normalized using the softmax function before being multiplied by... Multiplying the results yields the attention score for single-head self-attention. This is expressed by the following formula:
[0119] ;
[0120] In the above formula, For attention score, For the softmax function, for and dot product between Scaling factor for Dimensions.
[0121] Multi-head self-attention concatenates the attention scores of the individual heads mentioned above, and then uses a projection matrix. Wo This is then mapped back to the original 1024 dimensions. The output of the multi-head self-attention is then processed by an MLP (Multilayer Perceptron) layer consisting of a linear transformation and the GELU activation function to ultimately form the output of the feature extraction module.
[0122] The body measurements of the Binlangjiang water buffalo involve six indicators: height, cross-shaped height, body length, chest circumference, and abdominal circumference. Key points need to be measured, including the highest point of the withers, the cross-shaped height, the anterior edge of the shoulder, the posterior edge of the ischial tuberosity, the posterior edge of the withers, the thoracic base, the lumbar vertebrae, the abdominal base, and the ground plane. For ease of description, these key points are referred to as characteristic points. Height is the vertical distance between the highest point of the withers and the ground plane; cross-shaped height is the vertical distance from the cross-shaped height to the ground plane; body length is the distance from the anterior edge of the shoulder to the posterior edge of the ischial tuberosity; chest circumference is the length enclosed by the posterior edge of the withers to the thoracic base; and abdominal circumference is the length enclosed by the lumbar vertebrae to the abdominal base. The highest point of the withers, the cross-shaped height, and other characteristic points refer to measurement benchmarks on the buffalo's body surface with clear anatomical significance. Sub-pixel-level positioning accuracy can be achieved through Gaussian heatmap regression.
[0123] The feature point detection process is as follows: The aforementioned feature points are labeled on the side view image of the cow. Each feature point is modeled as a two-dimensional heatmap using a Gaussian distribution, with pixel values decreasing as distance from the feature point increases. Each feature point is then adjusted to a 148×148 heatmap as its true value. The heatmap method models feature points as a two-dimensional Gaussian distribution heatmap, where values decrease as distance from the feature point increases. During decoding, the coordinates of the feature point are obtained by finding the location of the maximum value in the heatmap.
[0124] Furthermore, to detect these feature points, this embodiment provides a feature point detection head. The input to the feature point detection head is the output of the feature extraction module, a global feature map of a bovine body with a shape of 1024×37×37. The detection head uses a 1024-channel, 2-stride transposed convolutional layer (ConvTranspose2d) to upsample the feature map by a factor of 2, while simultaneously adjusting the output channels to 256. Subsequently, the output is normalized and activated using BatchNorm and ReLU activation functions. This process is repeated twice, and then a convolutional layer is used for prediction, predicting one feature point for each output channel. The mean squared error (MSE) is used to calculate the loss between the heatmap of the true feature points and the predicted points. Feature points The calculation is as follows:
[0125] ;
[0126] In the above formula, For the first The mean square error of each feature point The number of pixels in the heatmap is one. It is the first The actual value of each pixel. It is the first Predicted value for each pixel;
[0127] The total mean square error of all feature points This is the cumulative value of the mean square error of each of the above individual feature points:
[0128] .
[0129] In this embodiment, the feature point detection task is transformed into a regression problem by using a heatmap to predict feature points, thereby improving the accuracy to the pixel level. Simultaneously, each feature point is transformed into a Gaussian distribution, taking into account the ambiguity of feature points and avoiding the problem of excessively sparse true values during training.
[0130] Feature reorganization in multi-scale depth estimation refers to the process of reconstructing features by residual convolution after upsampling / downsampling feature maps of different resolutions. Feature fusion, on the other hand, integrates features at each level step by step to improve the continuity of depth prediction.
[0131] Specifically, ordinary RGB images lack depth information, making it difficult to estimate the size of actual objects from images, and thus difficult to measure body size using a single side-view photograph of a cow. The depth estimation module utilizes a deep neural network to estimate the depth information of the cow's side-view photograph, providing a foundation for subsequent body size calculations. The depth estimation module extracts feature maps at four different resolutions: 1 / 4, 1 / 8, 1 / 16, and 1 / 32, to estimate the depth information of different details and objects in the image. These four feature maps are first adjusted using a channel number adjustment module, setting the number of channels to 256, 512, 1024, and 1024 respectively.
[0132] The resampling module uses transposed convolution, ordinary convolution, and identity mapping to upsample the four feature maps at different resolutions by a factor of 4, a factor of 2, remain unchanged, and downsample by a factor of 2 before feeding them into the feature reconstruction module. The feature reconstruction module then uses residual convolution to extract features again. The four feature maps at different resolutions are then fused using a feature fusion module, which sequentially fuses features from different levels. For example, feature fusion layer 2 fuses reconstructed feature 3 with fused feature 2. The final feature map after four fusion layers uses a prediction head to predict the depth information of all pixels, resulting in a depth information estimation image.
[0133] Camera calibration parameters include intrinsic and extrinsic parameter matrices. The intrinsic parameter matrix reflects the lens focal length and the center position of the image plane, while the extrinsic parameter matrix describes the transformation relationship between the camera coordinate system and the world coordinate system. When calculating body size parameters, vertical distance is directly obtained through the Z-axis coordinate difference, linear distance is calculated using the Euclidean distance formula, and perimeter parameters are obtained by summing the features from a series of broken lines.
[0134] The body size calculation module needs to transform the pixel coordinate system in the depth information estimation image to the world coordinate system. Using the theory of pinhole cameras, for a camera's focal length parameter... Camera and image center point coordinates Then pixel coordinates and depth value The following formula can be used to map pixel coordinates to camera coordinates in three-dimensional coordinates. :
[0135] ;
[0136] In the above formula, Let be the equivalent focal length of the camera in the horizontal direction. Let be the equivalent focal length of the camera in the vertical direction. The horizontal coordinates of the principal point. The vertical coordinates of the principal point are the points where the camera's optical axis intersects the imaging plane.
[0137] In order to set camera coordinates Transforming to a real-world coordinate system requires considering the camera's extrinsic parameters, namely the camera's rotation matrix and translation vector relative to the world coordinate system. Let's assume the camera's rotation matrix is... The displacement vector is The camera coordinate system can be set using the following formula. Transform to world coordinates :
[0138] ;
[0139] In body size measurement, pixel coordinates of key points such as the highest point of the withers and the cross point. Depth value from keypoint detection module This data comes from the depth estimation module. It is then converted to world coordinates using the two formulas mentioned above. The distance between two points is calculated using Euclidean distance to obtain body size information. For example, suppose the anterior edge of the shoulder is... The posterior border of the ischial tuberosity is The oblique length of the body is calculated using the following formula:
[0140] ;
[0141] In the above formula, It is a body with an oblique length.
[0142] For circumferential body measurements such as chest circumference, the measurement can be taken from two key points: the posterior edge of the withers and the base of the chest. 1 point, counted as .
[0143] Calculate the distance between each pair of elements: After summing the results, multiply by 2 to calculate the perimeter-type body size index, as shown in the following formula:
[0144] ;
[0145] In the above formula, As a counting unit, It is a perimeter-type body size index.
[0146] In this embodiment, after acquiring images with a monocular camera, the body features of the cow with global perception capability are first extracted through the Vision Transformer network. Then, feature point localization and depth information estimation are performed simultaneously. Finally, the two-dimensional observation data are converted into three-dimensional spatial coordinates by combining the camera geometric model to complete the body size measurement.
[0147] This embodiment utilizes deep learning to achieve accurate identification of key anatomical points, and multi-scale feature fusion ensures the reliability of depth estimation. All body size parameters required for traditional contact measurements can be acquired using only a standard camera. Specifically, Gaussian heatmap regression achieves pixel-level accuracy in feature point localization, while the multi-level depth estimation strategy effectively overcomes the scale ambiguity problem inherent in monocular vision. While ensuring measurement accuracy, it completely avoids the stress reactions caused to cattle by traditional methods, providing a safe and efficient technical means for body size measurement of sensitive livestock breeds like the Binlangjiang water buffalo. The output body size parameters include five core indicators such as body height and cross-shaped height, fully meeting the measurement needs for germplasm resource conservation.
[0148] In some embodiments, raw image data acquired by a monocular camera is obtained, and the raw image data is preprocessed to obtain a standardized image. The preprocessing includes resizing and image padding, including:
[0149] The original image data is scaled to a target size of 518×518 pixels using bilinear interpolation.
[0150] The scaled image is then symmetrically filled while maintaining the aspect ratio of the cow's body to obtain the first filled image.
[0151] The pixel values of the first filled image are converted to the [0,1] interval by normalization processing to obtain the second filled image;
[0152] The second filled image is divided into blocks, resulting in 37×37 image blocks;
[0153] Each image patch is flattened into a 1024-dimensional vector and positional encoding is added to obtain the initial normalized image;
[0154] CLS classification markers are added before the initial normalized image to form a normalized image of 1370×1024.
[0155] In some embodiments, a standardized image is input into a Vision Transformer feature extraction network, and global features of the bovine body are extracted through block embedding and multi-head attention mechanisms to generate a global feature map of the bovine body, including:
[0156] The standardized image is input into a linear projection layer for feature space transformation to obtain a block feature sequence;
[0157] The block feature sequence is input into a multi-layer Transformer encoder. Each layer calculates the inter-block association weights through a multi-head self-attention mechanism and performs layer normalization and residual connection on the attention weighting results.
[0158] Feature transformation is performed using a feedforward neural network to extract the feature vector corresponding to the classification label output by the last layer of the Transformer encoder;
[0159] The feature vectors corresponding to the classification labels are reshaped into a three-dimensional tensor form of a global feature map of the bovine body.
[0160] In this embodiment, bilinear interpolation refers to image scaling using the weighted average of four adjacent pixels, which effectively reduces image distortion and maintains the smoothness of the cow's outline. Symmetrical filling involves mirroring pixel values in the image edge region to ensure that key parts of the cow's body are not affected by cropping. Normalization maps pixel values linearly to the [0,1] interval to eliminate interference from differences in lighting conditions on feature extraction. An image patch is a 37×37 pixel local region formed by uniformly dividing a standardized image; its flattened 1024-dimensional vector retains spatial structure information through linear transformation. Position encoding refers to a sinusoidal position signal superimposed on the image patch vector, used to inject prior knowledge of spatial position into the model. CLS classification label refers to a learnable parameter vector added to the beginning of the sequence; its final output feature vector carries global semantic information. The linear projection layer is a weight matrix that maps the 1024-dimensional image patch vector to the feature space, achieving feature space alignment of the input data. In the multi-head self-attention mechanism, each attention head independently calculates the correlation between different feature subspaces, enhancing the model's ability to capture multi-dimensional features through a parallel structure. Layer normalization standardizes the attention output with zero mean and unit variance, while residual connections preserve the original features and prevent gradient vanishing. The feedforward neural network employs a two-layer fully connected structure with the GELU activation function to further enhance the expressive power of features.
[0161] This embodiment preserves the morphological integrity of the cow body through bilinear interpolation and symmetric padding, constructing a spatially aware input sequence via block embedding and positional encoding. The Vision Transformer network utilizes a multi-head attention mechanism to establish long-range dependencies between image blocks, forming a feature map containing global contextual information through 3D reconstruction of classification label feature vectors. In the preprocessing stage, this method employs a symmetric padding strategy to avoid information loss in key areas, and in the feature extraction stage, multi-head parallel computation improves feature interaction efficiency. Preferably, the reshaping operation of the classification label feature vectors effectively aggregates global semantic information, ensuring that the generated global feature map of the cow body simultaneously contains local details and overall structural features. This significantly improves the generalization ability of the neural network while maintaining measurement accuracy, providing a highly robust feature representation for subsequent keypoint detection and depth estimation.
[0162] In some embodiments, a Transformer encoder includes multiple Transformer encoding layers;
[0163] The block feature sequence is input into a multi-layer Transformer encoder. Each layer calculates the inter-block association weights through a multi-head self-attention mechanism and performs layer normalization and residual connections on the attention weighting results, including:
[0164] The block feature sequence is input into the current Transformer encoding layer, and a query vector, key vector, and value vector are generated through linear transformation.
[0165] Calculate the dot product of the query vector and the key vector, scale it, and then apply the softmax function to obtain the attention weight matrix;
[0166] The value vector is weighted and summed using the attention weight matrix to obtain the output features of the multi-head attention mechanism;
[0167] The output features of the multi-head attention mechanism are residually concatenated with the block feature sequence to obtain the feature information after residual concatenation.
[0168] The feature information after residual connection is subjected to layer normalization to obtain the intermediate features of the current Transformer coding layer.
[0169] The intermediate features are input into the feedforward neural network for nonlinear transformation, and residual connection and layer normalization are performed again.
[0170] The updated feature sequence processed by the current Transformer encoding layer is used as the input of the next Transformer encoding layer.
[0171] Repeat the above steps until the last Transformer coding layer;
[0172] Extract the feature vector corresponding to the classification label output by the last Transformer encoder layer, including:
[0173] The feature vectors corresponding to the classification labels in the updated feature sequence output by the last Transformer encoding layer are separated and denoted as classification label features;
[0174] The classification label features are input into a feedforward neural network for nonlinear transformation. The feedforward neural network contains two fully connected layers and an activation function.
[0175] The output features of the first fully connected layer are subjected to a dimensionality expansion transformation to obtain the expanded features.
[0176] The expanded features are input into the second fully connected layer for dimensionality compression and restoration to obtain the compressed features.
[0177] The compressed features are nonlinearly mapped by an activation function to obtain the transformed classification label features, which are the feature vectors corresponding to the final classification labels.
[0178] In this embodiment, the Transformer encoding layer refers to a stacked feature processing unit composed of a multi-head self-attention mechanism and a feedforward neural network. Each encoding layer has the same structure but independent parameters. The query vector, key vector, and value vector are three feature representations derived from the input feature sequence through linear transformation. The query vector is used to actively retrieve relevant information, the key vector provides the feature benchmark for matching, and the value vector carries the substantive feature content to be aggregated.
[0179] The attention weight matrix refers to the distribution of inter-block association strength after softmax normalization, and its value reflects the semantic relevance between different image blocks. Residual connections are operations that directly add the module input and output, used to alleviate gradient decay problems in deep network training. Layer normalization involves standardizing the mean and variance along the feature dimensions to stabilize the input distribution of each layer in the network. In a feedforward neural network with two fully connected layers, the first fully connected layer typically performs feature dimension expansion to enhance expressive power, while the second fully connected layer performs feature compression to achieve dimension matching. The activation function introduces nonlinear factors to improve the model's fitting ability. Classification label features, as carriers of global semantics, have their final transformation results fused with the contextual information of all image blocks through dimension adjustment and nonlinear mapping.
[0180] This embodiment enhances the semantic expressive power of feature sequences through cascaded processing of multiple Transformer encoders. Each encoding layer first establishes a dynamic association model between image patches using a multi-head self-attention mechanism, preserves the original feature information through residual connections, and then performs higher-order feature transformations via a feedforward neural network. In particular, the classification label features continuously aggregate the global context during the layer-by-layer transmission process, and finally form a discriminative feature representation through a specially designed feedforward network transformation.
[0181] This embodiment achieves a progressive fusion of local features and global semantics through stacked processing. Residual connections ensure effective training of the deep network, while layer normalization maintains the stability of feature distribution. Preferably, the final classification label feature vector not only contains the overall morphological information of the bovine body but also encodes the spatial relationships of various anatomical parts, providing a robust feature foundation for subsequent body size parameter calculations. While ensuring efficient feature transfer, multi-level nonlinear transformations significantly improve the model's ability to represent complex bovine structures.
[0182] In some embodiments, feature points are identified based on the global feature map of the bovine body, including:
[0183] The global feature map of the bovine body is input into the feature point localization network, which contains multiple convolutional layers and upsampling layers.
[0184] The first convolutional layer performs shallow feature extraction on the global feature map of the bovine body to obtain the initial feature map;
[0185] The initial feature map is sequentially fed into multiple subsequent convolutional layers for deep feature extraction, resulting in a multi-scale feature map.
[0186] Upsampling is performed on the multi-scale feature map to restore its spatial resolution, resulting in the upsampled feature map.
[0187] The upsampled feature map is fused with the initial feature map to obtain the enhanced feature map.
[0188] Feature weights are calculated on the enhanced feature map using a spatial attention mechanism algorithm. The spatial attention mechanism algorithm is configured to highlight the feature responses of key parts of the bovine body, resulting in an attention-weighted feature map.
[0189] A feature point heatmap is generated by channel compression of the attention-weighted feature map through a 1×1 convolutional layer.
[0190] The peak points are located on the feature point heatmap using a non-maximum suppression algorithm, and these peak points are used as feature points.
[0191] In this embodiment, the feature point localization network refers to an encoder-decoder structure composed of convolutional layers and upsampling layers, which achieves precise localization by progressively extracting and fusing multi-scale features. Shallow feature extraction utilizes the first convolutional layer to capture basic features such as the cow's body edges and texture, forming an initial feature map containing spatial details. Multi-scale feature maps refer to feature representations extracted through convolutional layers of different depths. Deeper features have a larger receptive field to encode semantic information, while shallower features retain the spatial details needed for precise localization. Upsampling operations use transposed convolution or interpolation methods to progressively restore the feature map resolution, aligning the deep semantic features with the shallow spatial features in terms of size. Feature fusion involves concatenating or weighting feature maps from different levels through skip connections, combining local details with global contextual information. The spatial attention mechanism dynamically enhances the feature responses of key areas of the cow's body (such as joints and the center of the trunk) by calculating the weight distribution of the spatial locations of the feature maps. The feature point heatmap maps map multi-channel features into a single-channel probability map using 1×1 convolutions, with the peak positions corresponding to the predicted coordinates of the feature points. Nonmaximum suppression algorithms eliminate redundant responses in heatmaps and determine the final feature point locations through local extremum search and threshold filtering.
[0192] This embodiment achieves high-precision localization of key bovine anatomy features through the collaborative operation of multi-scale feature extraction and spatial attention mechanisms. The network first constructs a feature pyramid from local details to global semantics using a cascaded convolutional layer structure, then recovers spatial information through upsampling and feature fusion. The spatial attention mechanism automatically focuses on key anatomical regions of the bovine anatomy, effectively suppressing background interference. The final heatmap, after non-maximum suppression processing, yields feature point coordinates with sub-pixel accuracy.
[0193] This embodiment ensures positioning accuracy through deep and shallow feature fusion and enhances algorithm robustness through an attention mechanism, enabling stable identification of feature points in various parts of the bovine body even in complex scenarios. Preferably, the multi-scale feature extraction strategy allows the network to identify both obvious surface features and subtle anatomical landmarks, providing a reliable set of reference points for subsequent 3D reconstruction and body size measurement. End-to-end training optimizes the synergy between feature extraction and positioning, significantly improving the accuracy and stability of automated measurement.
[0194] In some embodiments, obtaining the pixel coordinates of each feature point through Gaussian heatmap regression includes:
[0195] Input the feature point heatmap into the Gaussian kernel function processing module to generate a corresponding Gaussian distribution heatmap for each feature point;
[0196] Calculate the probability value of each pixel in the Gaussian distribution heatmap one by one to generate a probability distribution map;
[0197] Locate the probability peak point corresponding to the current feature point on the probability distribution map, and use the pixel coordinates of the probability peak point as the initial pixel coordinates;
[0198] A sub-pixel level coordinate correction algorithm is used to finely adjust the initial pixel coordinates, including:
[0199] Based on the probability value distribution of the neighborhood of the probability peak point, the sub-pixel offset is calculated by fitting a quadratic surface;
[0200] Add the initial pixel coordinates to the sub-pixel offset to obtain the corrected pixel coordinates of the current feature point;
[0201] Repeat the above steps until the pixel coordinates of all feature points have been calculated.
[0202] In this embodiment, the Gaussian kernel function processing module refers to the computational unit that maps discrete feature points to a continuous probability distribution. It generates a smooth heatmap distribution using a two-dimensional Gaussian function, with the standard deviation parameter controlling the diffusion degree of the probability distribution. The probability distribution map refers to the continuous probability field formed after Gaussian kernel processing, where the value of each pixel reflects its probability of being the center position of a feature point. The probability peak point refers to the pixel position corresponding to the local maximum value in the probability distribution map, and its coordinates serve as the integer-level initial solution for feature point localization. The sub-pixel-level coordinate correction algorithm is a refined localization method that overcomes the limitation of pixel integers. In this algorithm, quadratic surface fitting establishes a quadratic function model of the probability value distribution and calculates the sub-pixel-level deviation between the peak position and the initial integer coordinates. The neighborhood probability value distribution typically uses a 3×3 or 5×5 window range to ensure the stability of the offset calculation.
[0203] This embodiment achieves high-precision feature point localization through Gaussian heatmap regression. First, discrete predictions are converted into a continuous probability distribution. The approximate location of the feature points is determined using probability peaks. Then, sub-pixel correction achieves positioning accuracy exceeding the pixel level. Gaussian kernel processing makes the feature point coordinate predictions differentiable, facilitating end-to-end training of the neural network. The sub-pixel correction algorithm, based on the geometric properties of the probability distribution, calculates more precise peak positions by fitting a neighborhood probability value surface, effectively eliminating quantization errors caused by feature map downsampling.
[0204] This embodiment is particularly suitable for applications requiring millimeter-level precision, such as cattle body measurement. Preferably, the quadratic surface fitting algorithm, while ensuring computational efficiency, can improve coordinate accuracy to the 0.1 pixel level, significantly enhancing the accuracy of subsequent 3D reconstruction and body size parameter calculation. The entire coordinate regression process combines robustness and accuracy, adapting to the feature point localization needs of cattle of different sizes.
[0205] In some embodiments, multi-scale depth estimation is performed on the global feature map of the bovine body, extracting multiple feature layers of different resolutions, and outputting a depth information estimation image after channel adjustment, feature recombination, and fusion, including:
[0206] The global feature map of the bovine body is input into the depth estimation network, which contains parallel first feature extraction branch, second feature extraction branch, and third feature extraction branch.
[0207] The first feature extraction branch performs full-resolution processing on the global feature map of the bovine body, preserving the original spatial size, to obtain a high-resolution feature layer.
[0208] The global feature map of the bovine body is downsampled through the second feature extraction branch to obtain a medium-resolution feature layer.
[0209] The global feature map of the bovine body is downsampled twice by the third feature extraction branch to obtain a low-resolution feature layer.
[0210] The number of channels in the high-resolution feature layer, medium-resolution feature layer, and low-resolution feature layer is adjusted to make the channel dimensions of the high-resolution feature layer, medium-resolution feature layer, and low-resolution feature layer consistent.
[0211] The high-resolution feature layer, medium-resolution feature layer and low-resolution feature layer after channel adjustment are input into the feature recombination module. Through cross-resolution feature interaction, feature information complementarity is achieved to obtain the recombined multi-resolution feature layer.
[0212] In the feature fusion stage, the recombined multi-resolution feature layers are weighted and fused to obtain a fused feature map;
[0213] By progressively upsampling and fusing feature maps through deconvolution operations, the original input size is restored, and the depth information is output as an estimated image.
[0214] In this embodiment, the depth estimation network refers to a feature pyramid network based on a multi-branch parallel architecture, which achieves high-precision depth prediction by collaboratively processing features at different scales. Full-resolution processing involves directly extracting features without reducing spatial dimensions, preserving detailed information about the bovine surface (such as hair texture and skin wrinkles). Its output high-resolution feature layer has maximum spatial accuracy but a limited receptive field. Downsampling processing progressively compresses the feature map size through stride convolution or pooling operations. Medium-resolution and low-resolution feature layers correspond to 1 / 2 and 1 / 4 of the original resolution, respectively, achieving a larger receptive field while sacrificing spatial accuracy, enabling the capture of the overall bovine morphology and long-range dependencies. Channel number adjustment uses 1×1 convolution to achieve uniform regularization of feature channels, ensuring dimensionality compatibility of multi-scale features in subsequent processing. The feature reorganization module achieves cross-scale feature interaction through bidirectional cross-connections (such as feature interpolation upsampling + concatenation or attention weighting), enabling semantic enhancement of high-resolution features and supplementing spatial details with low-resolution features. Weighted fusion employs a learnable channel attention mechanism to dynamically allocate the contribution weights of features at each resolution. The deconvolution operation uses transposed convolution or subpixel convolution to gradually restore the fused feature map to the input image size. The final output depth information estimates the distance from the cow's body surface to the camera for each pixel value.
[0215] This embodiment effectively solves the contradiction between detail preservation and semantic understanding in monocular depth prediction by employing a multi-scale collaborative depth estimation strategy. Three parallel branches focus on different levels of visual information: the high-resolution branch accurately captures local geometric features (such as joint contours), the medium-resolution branch establishes part-level structural relationships (such as the relative positions of the torso and limbs), and the low-resolution branch understands the global spatial layout of the cow's body. The feature reorganization module, through cross-resolution information flow, enables high-resolution features to acquire semantic context (such as associating leg depth prediction with torso depth), while low-resolution features absorb edge details (such as accurately depicting hoof contours).
[0216] This embodiment avoids the problem of lost deep feature spatial information in traditional single-path networks and overcomes the deficiency of insufficient receptive field caused by simply using high-resolution computation. Preferably, the final output depth information estimation image can accurately reflect the three-dimensional spatial relationship between various parts of the cattle body while maintaining millimeter-level local accuracy, providing a reliable geometric basis for subsequent tasks such as volume calculation and body size measurement. The entire scheme optimizes the synergistic effect of multi-scale features through end-to-end training, and can still achieve stable depth estimation performance in complex farming scenarios.
[0217] In some embodiments, the channel-adjusted high-resolution feature layer, medium-resolution feature layer, and low-resolution feature layer are input into the feature recombining module. Feature information complementarity is achieved through cross-resolution feature interaction to obtain a recombined multi-resolution feature layer, including:
[0218] The high-resolution feature layer is enhanced by local feature enhancement through 3×3 convolution, resulting in an enhanced high-resolution feature layer.
[0219] The medium-resolution feature layer is upsampled by 2 times and then added element-wise to the enhanced high-resolution feature layer to obtain the first-level fusion feature layer.
[0220] After upsampling the low-resolution feature layer by 4 times, the feature response is adjusted through the channel attention module to obtain the adjusted low-resolution feature layer;
[0221] The adjusted low-resolution feature layer is then combined with the first-level fused feature layer through a channel stitching operation to obtain the stitched feature layer.
[0222] The concatenated feature layers are compressed by 1×1 convolution to obtain a recombined feature layer with a balanced number of channels.
[0223] A spatial attention mechanism algorithm is applied to the recombined feature layer for weighting, highlighting the complementary information between cross-resolution features, and the spatial attention-weighted recombined feature layer is output as the final recombined multi-resolution feature layer.
[0224] In this embodiment, the feature recombination module adopts a hierarchical cross-resolution feature fusion strategy, achieving feature complementarity through local enhancement, multi-level upsampling, and a dual attention mechanism. 3×3 convolutional local feature enhancement refers to using small receptive field convolutional kernels to strengthen the edge, texture, and other detailed information of high-resolution features while suppressing noise interference. 2x upsampling uses bilinear interpolation or transposed convolution to achieve spatial expansion of medium-resolution features, which is then added element-wise with the enhanced high-resolution features to achieve preliminary fusion of detailed features and medium-level semantic features. 4x upsampling restores low-resolution features to their original size through cascaded 2x upsampling operations or sub-pixel convolutions. The channel attention module adopts an SE (Squeeze-and-Excitation) structure, generating channel weight vectors through global average pooling and fully connected layers to dynamically enhance feature channels strongly correlated with depth estimation. Channel concatenation connects features from different sources along the channel dimension (C dimension) to form a composite feature representation containing multi-granularity information.
[0225] 1×1 convolutional channel compression reduces feature redundancy after concatenation by dimensionality reduction, preserving key features while maintaining computational efficiency. The spatial attention mechanism adopts the spatial attention branch in CBAM (Convolutional Block Attention Module), generating a spatial weight map through joint feature description of max pooling and average pooling, focusing on activating regions with complementary value across resolution features (such as regions where the edge information of high-resolution features is consistent with the semantic prediction of low-resolution features).
[0226] In this embodiment, the feature reconstruction process first achieves medium-to-high resolution feature fusion through 2x upsampling, and then introduces global semantic information through 4x upsampling, avoiding alignment difficulties caused by directly fusing features of different scales. Channel attention optimizes the contribution allocation of feature channels (e.g., enhancing channels related to trunk depth prediction), while spatial attention focuses on key regions of the feature map (e.g., depth abrupt change regions at limb joints). 1×1 convolution maintains the balance of cross-resolution features during dimensionality reduction, preventing features of one scale from dominating. This ensures that the final output reconstructed feature layer contains both high-resolution geometric details (accurately describing the curvature changes of the bovine body surface) and low-resolution global structural understanding (ensuring the consistency of overall depth prediction), providing optimal feature representation for subsequent depth map reconstruction.
[0227] In some embodiments, the image is estimated based on the pixel coordinates and depth information of feature points, and the two-dimensional pixel coordinates are converted into three-dimensional world coordinates using camera calibration parameters, including:
[0228] Establish a camera imaging geometric model and obtain the pre-calibrated camera intrinsic parameter matrix and camera extrinsic parameter matrix;
[0229] The pixel coordinates of the feature points are represented as two-dimensional pixel coordinates;
[0230] Estimate the depth value in the image based on the depth information, and determine the Z-axis coordinate of each feature point in the camera coordinate system;
[0231] The three-dimensional coordinates of the feature points in the camera coordinate system are calculated based on the pre-calibrated camera intrinsic parameter matrix and Z-axis coordinates, and through the perspective projection inverse transformation function.
[0232] The 3D coordinates in the camera coordinate system are transformed to the world coordinate system using a pre-calibrated camera extrinsic parameter matrix to obtain the transformed 3D coordinates.
[0233] The transformed 3D coordinates are then scaled to obtain 3D world coordinates.
[0234] In this embodiment, the camera imaging geometry model refers to a mathematical model that describes the mapping relationship between three-dimensional spatial points and two-dimensional pixels. Its intrinsic parameter matrix is used to characterize optical characteristics such as lens focal length and principal point offset, while the extrinsic parameter matrix defines the camera's pose in the world coordinate system. The pixel coordinates of feature points refer to the precise location of key parts of the cow's body (such as joints and spine) extracted by image processing algorithms in the image, and are usually represented by pixel row and column numbers.
[0235] The depth information estimation image is a dense depth map generated by a multi-scale depth estimation network, where each pixel value corresponds to the vertical distance from the scene point to the camera. The camera coordinate system is a three-dimensional Cartesian coordinate system with the camera's optical center as the origin, and the Z-axis pointing towards the observed scene along the optical axis. The perspective projection inverse transformation function is a mathematical relationship for three-dimensional coordinates derived in reverse based on the pinhole imaging principle, projecting the two-dimensional pixel positions back into three-dimensional space using an intrinsic parameter matrix and depth values. The world coordinate system is a predefined global reference system used to unify multi-view observation data. Scale normalization standardizes coordinate values according to actual physical units, preferably using the metric unit to ensure measurement consistency.
[0236] This embodiment achieves 3D reconstruction of a bovine body by integrating visual geometry and deep learning technologies. Based on feature detection algorithms, the pixel coordinates of key points on the bovine body are located. Combined with pixel-by-pixel depth values predicted by a depth estimation network, camera calibration parameters are used to invert 2D observation data into 3D spatial coordinates. In the camera coordinate system reconstruction stage, perspective projection inverse transformation accurately restores the 3D positions of feature points. After transformation to the world coordinate system through an extrinsic parameter matrix, spatial consistency of multi-view observation data is ensured. Finally, scale normalization processing eliminates systematic errors, outputting 3D coordinates that can be directly used for biological measurements. This overcomes the limitations of traditional methods that rely on manual calibration or dedicated depth sensors. Through an end-to-end coordinate transformation process, it can stably output 3D data with millimeter-level accuracy even in complex breeding environments. It is robust to changes in bovine posture; even with partial occlusion, depth estimation can compensate for missing information, providing reliable 3D foundational data for applications such as automated body size measurement and growth monitoring.
[0237] In some embodiments, the volume scale parameters are calculated based on three-dimensional world coordinates, including:
[0238] A body size parameter calculation model is established, which includes modules for calculating body height, cross-shaped height, body oblique length, chest circumference, and abdominal circumference.
[0239] Obtain the 3D world coordinates of each feature point;
[0240] Input the three-dimensional world coordinates of the feature points corresponding to the body height into the body height calculation module, and calculate the vertical distance between the highest point of the withers and the ground plane as the body height value;
[0241] Input the three-dimensional world coordinates of the feature point corresponding to the cross height into the cross height calculation module, and calculate the vertical distance between the cross point and the ground plane point as the cross height value.
[0242] Input the three-dimensional world coordinates of the feature points corresponding to the body oblique length into the body oblique length calculation module, and calculate the straight-line distance between the anterior edge of the shoulder and the posterior edge of the ischial tuberosity as the body oblique length value.
[0243] Input the three-dimensional world coordinates of the feature points corresponding to the chest circumference into the chest circumference calculation module, and use the perimeter formed by the rear edge of the withers and the chest base point as the chest circumference value;
[0244] Input the three-dimensional world coordinates of the feature points corresponding to the waist circumference into the waist circumference calculation module to calculate the waist circumference as the perimeter enclosed by the lumbar vertebra point and the abdominal floor point.
[0245] The height, length, chest circumference, and abdominal circumference values are processed by moving average filtering to output the final body size parameters.
[0246] The body size parameter calculation model refers to a mathematical model that calculates growth indicators (such as body height, body length, and chest circumference) based on the three-dimensional coordinates of key feature points of the bovine body. The body height calculation module measures the vertical distance between the withers (the highest point of the scapula) and the ground plane, reflecting the overall height of the bovine body; the cruciate height calculation module calculates the vertical distance between the cruciate region (the junction of the lumbar and sacral vertebrae) and the ground plane, used to assess hindquarter development; the body length calculation module characterizes body length by measuring the straight-line distance between the anterior edge of the shoulder and the posterior edge of the ischial tuberosity; the chest circumference calculation module calculates the chest circumference based on the posterior edge of the withers and the base of the chest, reflecting the degree of thoracic cavity development; and the abdominal circumference calculation module measures the abdominal circumference based on the lumbar vertebrae and the base of the abdomen, used to assess nutritional status.
[0247] Three-dimensional world coordinates refer to the precise positions of the cow's feature points in the world coordinate system, obtained through camera calibration and depth estimation, ensuring a consistent measurement benchmark. Moving average filtering is used to smooth multi-frame measurement data, eliminating fluctuations caused by minor cow movements or measurement noise, and improving parameter stability.
[0248] This embodiment calculates key body size parameters of cattle using three-dimensional coordinates, achieving automated and precise measurement. Based on feature point detection and depth estimation, the three-dimensional coordinates of various parts of the cattle body are obtained, and then input into the sub-modules of the body size parameter calculation model to calculate body height, cross-shaped height, body slant length, chest circumference, and abdominal circumference, respectively. During the calculation process, vertical distances are directly solved using coordinate differences, while perimeter parameters are calculated through three-dimensional spatial curve fitting. Moving average filtering optimizes data stability, ensuring reliable output results.
[0249] This embodiment avoids the subjective errors of traditional manual measurement and the inconvenience of contact measurement, and can efficiently and non-contactly acquire bovine growth data. It is suitable for dynamic scenarios and can accurately output body size parameters even when the bovine is standing naturally or in a state of slight movement, providing objective data support for precision breeding, genetic breeding and health monitoring.
[0250] In a second aspect, this embodiment also provides a body size measuring device for buffalo based on a monocular camera, which is applicable to the method described in the first aspect.
[0251] In a third aspect, this embodiment also provides a computer-readable storage medium storing computer program instructions thereon, which, when executed by a processor, implement the method described in the first aspect.
[0252] The computer program involved in this embodiment can be stored in a computer device readable storage medium, which includes, but is not limited to, disks, magnetic tapes, magnetic cards, floppy disks, flash memory, optical disks, optical cards, read-only memory (ROM), random access memory (RAM), erasable programmable ROM (EPROM), and electrically erasable programmable ROM (EEPROM), etc. It also includes other biological, physical, or chemical structures capable of performing similar or equivalent functions to the storage media listed above, such as DNA, RNA, proteins, and other units with information storage capabilities. In specific embodiments, the storage medium involved can be one of the above-mentioned media types or a combination of the above media types. In different embodiments, the computer program involved in the embodiment can be centrally stored in a single medium or distributed across multiple media. The memory containing the computer device readable storage medium can be non-volatile memory or random access memory. These computer device readable storage media can be built into the device or connected to the device involved in the embodiment as an external device or part of an external device. In some embodiments, the memory having a computer device readable storage medium is deployed locally; in other embodiments, the memory may be deployed remotely from the processor, for example, as a network-attached memory accessed via RF circuitry or an external port and a communication network, wherein the communication network may be the Internet, one or more intranets, a local area network (LAN), a wide area network (WLAN), a storage area network (SAN), or a suitable combination thereof, as long as computer device access to the memory is enabled. Furthermore, the computer program involved in the embodiments may be stored in plaintext / ciphertext form, or it may be designed as training data, integrated and recombined through model training and implicitly stored in the parameter states of a deep neural network or other machine learning model.
[0253] Unlike existing technologies, the above technical solution obtains standardized images by acquiring raw image data from a monocular camera and preprocessing it. The standardized images are then input into a Vision Transformer feature extraction network, which extracts global bovine body features through block embedding and multi-head attention mechanisms. Based on the global bovine body feature map, point recognition is performed to obtain the pixel coordinates of feature points, including the highest point of the withers and the cross point. Multi-scale depth estimation is performed on the global bovine body feature map to output a depth information estimation image. Based on the pixel coordinates of the feature points and the depth information estimation image, the two-dimensional pixel coordinates are converted to three-dimensional world coordinates using camera calibration parameters. Finally, based on the three-dimensional world coordinates, body size parameters including body height, cross height, body oblique length, chest circumference, and abdominal circumference are calculated and output as the measurement results. This technical solution employs a monocular camera for non-contact measurement, avoiding the stress and safety hazards associated with traditional contact measurements, making it particularly suitable for the Binlangjiang water buffalo. By combining a Vision Transformer network with a multi-head attention mechanism, it effectively extracts global features of the buffalo body, improving the accuracy of feature point recognition. A multi-scale depth estimation method, combined with feature maps of different resolutions, significantly enhances the accuracy of depth information estimation. Through 3D world coordinate transformation and geometric calculations, it achieves precise measurement of key body size parameters such as height, body length, and chest circumference. The entire measurement process is highly automated, significantly improving measurement efficiency and providing reliable technical support for the conservation and breeding of Binlangjiang water buffalo germplasm resources.
[0254] Finally, it should be noted that although the above embodiments have been described in the text and drawings of this application, this should not limit the scope of patent protection of this application. Any technical solutions that are based on the essential concept of this application and utilize the content described in the text and drawings of this application, resulting in equivalent structural or procedural substitutions or modifications, as well as the direct or indirect application of the technical solutions of the above embodiments to other related technical fields, are all included within the scope of patent protection of this application.
Claims
1. A method for measuring the body size of buffalo based on a monocular camera, characterized in that, include: The raw image data acquired by the monocular camera is obtained, and the raw image data is preprocessed to obtain a standardized image. The preprocessing includes size adjustment and image filling. The standardized image is input into the Vision Transformer feature extraction network, and global features of the cow are extracted through block embedding and multi-head attention mechanism to generate a global feature map of the cow. Based on the global feature map of the bovine body, point identification is performed to obtain feature points, which include the highest point of the withers, the cruciate point, the anterior edge of the shoulder, the posterior edge of the ischial tuberosity, the posterior edge of the withers, the thoracic base point, the lumbar vertebra point, the abdominal base point, and the ground plane point. The pixel coordinates of each feature point are obtained by Gaussian heatmap regression. Multi-scale depth estimation is performed on the global feature map of the bovine body, and multiple feature layers with different resolutions are extracted. After channel adjustment, feature recombination and fusion, the depth information estimation image is output. The image is estimated based on the pixel coordinates and depth information of the feature points, and the two-dimensional pixel coordinates are converted into three-dimensional world coordinates through camera calibration parameters. Based on the aforementioned three-dimensional world coordinates, body size parameters are calculated. These body size parameters include body height, cross height, body oblique length, chest circumference, and abdominal circumference. The body height is the vertical distance between the highest point of the withers and the ground plane. The cross height is the vertical distance between the cross point and the ground plane. The body oblique length is the straight-line distance between the anterior edge of the shoulder and the posterior edge of the ischial tuberosity. The chest circumference is the circumference formed by the posterior edge of the withers and the base of the chest. The abdominal circumference is the circumference formed by the lumbar vertebra and the base of the abdomen. Output the measurement results containing the stated body size parameters; Among them, feature points are obtained by identifying locations based on the global feature map of the bovine body, including: The global feature map of the bovine body is input into a feature point localization network, which contains multiple convolutional layers and upsampling layers. The first convolutional layer performs shallow feature extraction on the global feature map of the bovine body to obtain the initial feature map; The initial feature map is sequentially fed into multiple subsequent convolutional layers for deep feature extraction, resulting in a multi-scale feature map. Upsampling is performed on the multi-scale feature map to restore its spatial resolution, resulting in the upsampled feature map. The upsampled feature map is fused with the initial feature map to obtain the enhanced feature map. Feature weights are calculated on the enhanced feature map using a spatial attention mechanism algorithm, which is configured to highlight the feature responses of key parts of the bovine body, resulting in an attention-weighted feature map. A feature point heatmap is generated by channel compression of the attention-weighted feature map through a 1×1 convolutional layer. A non-maximum suppression algorithm is used to locate peak points on the feature point heatmap, and these peak points are used as feature points.
2. The method for measuring the body size of buffalo based on a monocular camera according to claim 1, characterized in that, The raw image data acquired by the monocular camera is obtained, and the raw image data is preprocessed to obtain a standardized image. The preprocessing includes resizing and image filling, including: The original image data is scaled to a target size of 518×518 pixels using bilinear interpolation. The scaled image is then symmetrically filled while maintaining the aspect ratio of the cow's body to obtain the first filled image. The pixel values of the first filled image are converted to the [0,1] interval by normalization processing to obtain the second filled image; The second filled image is divided into blocks, resulting in 37×37 image blocks; Each image patch is flattened into a 1024-dimensional vector and positional encoding is added to obtain the initial normalized image; CLS classification markers are added before the initial normalized image to form a normalized image of 1370×1024.
3. The method for measuring the body size of buffalo based on a monocular camera according to claim 1, characterized in that, The standardized image is input into the Vision Transformer feature extraction network, and global features of the cow are extracted through block embedding and multi-head attention mechanisms to generate a global feature map of the cow, including: The standardized image is input into a linear projection layer for feature space transformation to obtain a block feature sequence; The block feature sequence is input into a multi-layer Transformer encoder. Each layer calculates the inter-block association weights through a multi-head self-attention mechanism and performs layer normalization and residual connection on the attention weighting results. Feature transformation is performed using a feedforward neural network to extract the feature vector corresponding to the classification label output by the last layer of the Transformer encoder; The feature vectors corresponding to the classification labels are reshaped into a three-dimensional tensor form of a global feature map of the bovine body.
4. The method for measuring the body size of buffalo based on a monocular camera according to claim 3, characterized in that, A Transformer encoder consists of multiple Transformer encoding layers; The block feature sequence is input into a multi-layer Transformer encoder. Each layer calculates the inter-block association weights through a multi-head self-attention mechanism and performs layer normalization and residual connections on the attention weighting results, including: The block feature sequence is input into the current Transformer encoding layer, and a query vector, key vector, and value vector are generated through linear transformation. Calculate the dot product of the query vector and the key vector, scale it, and then apply the softmax function to obtain the attention weight matrix; The value vector is weighted and summed using the attention weight matrix to obtain the output features of the multi-head attention mechanism; The output features of the multi-head attention mechanism are residually concatenated with the block feature sequence to obtain the feature information after residual concatenation. The feature information after residual connection is subjected to layer normalization to obtain the intermediate features of the current Transformer coding layer. The intermediate features are input into the feedforward neural network for nonlinear transformation, and residual connection and layer normalization are performed again. The updated feature sequence processed by the current Transformer encoding layer is used as the input of the next Transformer encoding layer. Repeat the above steps until the last Transformer coding layer; Extract the feature vector corresponding to the classification label output by the last Transformer encoder layer, including: The feature vectors corresponding to the classification labels in the updated feature sequence output by the last Transformer encoding layer are separated and denoted as classification label features; The classification label features are input into a feedforward neural network for nonlinear transformation. The feedforward neural network contains two fully connected layers and an activation function. The output features of the first fully connected layer are subjected to a dimensionality expansion transformation to obtain the expanded features. The expanded features are input into the second fully connected layer for dimensionality compression and restoration to obtain the compressed features. The compressed features are nonlinearly mapped by an activation function to obtain the transformed classification label features, which are the feature vectors corresponding to the final classification labels.
5. The method for measuring the body size of buffalo based on a monocular camera according to claim 1, characterized in that, The pixel coordinates of each feature point are obtained through Gaussian heatmap regression, including: The feature point heatmap is input into the Gaussian kernel function processing module to generate a corresponding Gaussian distribution heatmap for each feature point; Calculate the probability value of each pixel in the Gaussian distribution heatmap one by one to generate a probability distribution map; Locate the probability peak point corresponding to the current feature point on the probability distribution map, and use the pixel coordinates of the probability peak point as the initial pixel coordinates; A sub-pixel level coordinate correction algorithm is used to finely adjust the initial pixel coordinates, including: Based on the probability value distribution of the neighborhood of the probability peak point, the sub-pixel offset is calculated by fitting a quadratic surface; Add the initial pixel coordinates to the sub-pixel offset to obtain the corrected pixel coordinates of the current feature point; Repeat the above steps until the pixel coordinates of all feature points have been calculated.
6. The method for measuring the body size of buffalo based on a monocular camera according to claim 1, characterized in that, Multi-scale depth estimation is performed on the global feature map of the bovine body, extracting multiple feature layers of different resolutions. After channel adjustment, feature recombination, and fusion, a depth information estimation image is output, including: The global feature map of the bovine body is input into a depth estimation network, which includes a first feature extraction branch, a second feature extraction branch, and a third feature extraction branch in parallel. The first feature extraction branch performs full-resolution processing on the global feature map of the bovine body, preserving the original spatial size, to obtain a high-resolution feature layer. The global feature map of the bovine body is downsampled through the second feature extraction branch to obtain a medium-resolution feature layer. The global feature map of the bovine body is downsampled twice by the third feature extraction branch to obtain a low-resolution feature layer. The number of channels in the high-resolution feature layer, medium-resolution feature layer, and low-resolution feature layer is adjusted to make the channel dimensions of the high-resolution feature layer, medium-resolution feature layer, and low-resolution feature layer consistent. The high-resolution feature layer, medium-resolution feature layer and low-resolution feature layer after channel adjustment are input into the feature recombination module. Through cross-resolution feature interaction, feature information complementarity is achieved to obtain the recombined multi-resolution feature layer. In the feature fusion stage, the recombined multi-resolution feature layers are weighted and fused to obtain a fused feature map; By progressively upsampling and fusing feature maps through deconvolution operations, the original input size is restored, and the depth information is output as an estimated image.
7. The method for measuring the body size of buffalo based on a monocular camera according to claim 6, characterized in that, The high-resolution, medium-resolution, and low-resolution feature layers, after channel adjustment, are input into the feature reconstructing module. Through cross-resolution feature interaction, feature information is complemented to obtain the reconstructed multi-resolution feature layer, including: The high-resolution feature layer is enhanced by local feature enhancement through 3×3 convolution, resulting in an enhanced high-resolution feature layer. The medium-resolution feature layer is upsampled by 2 times and then added element-wise to the enhanced high-resolution feature layer to obtain the first-level fusion feature layer. After upsampling the low-resolution feature layer by 4 times, the feature response is adjusted through the channel attention module to obtain the adjusted low-resolution feature layer; The adjusted low-resolution feature layer is then combined with the first-level fused feature layer through a channel stitching operation to obtain the stitched feature layer. The concatenated feature layers are compressed by 1×1 convolution to obtain a recombined feature layer with a balanced number of channels. A spatial attention mechanism algorithm is applied to the recombined feature layer for weighting, highlighting the complementary information between cross-resolution features, and the spatial attention-weighted recombined feature layer is output as the final recombined multi-resolution feature layer.
8. A device for measuring the body size of buffalo based on a monocular camera, characterized in that, The apparatus is used to perform the method according to any one of claims 1 to 7.
9. A computer-readable storage medium storing computer program instructions thereon, characterized in that, The computer program instructions, when executed by a processor, implement the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Garbage distance measurement and size calculation method and system based on monocular camera perception
CN118485726A
Beef cattle body size measuring system based on image recognition
CN120451247A