A pig part zero-label recognition method based on discrete Morse theory

CN122657940BActive Publication Date: 2026-10-27JIANGXI AGRICULTURAL UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611149521.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-07-31
Publication Date
2026-10-27
Estimated Expiration
2046-07-31

AI Technical Summary

Technical Problem

[0003]上述方法对人工标注数据具有较强依赖

Benefits of technology

1.本发明通过视觉基础模型基于文本提示完成猪只实例分割,保持所述视觉基础模型的参数冻结,并根据自动生成的二值掩码构建训练数据,整个猪只部位识别过程无需人工标注头部、尾部和腿部关键点,降低了猪只部位识别系统的数据标注成本和部署门槛。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122657940B_ABST
    Figure CN122657940B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of computer vision, in particular to a pig part zero-label recognition method based on discrete Morse theory. A video frame sequence containing pigs is obtained, and instance segmentation of the pigs is performed based on a text prompt through a visual basic model to obtain a binary mask and image embedding features; an Euclidean distance transform terrain field is predicted according to the image embedding features and the background area is removed; the Euclidean distance transform terrain field is taken as a discrete Morse function to determine topological critical points and persistent homology values; an initial skeleton is obtained by skeleton thinning the binary mask, and the terminal branches are pruned according to the persistent homology values to obtain a pig topological skeleton; the head, tail and leg are identified according to the pig center, end points in the pig topological skeleton, head direction and pig body axis to obtain a pig part recognition result. The present application does not require manual key point labeling, can reduce deployment cost and improve cross-scene applicability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer vision technology, specifically to a method for zero-label recognition of pig body parts based on discrete Morse theory. Background Technology

[0002] In precision livestock management, the automatic localization of the pig's head, tail, and legs is a crucial foundation for monitoring feeding behavior, analyzing activity status, identifying lameness, and detecting abnormal behavior. Existing methods for pig body part identification typically employ supervised learning, pre-collecting images or videos of pigs, manually annotating key points on the pigs, and then using the annotated data to train a posture estimation model to achieve localization of different parts of the pig.

[0003] The methods described above heavily rely on manually labeled data. Different pig farms have varying camera angles, lighting conditions, stocking densities, and pig appearances. When the application scenario changes, it is usually necessary to re-collect and label data, and train or fine-tune the model, resulting in long deployment cycles and high labeling costs. Furthermore, general animal pose estimation models typically use relatively fine-grained anatomical keypoint definitions, while actual farm monitoring often only requires coarse-grained features such as the head, tail, and legs. This mismatch between general keypoint definitions and actual monitoring needs creates a gap between general keypoint definitions and actual monitoring requirements.

[0004] Visual basic models can segment pigs in videos based on text prompts, but their output mainly consists of binary masks and image embedding features, and cannot directly determine the positions of the pig's head, tail, and legs. When processing the binary mask of the pig using conventional skeleton refinement methods, mask boundary burrs, ear contours, and local shape variations easily form non-realistic skeleton branches, leading to an increase in the number of skeleton endpoints and making it difficult to accurately distinguish the head, tail, and legs based on skeleton endpoints. Therefore, a method is needed that can extract topologically significant skeleton structures from pig segmentation results and complete pig part recognition without the need for manual keypoint annotation. Summary of the Invention

[0005] This invention provides a zero-label recognition method for pig parts based on discrete Morse theory, which enables automatic recognition of the head, tail and legs of pigs without the need for manual key point annotation, and improves the ability to be deployed across different scenarios.

[0006] To achieve the above objectives, the present invention provides the following technical solution: This invention discloses a method for zero-label identification of pig body parts based on discrete Morse theory, comprising: S100: Obtain a video frame sequence containing pigs, and perform instance segmentation of the pigs in the video frame sequence based on text prompts using a visual basic model to obtain the binary mask and image embedding features of the pigs. S200: Predict the Euclidean distance transformed terrain field of the pig based on the image embedding features, and remove the background region in the Euclidean distance transformed terrain field based on the binary mask; S300: The Euclidean distance-transformed terrain field is used as a discrete Morse function, and the discrete Morse function value is scanned from high to low. The topological critical point and continuous homology value are determined based on the change in pixel connectivity during the scanning process. S400: The binary mask is refined to obtain an initial skeleton. The terminal branches in the initial skeleton are pruned according to the continuous homology value to obtain the pig topological skeleton. S500: Determine the pig center based on the Euclidean distance transformed topographic field, determine the head based on the pig center and the endpoints in the pig topological skeleton, identify the tail based on the direction of the head relative to the pig center and establish the pig body axis, identify the legs based on the position of the remaining endpoints relative to the pig body axis, and obtain the pig part identification result.

[0007] As a preferred technical solution of the present invention, in S100, the specific steps of performing instance segmentation of pigs in the video frame sequence based on text prompts using a visual basic model include: The pig target is initialized in the first frame of the video frame sequence with a text prompt corresponding to the pig; The parameters of the visual base model are kept frozen, and the pig target is segmented by the visual base model to obtain the corresponding binary mask and image embedding features. Based on the pig target initialized in the first frame of the video frame sequence, the corresponding pigs in the subsequent video frames of the video frame sequence are tracked and segmented to obtain the binary mask and image embedding features corresponding to each pig in the subsequent video frames.

[0008] As a preferred embodiment of the present invention, in S200, the specific steps of predicting the Euclidean distance transformed terrain field of the pig based on the image embedding features include: The image embedding features are input into a cascaded convolutional network head, which includes a first convolutional layer, a second convolutional layer, and a third convolutional layer connected in sequence. The first and second convolutional layers are sequentially processed by convolution, grouping normalization, and ReLU activation, and the third convolutional layer is processed by convolution and Sigmoid activation to obtain a single-channel normalized terrain field. The normalized terrain field is upsampled to the original resolution of the corresponding video frame in the video frame sequence and multiplied pixel by pixel with the binary mask to obtain the Euclidean distance transformed terrain field with the background area removed.

[0009] As a preferred embodiment of the present invention, in S200, the cascaded convolutional network head used to predict the Euclidean distance transformed terrain field is trained through the following steps: Based on the binary mask obtained by instance segmentation of the training video using the aforementioned visual foundation model, the Euclidean distance transformation result corresponding to the binary mask is calculated, and the Euclidean distance transformation result is normalized to obtain the supervised terrain field. The image embedding features output by the visual base model are input into the head of the cascaded convolutional network to obtain a normalized terrain field. Within the region corresponding to the binary mask, calculate the mean square error loss between the normalized terrain field and the supervised terrain field; Keep the parameters of the visual base model frozen, and update the parameters of the cascaded convolutional network head according to the mean squared error loss.

[0010] As a preferred embodiment of the present invention, in S300, the specific steps for determining the topological critical point and the continuous coherence value based on the changes in pixel connectivity during the scanning process include: Sort all pixels within the binary mask region from high to low according to their corresponding discrete Morse function values ​​and scan them sequentially. For the currently scanned pixel, determine the adjacency relationship between the currently scanned pixel and the already formed connected components; When the currently scanned pixel is not adjacent to any existing connected component, a new connected component is established based on the currently scanned pixel, and the currently scanned pixel is determined as a maximum value; When the currently scanned pixel is adjacent to only one established connected component, the currently scanned pixel is incorporated into the connected component; When the current scanned pixel is adjacent to two or more different connected components at the same time, the current scanned pixel is determined as a saddle point, and the two or more different connected components are merged into the same connected component through the current scanned pixel; When merging two or more different connected components, the connected component with the highest discrete Morse function value corresponding to the maximum value among the connected components participating in the merger is retained, and the maximum values ​​corresponding to the remaining connected components participating in the merger are paired with the saddle point respectively. Based on the difference between the discrete Morse function value corresponding to the maximum value paired with the saddle point and the discrete Morse function value corresponding to the saddle point, the continuous homology value corresponding to each maximum value paired with the saddle point is determined.

[0011] As a preferred embodiment of the present invention, in S300, the step of scanning according to the discrete Morse function values ​​from high to low includes: For pixels with the same discrete Morse function value, the interconnected pixels are merged into a pixel set according to the pixel adjacency relationship; For each set of pixels, the set of pixels is treated as a whole, and the adjacency relationship between the set of pixels and the formed connected components is determined. When the pixel set is not adjacent to any existing connected component, a new connected component is established based on the pixel set, the pixel set is determined as a maximum region, and the centroid position of the pixel set is determined as the maximum position corresponding to the new connected component. When the pixel set is adjacent to only one existing connected component, the pixel set is incorporated into the connected component; When the pixel set is adjacent to two or more different connected components at the same time, the corresponding saddle point is determined, and the two or more different connected components are merged into the same connected component through the pixel set.

[0012] As a preferred embodiment of the present invention, in S400, the specific steps of pruning the terminal branches in the initial skeleton according to the continuous homology value include: The binary mask is subjected to morphological opening and closing operations, and the processed binary mask is skeletonized to obtain an initial skeleton with a single pixel width. Traverse the terminal branches in the initial skeleton, determine the endpoint pixels of each terminal branch, determine the connected component to which the endpoint pixels belong before the connected component is merged based on the belonging relationship of the endpoint pixels in the process of connected component generation and merging, and obtain the maximum value corresponding to the connected component and the continuous cohomology value corresponding to the maximum value. When the sustained coherence value is not lower than the preset sustained coherence threshold, the corresponding terminal branch is retained; When the sustained coherence value is lower than the preset sustained coherence threshold, and the pixel length of the corresponding end branch does not reach the long branch protection threshold, the corresponding end branch is deleted. When the sustained coherence value is lower than the preset sustained coherence threshold, and the pixel length of the corresponding terminal branch reaches the long branch protection threshold, the corresponding terminal branch is retained. Remove residual terminal branches whose pixel length is lower than the preset short branch length threshold after pruning to obtain the pig topological skeleton containing endpoints and bifurcation points.

[0013] As a preferred embodiment of the present invention, in S500, the specific steps of determining the head based on the pig center and the endpoints in the pig topological skeleton include: Determine the set of pixels with the largest discrete Morse function value within the binary mask region, and determine the pig center based on the centroid position of the pixel set; Obtain the endpoints in the topological skeleton of the pig, and normalize the distance from each endpoint to the center of the pig and the discrete Morse function value corresponding to each endpoint to obtain the normalized distance and normalized discrete Morse function value corresponding to each endpoint. The normalized distance and the normalized discrete Morse function value are weighted and combined to obtain a comprehensive score for each endpoint, and the endpoint with the highest comprehensive score is determined as the head candidate. The nearest bifurcation point to the head candidate is determined along the pig's topological skeleton. When the distance between the bifurcation point and the head candidate is not greater than a preset ratio of the distance between the head candidate and the center of the pig, the bifurcation point is determined as the head. When the distance between the bifurcation point and the head candidate is greater than a preset ratio of the distance between the head candidate and the center of the pig, the head candidate is determined as the head.

[0014] As a preferred embodiment of the present invention, in S500, the specific steps of identifying the tail based on the direction of the head relative to the center of the pig include: Determine the head direction from the center of the pig to the head; Obtain the remaining endpoints other than the head candidate, and determine the candidate directions pointing from the center of the pig to each remaining endpoint; Remove remaining endpoints whose distance from the center of the pig is less than a preset center distance threshold; Calculate the cosine similarity between the candidate direction and the head direction respectively, and determine the remaining endpoint with the smallest cosine similarity as the tail.

[0015] As a preferred embodiment of the present invention, in S500, the specific steps of identifying the leg based on the position of the remaining endpoint relative to the pig's body axis include: The pig's body axis is determined by the direction of the line connecting the head and the center of the pig, and the normal axis is determined by the direction perpendicular to the pig's body axis. A local coordinate system aligned with the pig's orientation is established. Obtain the remaining endpoints other than the head candidate and the tail, and project the remaining endpoints onto the normal axis direction; Based on the pig outline formed by the binary mask and the distribution of the remaining endpoints on both sides of the pig's body axis, the ventral and dorsal sides of the pig's body axis are determined. Retain the remaining endpoints located on the ventral side of the pig's body axis and remove the remaining endpoints located on the dorsal side of the pig's body axis; Remove any remaining endpoints whose distance from the head or tail is less than a preset head-to-tail distance threshold, and define the remaining endpoints as legs.

[0016] The beneficial effects of this invention are: 1. This invention completes pig instance segmentation based on text prompts using a visual basic model, keeps the parameters of the visual basic model frozen, and constructs training data based on automatically generated binary masks. The entire pig part recognition process does not require manual annotation of key points of the head, tail, and legs, reducing the data annotation cost and deployment threshold of the pig part recognition system.

[0017] 2. This invention treats interconnected pixels with the same discrete Morse function value as a whole for scanning, avoiding false saddle points caused by different pixel scanning orders. It also combines a continuous coherence threshold, a long branch protection threshold, and a preset short branch length threshold to perform layered screening of the initial skeleton. This reduces false branches formed by binary mask boundary spikes and local noise, while avoiding the accidental deletion of real long branches such as the head, thus improving the stability and integrity of the pig topological skeleton.

[0018] 3. This invention automatically generates a supervised terrain field based on a binary mask, and uses a cascaded convolutional network head to convert the image embedding features extracted by the visual base model into an Euclidean distance transformed terrain field, so that image embedding features without clear part semantics can be used for subsequent recognition of pig geometry, topology and pig parts; during training, only the parameters of the cascaded convolutional network head are updated, without the need to train or fine-tune the visual base model, thus reducing training overhead.

[0019] 4. This invention identifies the head, tail, and legs based on the pig's center, endpoints in the pig's topological skeleton, head direction, body axis, and distribution on the ventral and dorsal sides. The output pig part identification results can be used for pig behavior monitoring and can also be used as pseudo-labels to train downstream key point detection models, thereby improving the utilization rate of unlabeled pig house video data. Attached Figure Description

[0020] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings: Figure 1 This is a flowchart illustrating a method for identifying zero-labeled parts of pigs based on discrete Morse theory according to the present invention. Figure 2 This is a schematic diagram of the overall structure of the present invention, which includes pig instance segmentation, Euclidean distance transformation terrain field prediction, discrete Morse analysis, pig topological skeleton extraction, and pig part identification. Figure 3 This is a three-dimensional schematic diagram of the terrain field and topological critical point of the Euclidean distance transformation of the present invention; Figure 4 This is a schematic diagram of the pig topological skeleton and pig part recognition results in a multi-pig scenario according to the present invention; Figure 5This is a schematic diagram showing the superimposed topographic field of the Euclidean distance transformation, the topological skeleton of the pig, and the identification results of the pig parts in this invention. Detailed Implementation

[0021] The preferred embodiments of the present invention will be described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.

[0022] Example 1: As Figure 1 As shown, the present invention provides a method for zero-label identification of pig body parts based on discrete Morse theory, comprising: S100: Obtain a video frame sequence containing pigs, and perform instance segmentation of the pigs in the video frame sequence based on text prompts using a visual basic model to obtain the binary mask and image embedding features of the pigs. In one embodiment, continuously captured video footage from a fixed camera inside the pigsty is obtained, and the video frames arranged in chronological order of capture time are used as a video frame sequence. In this embodiment, the fixed camera is positioned in a top-down view, the resolution of each video frame in the video frame sequence is 1920×1080 pixels, and the video frame sequence contains one or more pigs.

[0023] The video frame sequence is input into the visual base model. In this embodiment, the visual base model adopts the SAM3 visual base model, loads the official pre-trained weights of the SAM3 visual base model, and keeps the parameters of the visual base model frozen, so that the visual base model does not perform parameter updates or fine-tuning during pig instance segmentation.

[0024] Using the first frame of the video frame sequence as the initialization frame, the text prompt corresponding to the pig is input into the visual base model. In this embodiment, the text prompt is "pig". The visual base model determines the pig target in the first frame of the video frame sequence based on the text prompt, and performs instance segmentation on the pig target to obtain a binary mask corresponding to each pig. The binary mask is represented as follows: ; in, Indicates the first The binary mask corresponding to each pig; The number representing the pig instance; The binary mask indicates that each pixel has a value of 0 or 1, where a value of 1 indicates that the corresponding pixel belongs to the [missing value]. There are 1 pigs, and a value of 0 indicates that the corresponding pixel does not belong to the 1st pig. One pig; Indicates the pixel height of the corresponding video frame; This indicates the pixel width of the corresponding video frame.

[0025] During instance segmentation of the pig target, the image embedding features extracted and cached by the visual base model are obtained, and the image embedding features are represented as follows: ; in, This represents the image embedding features; Represents the set of real numbers; 256 represents the number of video frames input to the visual base model in a single input; 256 represents the number of feature channels of the image embedding features. The feature map height represents the image embedding features; The width of the feature map represents the image embedding feature. The image embedding feature contains semantic and spatial information of the corresponding video frame and maintains a spatial correspondence with the binary mask.

[0026] After initializing the pig target in the first frame of the video frame sequence, the corresponding pigs in subsequent video frames of the video frame sequence are tracked and segmented using the video propagation mechanism of the visual base model. For each subsequent video frame, the visual base model determines the position of the corresponding pig in the subsequent video frame based on the pig target initialized in the first frame, and outputs the binary mask corresponding to each pig and the image embedding features of the corresponding video frame.

[0027] Thus, a binary mask and image embedding features are obtained for each pig in the video frame sequence. The binary mask is used to remove background regions in the Euclidean distance-transformed terrain field in S200, and the image embedding features are input into the head of a cascaded convolutional network to predict the Euclidean distance-transformed terrain field of the corresponding pig. The above process uses only text prompts corresponding to the pigs to complete the initialization, instance segmentation, and tracking segmentation of the pig targets, without the need for manual annotation of the pig's head, tail, and legs.

[0028] S200: Predict the Euclidean distance transformed terrain field of the pig based on the image embedding features, and remove the background region in the Euclidean distance transformed terrain field based on the binary mask; like Figure 2 As shown, the corresponding video frames in the video frame sequence are processed by an image encoder to obtain image embedding features; the text prompts, after being processed by a prompt encoder, and the image embedding features, are used as inputs to a mask decoder, which generates a binary mask. The image embedding features are obtained solely from the corresponding video frames processed by the image encoder. Figure 2The data path output by the prompt encoder merges with the data path of the image embedding features, indicating that the text prompt processed by the prompt encoder and the image embedding features are jointly input into the mask decoder, but not that the prompt encoder generates or processes the image embedding features. The image embedding features are also input into a cascaded convolutional network head, which yields a normalized terrain field. This normalized terrain field is multiplied pixel-by-pixel by the binary mask to form an Euclidean distance transform terrain field. This Euclidean distance transform terrain field is used to determine subsequent topological critical points and sustained homology values. The binary mask is refined through a skeleton to obtain an initial skeleton, and the terminal branches in the initial skeleton are pruned according to the sustained homology values ​​to obtain the pig's topological skeleton, thereby completing the recognition of the pig's center, head, tail, and legs. S200 corresponds to... Figure 2 The process involves embedding features in an image, processing them through a cascaded convolutional network head, and combining them with a binary mask to generate an Euclidean distance-transformed terrain field.

[0029] In one implementation, the image embedding features obtained in S100 are input into a cascaded convolutional network head. The cascaded convolutional network head is located at the mask decoder of the visual base model and reads the image embedding features extracted by the visual base model during instance segmentation. The cascaded convolutional network head includes a first convolutional layer, a second convolutional layer, and a third convolutional layer connected sequentially.

[0030] The first convolutional layer uses a 3×3 convolution with 256 input channels and 128 output channels. After convolution processing by the first convolutional layer, the image embedding features undergo grouping normalization and ReLU activation sequentially. The second convolutional layer uses a 3×3 convolution with 128 input channels and 64 output channels. After convolution processing by the second convolutional layer, grouping normalization and ReLU activation are performed sequentially. The third convolutional layer uses a 1×1 convolution with 64 input channels and 1 output channel. After convolution processing by the third convolutional layer, Sigmoid activation is used to limit the output value to the range of 0 to 1.

[0031] The single-channel normalized terrain field output by the third convolutional layer is upsampled to the original resolution of the corresponding video frame in the video frame sequence, and the upsampled normalized terrain field is compared with the first convolutional layer. The binary mask corresponding to each pig Multiply pixel by pixel to obtain the binary mask. Setting the background region with a value of 0 to zero results in the first... The Euclidean distance transformed terrain field corresponding to each pig; the Euclidean distance transformed terrain field is a normalized terrain field with values ​​ranging from 0 to 1, expressed as: ; in, Indicates the first Euclidean distance-transformed topographic field corresponding to each pig; symbol This indicates that the Euclidean distance transformed terrain field is predicted by the head of a cascaded convolutional network; The number representing the pig instance; Represents the Euclidean distance transformed terrain field The numerical value of each pixel position ranges from 0 to 1; Indicates the pixel height of the corresponding video frame; This indicates the pixel width of the corresponding video frame. and stated Binary mask in S100 The pixel height and pixel width have the same meaning.

[0032] The Euclidean distance transformed terrain field Reflecting the This section describes the distance relationships between different pixels within the binary mask region of each pig and the mask boundary. Pixels closer to the mask boundary correspond to smaller values, while pixels farther away correspond to larger values. Wide and thick areas within the pig form regions with higher values, while the pig's boundaries and slender parts form regions with lower values. This transforms the two-dimensional geometry of the pig into a continuously changing terrain field, providing a data foundation for the S300 to scan according to discrete Morse function values.

[0033] The cascaded convolutional network head used to predict the Euclidean distance-transformed terrain field is trained through the following steps: A binary mask obtained by instance segmentation of the training video using the visual base model is acquired. For each binary mask, the Euclidean distance from each pixel within the mask region to its nearest boundary pixel is calculated to obtain the Euclidean distance transformation result. The Euclidean distance transformation result is normalized using the square root of the number of pixels with a value of 1 in the binary mask as the normalization scale to obtain the supervised terrain field, which is represented as... .

[0034] in, This represents the supervised terrain field formed after normalizing the Euclidean distance transform result calculated from the binary mask; the superscript " "This is used to indicate that the supervised terrain field is supervised data directly calculated based on a binary mask, and does not indicate a multiplication operation."

[0035] The visual foundation model embeds features into the image output from the training video. Input the cascaded convolutional network head to obtain a normalized terrain field, and then combine the normalized terrain field with the first... The binary mask corresponding to each pig Multiplying pixel by pixel, we get the first pixel. Euclidean distance transformed terrain field for each pig and in the binary mask Calculate the Euclidean distance transformed terrain field within the corresponding region. With the supervised terrain field The mean square error loss between them is: ; in, This represents the mean square error loss; Indicates the first The binary mask corresponding to each pig; The number representing the pig instance; Represents the binary mask The number of pixels with a value of 1; This represents the row coordinates of the pixels in the corresponding video frame; This represents the column coordinates of the pixels in the corresponding video frame; Represented by pixel row coordinates and pixel column coordinates Determined pixel position; Indicates pixel position Located in the binary mask The region containing a value of 1; Represents the Euclidean distance transformed terrain field At pixel position The value at that location; Represents the supervised terrain field At pixel position The value at that location; Indicates the first The supervising topographic field corresponding to each pig; the superscript * indicates that the supervising topographic field is directly calculated based on the binary mask, and does not indicate a multiplication operation; This represents the binary mask. The summation is performed on all pixel positions where the value is 1.

[0036] During training, the parameters of the visual baseline model are kept frozen and not updated. The parameters of the cascaded convolutional network head are updated based on the mean squared error loss. In this embodiment, the data used to train the cascaded convolutional network head comes from approximately 27,000 pig instances obtained by the visual baseline model through instance segmentation of the training video. The supervised terrain field is automatically calculated based on the binary mask corresponding to each pig instance, eliminating the need for manual annotation of pig parts or Euclidean distance transformed terrain fields.

[0037] After training the cascaded convolutional network head is completed, according to the first... The binary mask corresponding to each pig The number of pixels with a value of 1 is used to transform the Euclidean distance terrain field. The terrain field is restored to a pixel-level Euclidean distance transform, which is represented as follows: ; in, Indicates the first The pixel-level Euclidean distance transform terrain field corresponding to each pig; subscript This indicates that the Euclidean distance transformed terrain field has been restored to the pixel level; Indicates the first Euclidean distance-transformed terrain field corresponding to each pig; Indicates the first The binary mask corresponding to each pig; Represents the binary mask The number of pixels with a value of 1; Represents the binary mask The square root of the number of pixels with a value of 1.

[0038] The pixel-level Euclidean distance-transformed terrain field is used to characterize the pixel distance from a pixel within a binary mask region to the boundary of the binary mask. To ensure a uniform scale for the discrete Morse function values ​​across different pig instances, S300 employs this Euclidean distance-transformed terrain field. Perform scanning and topology analysis as a discrete Morse function.

[0039] S300: The Euclidean distance-transformed terrain field is used as a discrete Morse function, and the discrete Morse function value is scanned from high to low. The topological critical point and continuous homology value are determined based on the change in pixel connectivity during the scanning process. like Figure 2 and Figure 3 As shown, the Euclidean distance-transformed terrain field obtained in S200 is used as a discrete Morse function defined on the binary mask pixel grid. In one embodiment, before scanning according to the discrete Morse function values ​​from high to low, the Euclidean distance-transformed terrain field is Gaussian smoothed to obtain a smoothed Euclidean distance-transformed terrain field, and the smoothed Euclidean distance-transformed terrain field is used as the discrete Morse function. In this embodiment, the Gaussian smoothing parameter... Set to 5.0. The standard deviation of the Gaussian kernel used for Gaussian smoothing is represented in pixels. Gaussian smoothing is used to reduce the impact of local numerical fluctuations in the Euclidean distance-transformed terrain field on the determination of topological critical points. In this embodiment, for any pixel within the binary mask region, the discrete Morse function value corresponding to that pixel is the value of the smoothed Euclidean distance-transformed terrain field at the corresponding pixel location. In the smoothed Euclidean distance-transformed terrain field, locally thick areas around pigs correspond to larger discrete Morse function values, while areas near the pig boundaries correspond to smaller discrete Morse function values, thus forming a terrain structure that gradually decreases in size from locally thick areas to the pig boundaries.

[0040] Figure 3 The diagram shows the three-dimensional shape of the Euclidean distance transformed terrain field corresponding to a single pig, where the horizontal and vertical coordinates represent the pixel positions in the binary mask, and the vertical height represents the discrete Morse function value. Figure 3 The maxima P1, P2, and P3 are located in the local wide and thick regions of the pig, while saddle points S1 and S2 are located in the transition region between adjacent maxima. The maxima represent the positions where connected components are generated during the scanning process, and the saddle points represent the positions where two or more different connected components merge. Figure 2 The connection between the Euclidean distance transformed topographic field, topological critical points, and the distribution of persistent homology values ​​represents the process of extracting topological critical points and calculating persistent homology values ​​from the Euclidean distance transformed topographic field.

[0041] All pixels within the binary mask region are sorted from highest to lowest according to their corresponding discrete Morse function values, and then scanned sequentially according to the sorting results. During the scanning process, a disjoint-set data structure (DFT) is used to record the connectivity relationships between scanned pixels. The DFT searches and merges the connected components to which the scanned pixels belong, so that interconnected scanned pixels belong to the same connected component, and records the maximum value corresponding to each connected component.

[0042] For pixels with distinct discrete Morse function values, the currently scanned pixel is used as the processing object to determine the adjacency relationship between the currently scanned pixel and any existing connected components. When the currently scanned pixel is not adjacent to any existing connected component, a new connected component is established based on the currently scanned pixel, and the currently scanned pixel is determined as the maximum value corresponding to the new connected component.

[0043] When the current scanned pixel is adjacent to only one established connected component, the current scanned pixel is incorporated into the connected component, so that the connected component extends to the region with a lower discrete Morse function value as the scan range expands.

[0044] When the currently scanned pixel is adjacent to two or more different connected components simultaneously, the currently scanned pixel is determined as a saddle point, and the two or more different connected components are merged into a single connected component through the currently scanned pixel. Therefore, the maxima determined when establishing new connected components during the scanning process and the saddle points determined when merging connected components are used as topological critical points.

[0045] For pixels with the same discrete Morse function value, firstly, based on pixel adjacency relationships, interconnected pixels are merged into pixel sets, and then each pixel set is treated as a whole for subsequent scanning. For each pixel set, the adjacency relationship between the pixel set and the already formed connected components is determined.

[0046] When the pixel set is not adjacent to any existing connected component, a new connected component is established based on the pixel set, the pixel set is identified as a maxima region, the centroid of the pixel set is identified as the maxima position corresponding to the new connected component, and the maxima position is recorded as the maxima corresponding to the new connected component; when the pixel set is adjacent to only one existing connected component, the pixel set is merged into the connected component; when the pixel set is adjacent to two or more different connected components simultaneously, the corresponding saddle point is identified, and the two or more different connected components are merged into a single connected component through the pixel set.

[0047] By first merging pixels with the same discrete Morse function value and that are interconnected, and then establishing an adjacency relationship between the merged pixel set and the already formed connected components, inconsistent connected component merging results and pseudo saddle points can be avoided due to different scanning orders of pixels with the same discrete Morse function value.

[0048] When two or more distinct connected components merge, the discrete Morse function values ​​of the maxima corresponding to the merging connected components are compared. The connected component with the highest discrete Morse function value corresponding to the maxima is retained, and the maxima corresponding to the remaining merging connected components are paired with the saddle points corresponding to this merge. Based on the discrete Morse function value corresponding to the maxima paired with each saddle point and the discrete Morse function value corresponding to the saddle point, a corresponding sustained homology value is determined, where the sustained homology value is: ; in, This represents the topological feature corresponding to the maximum value that is paired with the saddle point during the merging of connected components; Representing the topological features The corresponding sustained cohomology value; The discrete Morse function is represented by the Euclidean distance transformed terrain field. Representing the topological features The generation location is the maximum value recorded when the corresponding connected component is established; Representing the topological features The ending position is the saddle point recorded when the corresponding connected component merges with other connected components; This represents the discrete Morse function value corresponding to the maximum value; This represents the discrete Morse function value corresponding to the saddle point.

[0049] The sustained cohomology value represents the range of discrete Morse function values ​​that the connected components corresponding to the maxima undergo from generation to merging. A larger sustained cohomology value indicates that the corresponding local structure has high topological saliency in the Euclidean distance-transformed topographic field; a smaller sustained cohomology value indicates that the corresponding local structure may be formed by binary mask boundary spikes or local noise.

[0050] During the scanning process, the correspondence between the connected components, maxima, saddle points, and sustained cohomology values ​​is saved, as well as the pixel affiliation during the connected component generation and merging process. These correspondences and affiliations are used in S400 to determine the maxima and sustained cohomology values ​​corresponding to each terminal branch in the initial skeleton, so as to perform terminal branch pruning based on the sustained cohomology values.

[0051] The ablation experimental results of the S300 step pseudo-saddle point elimination mechanism are shown in Table 1.

[0052] Table 1. Ablation experimental results of the S300 step pseudo-saddle point elimination mechanism.

[0053] As shown in Table 1, to verify the actual effect of the plateau judgment mechanism in step S300 (i.e., first merging pixels with the same discrete Morse function value, and then judging the adjacency relationship with existing connected components), comparative experiments were conducted on the real test set for two conditions: the terrain field without Gaussian smoothing and the actual deployment configuration of the present invention (after Gaussian smoothing). The results show that under the condition of no smoothing, the baseline scheme generated 514 pseudo saddle points, while the present invention scheme generated 0, indicating that the mechanism can effectively avoid pseudo saddle points caused by different pixel scanning orders. Under the actual deployment configuration of the present invention, neither scheme generated pseudo saddle points, and the downstream part recognition accuracy (Head@0.1, Tail@0.1, Leg@0.1, Mean@0.1, and mOKS) was basically the same, indicating that under Gaussian smoothing, neither scheme generated pseudo saddle points; when there is no smoothing or the smoothing effect is insufficient, the plateau judgment mechanism of the present invention can still maintain the stability of the topological critical point determination results and reduce the impact of changes in preprocessing conditions on subsequent continuous homology analysis.

[0054] S400: The binary mask is refined to obtain an initial skeleton. The terminal branches in the initial skeleton are pruned according to the continuous homology value to obtain the pig topological skeleton. like Figure 2 As shown, the binary mask obtained in S100 is refined into an initial skeleton. Then, the terminal branches in the initial skeleton are pruned according to the continuous coherence value obtained in S300 to obtain the pig topological skeleton. Figure 2 The process of generating an initial skeleton from a binary mask, pruning the terminal branches of the initial skeleton, and obtaining the pig topological skeleton corresponds to the skeleton generation and terminal branch pruning processes in this step.

[0055] In one implementation, morphological opening and closing operations are first performed on the binary mask. The morphological opening and closing operations include morphological opening and morphological closing operations, wherein the morphological opening operation is used to remove small protrusions on the boundary of the binary mask, and the morphological closing operation is used to fill small depressions on the boundary of the binary mask, so as to reduce the impact of binary mask boundary burrs on the skeleton refinement result.

[0056] The binary mask processed by morphological opening and closing operations is then refined into a skeleton. While maintaining the topological connectivity of the binary mask region, the region is progressively shrunk to an initial skeleton of single-pixel width. The initial skeleton includes endpoints, branch points, and skeleton paths connecting the endpoints and branch points.

[0057] Endpoints and branching points are determined based on the adjacency relationships between skeleton pixels in the initial skeleton. A skeleton pixel is designated as an endpoint when it is adjacent to only one other skeleton pixel; a skeleton pixel is designated as a branching point when it is adjacent to three or more other skeleton pixels. The skeleton path extending from the endpoint along the initial skeleton to the adjacent branching point is defined as the terminal branch, and the number of skeleton pixels constituting the terminal branch is taken as the pixel length of the terminal branch.

[0058] Traverse the terminal branches in the initial skeleton, determine the endpoint pixels of each terminal branch, and determine the connected component to which the endpoint pixels belong before the connected component merging process in S300 according to the belonging relationship of the endpoint pixels. Then, obtain the maximum value corresponding to the connected component and the continuous cohomology value corresponding to the maximum value.

[0059] When S300 scans from high to low according to the discrete Morse function values, each newly established connected component records its corresponding maximum value. When the connected component merges with other connected components at a saddle point, the maximum value corresponding to the connected component is paired with the saddle point, and the sustained homology value corresponding to the maximum value is determined. Based on the attribution record of the endpoint pixels of the terminal branch before the connected components merge, the correspondence between the corresponding connected component, maximum value, and sustained homology value is queried, thereby determining the corresponding sustained homology value for each terminal branch.

[0060] A preset continuous cohomology threshold, a long branch protection threshold, and a preset short branch length threshold are set. The preset continuous cohomology threshold is used to determine the topological salience of the local structure corresponding to the terminal branch; the long branch protection threshold is used to determine whether terminal branches with a continuous cohomology value lower than the preset continuous cohomology threshold need to be retained; and the preset short branch length threshold is used to remove the short terminal branches remaining after pruning.

[0061] It should be noted that the setting principles of the preset continuous coherence threshold, long branch protection threshold and preset short branch length threshold are to effectively filter out noisy terminal branches while avoiding the accidental deletion of the real skeletal structure corresponding to the pig's head, tail and legs due to overly strict pruning conditions.

[0062] In this embodiment, the preset continuous co-homogeneity threshold The value is set to 0.15; the long branch protection threshold is the larger of 20 and 3.5% of the number of pixels on the short side of the corresponding video frame; the preset short branch length threshold is the larger of 10 and 2.5% of the number of pixels on the short side of the image where the initial skeleton is located. The aforementioned values ​​are specific implementation parameters used in this embodiment and do not constitute a limitation on the values ​​of the corresponding parameters.

[0063] When the resolution of the corresponding video frame and the image containing the initial skeleton is both 1920×1080 pixels, the long branch protection threshold is the larger of 20 and 37.8, i.e., 37.8 pixels; the preset short branch length threshold is the larger of 10 and 27, i.e., 27 pixels.

[0064] The preset continuous coherence threshold, long branch protection threshold, and preset short branch length threshold can be calibrated based on the verification video in the target application scenario. For application scenarios with different video shooting angles, pig size ranges, or image resolutions, the above values ​​can be adaptively adjusted based on the preservation of branches in real parts and the removal of noisy terminal branches.

[0065] When the sustained coherence value is not lower than the preset sustained coherence threshold, the corresponding terminal branch is retained.

[0066] When the sustained coherence value is lower than the preset sustained coherence threshold, the pixel length of the corresponding terminal branch is compared with the long branch protection threshold. When the pixel length of the corresponding terminal branch does not reach the long branch protection threshold, the corresponding terminal branch is deleted; when the pixel length of the corresponding terminal branch reaches the long branch protection threshold, the corresponding terminal branch is retained to avoid deleting pig structures with large pixel lengths.

[0067] After pruning the terminal branches based on the sustained coherence value and the long branch protection threshold, the remaining terminal branches are traversed, and residual terminal branches with pixel lengths lower than the preset short branch length threshold are deleted. After the above processing, the main skeleton paths, topologically significant terminal branches, endpoints, and bifurcation points in the initial skeleton are retained, resulting in the pig's topological skeleton. The endpoints and bifurcation points in the pig's topological skeleton are used in S500 to determine the pig's head, tail, and legs.

[0068] The ablation experimental results of the S400 single-threshold and multi-threshold pruning schemes are shown in Table 2.

[0069] Table 2 Ablation Experiment Results of Single-Threshold and Multi-Threshold Pruning Schemes in S400 Step

[0070] As shown in Table 2, to verify the actual effect of the multi-threshold superposition pruning scheme (combining continuous homology threshold, long branch protection threshold, and preset short branch length threshold) in step S400 compared to the single continuous homology threshold pruning scheme, a comparative experiment was conducted on a real test set of 776 real part branches and 724 noise branches. The results show that the noise point removal rate of the single threshold pruning scheme is 81.2%, but the recall rate is only 35.1%, meaning that more than 60% of the real part branches were mistakenly deleted. The multi-threshold superposition pruning scheme of this invention achieves a recall rate of 96.1%, and the vast majority of real part branches are preserved, verifying that the long branch protection mechanism can effectively avoid the mistaken deletion of pig structures with large pixel lengths (such as the head). The scheme of this invention has a lower noise point removal rate (9.7%) and accuracy (53.3%) compared to the single threshold scheme. The further filtering of these residual noise branches is undertaken by geometric rules based on the pig center distance, head-tail direction, etc. in step S500.

[0071] S500: Determine the pig center based on the Euclidean distance transformed topographic field, determine the head based on the pig center and the endpoints in the pig topological skeleton, identify the tail based on the direction of the head relative to the pig center and establish the pig body axis, identify the legs based on the position of the remaining endpoints relative to the pig body axis, and obtain the pig part identification result.

[0072] like Figure 2 As shown, after obtaining the topological skeleton of the pig, the pig center is determined based on the maximum discrete Morse function value in the Euclidean distance transform terrain field. The head candidates are determined by combining the endpoints in the pig topological skeleton and the head is adsorbed. The tail is determined based on the reverse constraint of the head direction. Then, the remaining endpoints are screened based on the pig's body axis and normal axis to determine the legs, thus obtaining the pig part recognition result.

[0073] For any given pig, obtain the discrete Morse function values ​​corresponding to all pixels in the binary mask, and determine the largest discrete Morse function value. Form a pixel set from the pixels with the largest discrete Morse function value, and calculate the centroid of all pixel coordinates in the pixel set. Determine the centroid as the pig's center. When there is only one pixel with the largest discrete Morse function value, determine the location of that pixel as the pig's center.

[0074] Obtain all endpoints in the pig topological skeleton. For each endpoint, calculate the Euclidean distance between the endpoint and the pig center, and normalize the Euclidean distance based on the maximum Euclidean distance between all endpoints and the pig center to obtain the normalized distance corresponding to the endpoint; obtain the discrete Morse function value corresponding to the endpoint, and normalize the discrete Morse function value corresponding to the endpoint based on the maximum discrete Morse function value within the binary mask region to obtain the normalized discrete Morse function value corresponding to the endpoint.

[0075] Based on the normalized distance and the normalized discrete Morse function value, calculate the comprehensive score for each endpoint: ; in, Indicates endpoints ( The corresponding comprehensive score; This indicates the current pig's number. One endpoint; Indicates the endpoint number; This indicates the pig center of the current pig; Indicates endpoint With pig center The Euclidean distance between them; This represents the maximum Euclidean distance between all endpoints of the current pig and the pig's center; Indicates endpoint The corresponding discrete Morse function value; This represents the maximum discrete Morse function value within the binary mask region of the current pig; Indicates the weights corresponding to the normalized distance; This represents the weights corresponding to the normalized discrete Morse function values. In this embodiment, , .

[0076] Compare the overall scores of all endpoints and identify the endpoint with the highest overall score as the head candidate.

[0077] Identify the bifurcation point in the pig's topological skeleton that is closest to the candidate head, and determine the head adsorption range based on the Euclidean distance between the candidate head and the pig's center: ; in, Indicates the adsorption range of the head; Indicates the head candidate; This represents the pig center of the current pig, and is related to the aforementioned comprehensive scoring formula. The meaning is consistent; This represents the Euclidean distance between the candidate head and the center of the pig; This indicates a preset ratio. In this embodiment, .

[0078] Calculate the distance between the candidate head and the nearest bifurcation point. If the distance between the candidate head and the nearest bifurcation point is not greater than the head's adsorption range, the nearest bifurcation point is determined as the head; if the distance between the candidate head and the nearest bifurcation point is greater than the head's adsorption range, the candidate head is determined as the head.

[0079] The head orientation is determined based on the direction pointing from the pig's center to the head. Candidate heads are excluded from all endpoints of the pig's topological skeleton, resulting in remaining endpoints. The Euclidean distance between each remaining endpoint and the pig's center is calculated. Remaining endpoints whose Euclidean distance to the pig's center is less than a preset center distance threshold are deleted to exclude endpoints located near the pig's center.

[0080] For each remaining endpoint, the direction from the pig's center to that endpoint is determined as a candidate direction, and the cosine similarity between the candidate direction and the head direction is calculated. The cosine similarity of all candidate directions is compared, and the remaining endpoint with the lowest cosine similarity is determined as the tail. The smaller the cosine similarity, the closer the corresponding candidate direction is to the opposite direction of the head direction.

[0081] Using the line connecting the head and the center of the pig as the pig's body axis, the direction perpendicular to the pig's body axis as the normal axis, and the center of the pig as the origin of the local coordinate system, a local coordinate system corresponding to the pig's orientation is established.

[0082] The head and tail candidates are excluded from all endpoints of the pig's topological skeleton, leaving remaining endpoints for leg recognition. These remaining endpoints are then projected onto the normal axis, and their location on the pig's body axis is determined based on their projection position along the normal axis.

[0083] The ventral and dorsal sides of the pig are determined based on the distribution of the pig outline formed by the binary mask on both sides of the pig's body axis and the distribution of the remaining endpoints on both sides of the pig's body axis.

[0084] Retain the remaining endpoints located on the ventral side and delete those located on the dorsal side to exclude non-leg endpoints such as ears located on the dorsal side or near the head. Calculate the Euclidean distance between the retained remaining endpoints and the head, and the Euclidean distance between the retained endpoints and the tail. If the Euclidean distance between the remaining endpoint and the head is less than a preset head-to-tail distance threshold, or if the Euclidean distance between the remaining endpoint and the tail is less than the preset head-to-tail distance threshold, delete the corresponding remaining endpoint. The remaining endpoints retained after the above filtering are identified as legs.

[0085] It should be noted that the preset center distance threshold is used to exclude the remaining endpoints located near the center of the pig that are not suitable as the tail; the preset head-tail distance threshold is used to exclude the remaining endpoints located near the head or tail that are not suitable as the legs.

[0086] In this embodiment, the Euclidean distance between the candidate head and the center of the pig is used as the distance scale, and the preset head-to-tail distance threshold is set to 0.30 times the distance scale; the preset center distance threshold is set to 1.5 times the preset head-to-tail distance threshold, that is, 0.45 times the distance scale.

[0087] The setting principles for the preset center distance threshold and the preset head-tail distance threshold are to reduce misjudgments of body parts while avoiding the exclusion of true tail or leg endpoints due to overly strict distance screening conditions. For application scenarios with different video shooting angles, pig size ranges, or image resolutions, the above magnification can be adaptively adjusted based on the misjudgments in the head, tail, and leg recognition results and the retention of true body part endpoints.

[0088] like Figure 4 As shown, Figure 4 This diagram illustrates the overlay of pig topological skeletons and pig body part recognition results onto original video frames in a multi-pig scenario. White lines represent the topological skeleton of each pig, and the marked points indicate the head, tail, and legs determined according to the steps described above. Different pigs in the video frames are identified by their respective body parts based on their corresponding binary masks, Euclidean distance-transformed terrain fields, and pig topological skeletons.

[0089] like Figure 5 As shown, Figure 5 This is a superimposed diagram of the Euclidean distance-transformed terrain field of the pig, the pig's topological skeleton, and the pig's body part recognition results. The grayscale levels represent the magnitudes of the discrete Morse function values ​​in the Euclidean distance-transformed terrain field, the white lines represent the pig's topological skeleton obtained through continuous homology pruning, and the labeled points represent the determined head, tail, and legs. Therefore, the head, tail, and leg positions corresponding to each pig in the output video frame sequence are obtained, yielding the pig body part recognition results.

[0090] Example 2: To verify the ability of the method of the present invention to identify pig parts without the need for manual key point annotation, and the feasibility of using the pig part identification results output by the method of the present invention to train the downstream key point detection model, the method described in Example 1 was used to process unannotated pig house video frames.

[0091] A sequence of video frames containing pigs is input into a visual baseline model, with the parameters of the model frozen. Pigs in the video frame sequence are segmented using text prompts to obtain a binary mask and image embedding features for each pig. A cascaded convolutional network head predicts an Euclidean distance-transformed topological field. This Euclidean distance-transformed topological field is used as a discrete Morse function to determine topological critical points and sustained homology values. Based on the sustained homology values, the terminal branches in the initial skeleton are pruned to obtain a pig topological skeleton. Based on the Euclidean distance-transformed topological field and the pig topological skeleton, the head, tail, and legs of each pig are determined, resulting in pig part recognition.

[0092] Without using manually labeled keypoint data, the Mean@0.1 of the pig part identification results directly output by the method of the present invention is 67.7%, mOKS is 61.6%, and Leg@0.1 is 82.6%, indicating that the method of the present invention can determine the endpoints corresponding to the legs in the pig topological skeleton through Euclidean distance transformation of the terrain field, continuous cohomology analysis, and pig topological skeleton.

[0093] Furthermore, the head, tail, and leg coordinates output from unlabeled video frames using the method of this invention are used as pseudo-labels and converted into the training label format required by the downstream keypoint detection model. 50 and 200 video frames with the aforementioned pseudo-labels are selected as training samples to train YOLO11M-Pose, YOLO26M-Pose, HRNet-w32, HRNet-w48, and ResNet-50, respectively. The 50 and 200 frames represent the number of video frames for which pseudo-labels are automatically generated using the method of this invention. Neither the pseudo-label generation process nor the training process of the downstream keypoint detection model uses manually labeled keypoint data.

[0094] The recognition results for pig body parts were evaluated using Head@0.1, Tail@0.1, Leg@0.1, Mean@0.1, mOKS, and EPE. Here, Head@0.1 represents the PCK@0.1 value for the head; Tail@0.1 represents the PCK@0.1 value for the tail; and Leg@0.1 represents the PCK@0.1 value for the leg. PCK@0.1 represents the percentage of keypoints correctly identified when the distance between the predicted body part and its corresponding ground truth body part is less than 10% of the target size. Mean@0.1 represents the arithmetic mean of Head@0.1, Tail@0.1, and Leg@0.1. mOKS represents the average target keypoint similarity. EPE represents the average endpoint pixel error between the predicted body part and its corresponding ground truth body part, in pixels. Higher values ​​for Head@0.1, Tail@0.1, Leg@0.1, Mean@0.1, and mOKS indicate more accurate recognition results; lower values ​​for EPE indicate a smaller deviation between the predicted and ground truth positions. The actual locations of the pig's head, tail, and legs in the test set were obtained by manual annotation. The manual annotation was only used to calculate the evaluation index and did not participate in the training of the cascaded convolutional network head, pig part recognition, pseudo-label generation, or downstream key point detection model training.

[0095] The validation results of the detection models for each downstream key point are shown in Table 3.

[0096] Table 3 Performance comparison of downstream keypoint detection models trained with pseudo-labels on the test set.

[0097] As shown in Table 3, after increasing the number of pseudo-label frames from 50 to 200, the Mean@0.1 and mOKS of the five downstream keypoint detection models all improved, while the EPE all decreased. This indicates that increasing the number of pseudo-labels automatically generated by the method of this invention can improve the overall performance of pig part recognition of the downstream keypoint detection model.

[0098] When YOLO26M-Pose was trained with 50 frames of pseudo-labels, the Head@0.1 accuracy was 49.3%, Tail@0.1 was 57.3%, Leg@0.1 was 13.6%, Mean@0.1 was 40.1%, mOKS was 25.3%, and EPE was 62.8 pixels. After training with 200 frames of pseudo-labels, the Head@0.1 accuracy increased to 98.7%, Tail@0.1 increased to 97.3%, Leg@0.1 increased to 51.1%, Mean@0.1 increased to 82.4%, mOKS increased to 56.2%, and EPE decreased to 36.4 pixels.

[0099] When trained using 200 frames of pseudo-labels, the Mean@0.1 of the five downstream keypoint detection models ranged from 63.9% to 82.4%. YOLO26M-Pose had the highest Mean@0.1 at 82.4%, while HRNet-w32, ResNet-50, and HRNet-w48 had Mean@0.1 of 77.7%, 76.1%, and 72.5%, respectively. These results demonstrate that the pig body part identification results generated by the method of this invention can serve as training labels for downstream keypoint detection models with different structures, and are not limited to a single model structure.

[0100] This embodiment uses a maximum of 200 pseudo-labels to train the downstream keypoint detection model. In actual pigsty scenarios, the method described in Embodiment 1 can be used to continuously process unlabeled video frames and automatically generate a larger number of pseudo-labels for pig parts, eliminating the need for manual labeling of the pig's head, tail, and legs frame by frame. This forms a processing flow from zero-label recognition of pig parts and pseudo-label generation to training of the downstream keypoint detection model.

[0101] Example 3: To verify the performance of the method of the present invention in pig body part recognition without using manually labeled keypoint data, the recognition results of the method of the present invention are compared with the pose estimation model trained with manually labeled data. The same test set as in Example 2 and the evaluation metrics Head@0.1, Tail@0.1, Leg@0.1, Mean@0.1, mOKS, and EPE are used.

[0102] The method of this invention processes the test video frames according to S100 to S500 as described in Example 1, directly outputting the positions of the pig's head, tail, and legs without using manually labeled pig keypoint data. Under zero manual keypoint labeling conditions, the method of this invention achieves a Mean@0.1 of 67.7%, a mOKS of 61.6%, and a Leg@0.1 of 82.6%.

[0103] The comparison methods were trained using 50 manually annotated video frames, with the positions of the pig's head, tail, and legs manually labeled in each frame. The comparison models included YOLO11M-Pose, YOLO26M-Pose, HRNet-w32, HRNet-w48, and ResNet-50. YOLO11M-Pose and YOLO26M-Pose were pre-trained using COCO human pose data before training; HRNet-w32, HRNet-w48, and ResNet-50 were trained using both AP-10K animal pose data and without external pose data, respectively.

[0104] The external pose data refers to the pose dataset containing manually labeled keypoints that the model has pre-trained before training with 50 manually labeled video frames. The COCO human pose dataset includes approximately 200,000 images with manually labeled poses, and the AP-10K animal pose dataset includes approximately 10,000 images with multi-species manually labeled keypoints. The visual foundation model used in this invention only provides general instance segmentation capabilities and does not provide prior knowledge of head, tail, or leg keypoint poses for the pig body part recognition process.

[0105] The test results of each manual annotation training method are shown in Table 4.

[0106] Table 4. Performance Comparison of Manually Annotated Models on the Test Set

[0107] As shown in Table 4, the Mean@0.1 of YOLO11M-Pose trained using 50 manually annotated video frames is 49.6%, and the mOKS is 31.7%, which are lower than the 67.7% and 61.6% achieved by the method of this invention under the condition of zero manual keypoint annotation, respectively. The Mean@0.1 of the method of this invention is 18.1 percentage points higher than that of YOLO11M-Pose, indicating that the method of this invention can directly achieve the identification of pig parts even with a limited amount of manually annotated data.

[0108] The YOLO26M-Pose model trained using 50 manually labeled video frames achieved a Mean@0.1 of 71.1% and a mOKS of 47.3%. In Example 2, after training the same model using 200 pseudo-labels automatically generated by the method of this invention, the Mean@0.1 was 82.4% and the mOKS was 56.2%, representing improvements of 11.3 and 8.9 percentage points, respectively, compared to the results obtained using 50 manually labeled video frames. This demonstrates that the pig part recognition results generated by the method of this invention can serve as training labels for downstream keypoint detection models, and the training data can be expanded by increasing the number of unlabeled video frames.

[0109] Using AP-10K animal pose data and training with 50 manually annotated video frames, the Mean@0.1 of HRNet-w32, HRNet-w48, and ResNet-50 were 87.6%, 87.5%, and 79.5%, respectively. This training method achieves high recognition performance, but requires approximately 10,000 external images with multi-species manually annotated keypoints and 50 manually annotated video frames of pigs.

[0110] Without using external pose data, HRNet-w32, HRNet-w48, and ResNet-50, after training with 50 manually annotated video frames, achieved Mean@0.1 of 82.0%, 81.5%, and 80.4%, respectively. In Example 2, after training different downstream keypoint detection models using 200 pseudo-labels automatically generated by the method of this invention, Mean@0.1 ranged from 63.9% to 82.4%, with YOLO26M-Pose reaching 82.4%, which is at the same level as the results of the manually annotated training.

[0111] The above comparative results demonstrate that the method of this invention can directly identify the head, tail, and legs of pigs without using manually labeled keypoint data, and can use the identification results as pseudo-labels to expand the training data of downstream keypoint detection models. In pigsty scenarios lacking external pose data or manually labeled data, pseudo-labels for pig parts can be automatically generated using unlabeled video frames, reducing reliance on manual keypoint annotation and external pose data.

[0112] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for identifying zero-labeled body parts in pigs based on discrete Morse theory, characterized in that, include: S100: Obtain a video frame sequence containing pigs, and perform instance segmentation of the pigs in the video frame sequence based on text prompts using a visual basic model to obtain the binary mask and image embedding features of the pigs. S200: Predict the Euclidean distance transformed terrain field of the pig based on the image embedding features, and remove the background region in the Euclidean distance transformed terrain field based on the binary mask; S300: The Euclidean distance-transformed terrain field is used as a discrete Morse function, and the discrete Morse function value is scanned from high to low. The topological critical point and continuous homology value are determined based on the change in pixel connectivity during the scanning process. S400: The binary mask is refined to obtain an initial skeleton. The terminal branches in the initial skeleton are pruned according to the continuous homology value to obtain the pig topological skeleton. In S400, the specific steps of pruning the terminal branches in the initial skeleton according to the continuous homology value include: The binary mask is subjected to morphological opening and closing operations, and the processed binary mask is skeletonized to obtain an initial skeleton with a single pixel width. Traverse the terminal branches in the initial skeleton, determine the endpoint pixel of each terminal branch, determine the connected component to which the endpoint pixel belongs before the connected component is merged based on the belonging relationship of the endpoint pixel in the process of connected component generation and merging, and obtain the maximum value corresponding to the connected component and the continuous cohomology value corresponding to the maximum value. When the sustained coherence value is not lower than the preset sustained coherence threshold, the corresponding terminal branch is retained; When the sustained coherence value is lower than the preset sustained coherence threshold, and the pixel length of the corresponding end branch does not reach the long branch protection threshold, the corresponding end branch is deleted. When the sustained coherence value is lower than the preset sustained coherence threshold, and the pixel length of the corresponding terminal branch reaches the long branch protection threshold, the corresponding terminal branch is retained. Remove residual terminal branches whose pixel length is lower than the preset short branch length threshold after pruning to obtain the pig topological skeleton containing endpoints and bifurcation points. S500: Determine the pig center based on the Euclidean distance transformed topographic field, determine the head based on the pig center and the endpoints in the pig topological skeleton, identify the tail based on the direction of the head relative to the pig center and establish the pig body axis, identify the legs based on the position of the remaining endpoints relative to the pig body axis, and obtain the pig part identification result.

2. The method for zero-label identification of pig body parts based on discrete Morse theory according to claim 1, characterized in that, In S100, the specific steps of segmenting pigs in the video frame sequence based on text prompts using a visual base model include: The pig target is initialized in the first frame of the video frame sequence with a text prompt corresponding to the pig; The parameters of the visual base model are kept frozen, and the pig target is segmented by the visual base model to obtain the corresponding binary mask and image embedding features. Based on the pig target initialized in the first frame of the video frame sequence, the corresponding pigs in the subsequent video frames of the video frame sequence are tracked and segmented to obtain the binary mask and image embedding features corresponding to each pig in the subsequent video frames.

3. The method for zero-label identification of pig body parts based on discrete Morse theory according to claim 1, characterized in that, In S200, the specific steps of predicting the Euclidean distance transformed terrain field of the pig based on the image embedding features include: The image embedding features are input into a cascaded convolutional network head, which includes a first convolutional layer, a second convolutional layer, and a third convolutional layer connected in sequence. The first and second convolutional layers are sequentially processed by convolution, grouping normalization, and ReLU activation, and the third convolutional layer is processed by convolution and Sigmoid activation to obtain a single-channel normalized terrain field. The normalized terrain field is upsampled to the original resolution of the corresponding video frame in the video frame sequence and multiplied pixel by pixel with the binary mask to obtain the Euclidean distance transformed terrain field with the background area removed.

4. The method for zero-label identification of pig body parts based on discrete Morse theory according to claim 3, characterized in that, In S200, the cascaded convolutional network head used to predict the Euclidean distance-transformed terrain field is trained through the following steps: Based on the binary mask obtained by instance segmentation of the training video using the aforementioned visual foundation model, the Euclidean distance transformation result corresponding to the binary mask is calculated, and the Euclidean distance transformation result is normalized to obtain the supervised terrain field. The image embedding features output by the visual base model are input into the head of the cascaded convolutional network to obtain a normalized terrain field. Within the region corresponding to the binary mask, calculate the mean square error loss between the normalized terrain field and the supervised terrain field; Keep the parameters of the visual base model frozen, and update the parameters of the cascaded convolutional network head according to the mean squared error loss.

5. The method for zero-label identification of pig body parts based on discrete Morse theory according to claim 1, characterized in that, In S300, the specific steps for determining the topological critical point and the sustained coherence value based on the changes in pixel connectivity during the scanning process include: Sort all pixels within the region corresponding to the binary mask from high to low according to their corresponding discrete Morse function values ​​and scan them sequentially. For the currently scanned pixel, determine the adjacency relationship between the currently scanned pixel and the already formed connected components; When the currently scanned pixel is not adjacent to any existing connected component, a new connected component is established based on the currently scanned pixel, and the currently scanned pixel is determined as a maximum value; When the currently scanned pixel is adjacent to only one established connected component, the currently scanned pixel is incorporated into the connected component; When the current scanned pixel is adjacent to two or more different connected components at the same time, the current scanned pixel is determined as a saddle point, and the two or more different connected components are merged into the same connected component through the current scanned pixel; When merging two or more different connected components, the connected component with the highest discrete Morse function value corresponding to the maximum value among the connected components participating in the merger is retained, and the maximum values ​​corresponding to the remaining connected components participating in the merger are paired with the saddle point respectively. Based on the difference between the discrete Morse function value corresponding to the maximum value paired with the saddle point and the discrete Morse function value corresponding to the saddle point, the continuous homology value corresponding to each maximum value paired with the saddle point is determined.

6. The method for zero-label identification of pig body parts based on discrete Morse theory according to claim 5, characterized in that, In S300, the step of scanning according to the discrete Morse function values ​​from high to low includes: For pixels with the same discrete Morse function value, the interconnected pixels are merged into a pixel set according to the pixel adjacency relationship; For each set of pixels, the set of pixels is treated as a whole, and the adjacency relationship between the set of pixels and the formed connected components is determined. When the pixel set is not adjacent to any existing connected component, a new connected component is established based on the pixel set, the pixel set is determined as a maximum region, and the centroid position of the pixel set is determined as the maximum position corresponding to the new connected component. When the pixel set is adjacent to only one existing connected component, the pixel set is incorporated into the connected component; When the pixel set is adjacent to two or more different connected components at the same time, the corresponding saddle point is determined, and the two or more different connected components are merged into the same connected component through the pixel set.

7. The method for zero-label identification of pig body parts based on discrete Morse theory according to claim 1, characterized in that, In S500, the specific steps of determining the head based on the pig's center and the endpoints in the pig's topological skeleton include: Determine the set of pixels with the maximum discrete Morse function value within the region corresponding to the binary mask, and determine the pig center based on the centroid position of the pixel set; Obtain the endpoints in the topological skeleton of the pig, and normalize the distance from each endpoint to the center of the pig and the discrete Morse function value corresponding to each endpoint to obtain the normalized distance and normalized discrete Morse function value corresponding to each endpoint. The normalized distance and the normalized discrete Morse function value are weighted and combined to obtain a comprehensive score for each endpoint, and the endpoint with the highest comprehensive score is determined as the head candidate. The nearest bifurcation point to the head candidate is determined along the pig's topological skeleton. When the distance between the bifurcation point and the head candidate is not greater than a preset ratio of the distance between the head candidate and the center of the pig, the bifurcation point is determined as the head. When the distance between the bifurcation point and the head candidate is greater than a preset ratio of the distance between the head candidate and the center of the pig, the head candidate is determined as the head.

8. A method for zero-label identification of pig body parts based on discrete Morse theory according to claim 7, characterized in that, In S500, the specific steps for identifying the tail based on the direction of the head relative to the center of the pig include: Determine the head direction from the center of the pig to the head; Obtain the remaining endpoints other than the head candidate, and determine the candidate directions pointing from the center of the pig to each remaining endpoint; Remove remaining endpoints whose distance from the center of the pig is less than a preset center distance threshold; Calculate the cosine similarity between the candidate direction and the head direction respectively, and determine the remaining endpoint with the smallest cosine similarity as the tail.

9. A method for zero-label identification of pig body parts based on discrete Morse theory according to claim 8, characterized in that, In S500, the specific steps of identifying the leg based on the position of the remaining endpoint relative to the pig's body axis include: The pig's body axis is determined by the direction of the line connecting the head and the center of the pig, and the normal axis is determined by the direction perpendicular to the pig's body axis. A local coordinate system aligned with the pig's orientation is established. Obtain the remaining endpoints excluding the head candidate and the tail, and project the remaining endpoints onto the normal axis; Based on the pig outline formed by the binary mask and the distribution of the remaining endpoints on both sides of the pig's body axis, the ventral and dorsal sides of the pig's body axis are determined. Retain the remaining endpoints located on the ventral side of the pig's body axis and remove the remaining endpoints located on the dorsal side of the pig's body axis; Remove any remaining endpoints whose distance from the head or tail is less than a preset head-to-tail distance threshold, and define the remaining endpoints as legs.

Citation Information

Patent Citations

  • Hybrid modeling method based on discrete Morse theory feature recognition

    CN115935447A

  • Structure-first image compression method

    CN120496756A