Multi-target pig trajectory tracking control method, device, equipment and medium

By training an oriented rotating box detection model using sequential vertex representation and angle-weighted loss function, and combining it with extended state Kalman filter and orientation outlier correction, the positioning accuracy and stability issues of multi-target tracking in pig farm environments are solved. This enables accurate tracking of pig trajectories and high-quality data output, supporting the refined management of smart farming.

CN122244089APending Publication Date: 2026-06-19SOUTH CHINA AGRICULTURAL UNIVERSITY

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SOUTH CHINA AGRICULTURAL UNIVERSITY
Filing Date
2026-03-20
Publication Date
2026-06-19

Smart Images

  • Figure CN122244089A_ABST
    Figure CN122244089A_ABST
Patent Text Reader

Abstract

This application relates to a method, apparatus, device, and medium for multi-target pig trajectory tracking and control. The method includes: extracting historical orientation angles of the target pig that have undergone head-tail orientation correction from historical trajectory state data of multiple frames of pigsty images to construct a historical information window; calculating the circumferential median of the historical orientation angles within the historical information window to determine a reference orientation angle; calculating the shortest arc length difference between the first orientation angle and the reference orientation angle; performing a flip correction on the first orientation angle based on the shortest arc length difference to generate a second orientation angle; and outputting second rotated bounding box data containing the target pig's position, target pig size, and the second orientation angle; matching the second rotated bounding box data with trajectory prediction data; and if the match is successful, outputting trajectory tracking and control data that fuses the pig's identity identifier, continuous temporal horizontal and vertical coordinates, and the second orientation angle. This application solves the problems of ambiguous target pig detection orientation and incomplete tracking status in existing technologies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of smart farming, and in particular to a multi-target pig trajectory tracking and control method, corresponding device, electronic equipment and computer-readable storage medium. Background Technology

[0002] In modern precision animal husbandry, automated and stress-free monitoring of individual pigs is crucial for achieving refined management, improving breeding efficiency, and enhancing animal welfare. Multi-target tracking (MOT) technology, as a core visual tool, aims to assign a unique identification (ID) to each pig in a herd and continuously track its spatiotemporal trajectory. This trajectory data forms the basis for downstream applications such as individual feed intake statistics, drinking behavior monitoring, social interaction analysis, and early warning of health abnormalities (e.g., lameness, aggressive behavior). However, existing MOT technologies face two major technical bottlenecks when applied in real, high-density pig housing environments:

[0003] Limitations of target representation and the problem of directional ambiguity. Traditional horizontal bounding boxes (HBBs) often include a large amount of background or parts of other individuals' bodies when pigs are crowded, resulting in poor localization accuracy. Although the subsequently developed rotated bounding boxes (RBBs) can fit the pig's body contour more closely, they have an inherent 180-degree periodicity, meaning that a box rotated 180 degrees has the same parametric representation as the original box. This causes the algorithm to be unable to distinguish between the pig's head and tail. This directional ambiguity is a fatal flaw in existing technology, making it impossible to distinguish between feeding behavior "head-to-trough" and random approaching behavior "tail-to-trough," and between benign social interaction "head-to-head" and aggressive tail biting "head-to-tail."

[0004] Tracking target state variables suffers from incomplete motion states and poor tracking stability. Current mainstream 2D ​​bounding box tracking only tracks the position of the bounding box (i.e., horizontal and vertical coordinates). However, a pig's complete motion includes its orientation angle. Because the bounding box lacks unambiguous head and tail orientation angles, and the trajectory tracker does not include orientation states, trajectory tracking results in incomplete motion tracking. Furthermore, current mainstream "tracking-by-detection" methods, such as the SORT framework and its variants, are highly dependent on the quality of each frame's detection results.

[0005] In the complex environment of pigsties, due to changes in lighting and frequent body occlusion between pigs, detectors inevitably produce occasional and erroneous outputs, especially errors in orientation angles (for example, due to a brief head occlusion, the detector may output an orientation that is nearly 180 degrees flipped compared to the previous frame). When these anomalous observations are directly fed into the Kalman filter used as the motion model, the state estimation inside the filter is quickly contaminated, resulting in "state divergence," which in turn causes serious deviations in trajectory prediction. This ultimately manifests as frequent identity switching (IDSW) or tracking loss, severely compromising the continuity and reliability of trajectory data.

[0006] In summary, when abnormal observations such as changes in lighting, frequent body occlusion between pigs, and errors in orientation angles are directly fed into the Kalman filter used as a motion model in existing technologies, the state estimation inside the filter is quickly contaminated, resulting in "state divergence" and causing serious deviations in trajectory prediction. The applicant has made corresponding explorations to address this problem. Summary of the Invention

[0007] The purpose of this application is to solve the above-mentioned problems by providing a multi-target pig trajectory tracking and control method, corresponding device, electronic device and computer-readable storage medium.

[0008] To achieve the various objectives of this application, the following technical solution is adopted:

[0009] A multi-objective pig trajectory tracking control method proposed for one of the purposes of this application includes:

[0010] Acquire images of pigsties containing multiple target pigs to be detected;

[0011] The image of the pigsty to be detected is input into a directional rotating bounding box detection model that is trained to convergence using a sequential vertex representation to define the rotating bounding box of the target pig and an angle-weighted loss function, so as to output the first rotating bounding box data containing the position of the target pig, the size of the target pig, and the first orientation angle.

[0012] Extract the historical orientation angles of the target pig that have completed head-tail orientation correction from the historical trajectory status data of the pig house images in multiple frames to construct a historical information window. Calculate the circumferential median of the historical orientation angles within the historical information window to determine the reference orientation angle. Calculate the shortest circumferential arc length difference between the first orientation angle and the reference orientation angle. Based on the shortest circumferential arc length difference, perform a flip correction on the first orientation angle to generate a second orientation angle. Output the second rotated bounding box data containing the target pig's position, target pig size, and the second orientation angle.

[0013] A multidimensional state vector is determined, which includes the target pig's position, target pig size, second orientation angle, and the first-order angular velocity corresponding to the second orientation angle. The multidimensional state vector is input into a preset extended state Kalman filter, and based on the historical trajectory state data of the target pig, the motion state and rotation state corresponding to the next frame of the pig house image are predicted, generating trajectory prediction data including the predicted target position, predicted target size, and third orientation angle.

[0014] The second rotated bounding box data is matched with the trajectory prediction data. If the match is successful, the pig identification corresponding to the target pig is bound. At the same time, the second rotated bounding box data is used as an observation value and input into the extended state Kalman filter. The historical trajectory state data is updated in combination with the trajectory prediction data to determine the current trajectory state data. Based on the current trajectory state data, trajectory tracking control data that fuses the pig identification, continuous time-series horizontal and vertical coordinates, and the second direction angle is output.

[0015] Optionally, the step of defining the rotated bounding box of the target pig using sequential vertex representation includes:

[0016] The preset sequential vertex representation is invoked to determine multiple vertices of the rotating bounding box corresponding to the target pig in the pigsty image to be detected, and the multiple vertices are encoded in a clockwise or counterclockwise order so that the encoding order of the multiple vertices forms a unique mapping relationship with the head and tail orientation of the target pig.

[0017] Based on the coordinates of multiple vertices after ordered encoding, the target pig position, target pig size, and first orientation angle of the rotated bounding box are calculated.

[0018] Optionally, the steps for constructing the angle-weighted loss function include:

[0019] Obtain the basic loss term for target detection used to calculate the localization and classification deviation between the predicted and actual rotated bounding boxes;

[0020] An angle penalty loss term is constructed based on the cosine of the difference between the predicted and actual directions of the target pigs, in order to apply a targeted penalty to the direction prediction deviation.

[0021] By introducing a loss balancing hyperparameter, the target detection basic loss term and the angle penalty loss term are weighted and fused to obtain the angle-weighted loss function, thus completing the construction of the angle-weighted loss function.

[0022] Optionally, the step of extracting historical orientation angles from the historical trajectory state data of the target pig in multi-frame pigpen images, after head-tail orientation correction, to construct a historical information window, and calculating the circumferential median of the historical orientation angles within the historical information window to determine the reference orientation angle, includes:

[0023] For the target pig whose orientation angle needs to be corrected, extract the historical orientation angle of the target pig that has already been corrected for head and tail orientation in the historical trajectory state data of the target pig in multiple frames of pig house images;

[0024] Based on a preset window length, the historical orientation angles are filtered to construct a historical information window that characterizes the stable orientation features of the target pig;

[0025] Calculate the shortest arc distance from the candidate orientation angle to each historical orientation angle within the historical information window, take the candidate orientation angle with the smallest sum of the shortest arc distances as the median of the circle, and use the median of the circle as the reference orientation angle for correcting the head and tail orientation of the target pig.

[0026] Optionally, the step of calculating the difference in the shortest circumferential arc length between the first orientation angle and the reference orientation angle, and performing a flip correction on the first orientation angle based on the difference in the shortest circumferential arc length to generate the second orientation angle, includes:

[0027] Obtain the first direction angle and the reference direction angle corresponding to the target pig;

[0028] The shortest arc length difference between the first direction angle and the reference direction angle is calculated and determined, wherein the shortest arc length difference represents the shortest arc length distance between the first direction angle and the reference direction angle within the circumference.

[0029] Determine whether the difference in the shortest arc length of the circumference exceeds a preset arc length threshold. If it does, perform a 180-degree flip correction on the first direction angle to generate the second direction angle of the target pig. If it does not exceed the threshold, use the first direction angle as the second direction angle of the target pig.

[0030] Optionally, the step of matching the second rotated bounding box data with the trajectory prediction data further includes:

[0031] If the second rotated bounding box data does not match the trajectory prediction data, new trajectory status data is initialized based on the second rotated bounding box data, and a unique pig identification identifier is assigned to the new trajectory status data; at the same time, historical tracking trajectories that have not matched any second rotated bounding box data for a long time are deleted.

[0032] Optionally, the basic network architecture of the directional rotating bounding box detection model is a target detection model; the rotating bounding box represents the spatial position and head-tail orientation of the target pig; the first orientation angle is the orientation angle of the rotating bounding box corresponding to the target pig, used to represent the head-tail orientation of the target pig.

[0033] A multi-target pig trajectory tracking and control device provided for another purpose of this application includes:

[0034] The pigsty image acquisition module is configured to acquire images of pigsties to be detected that contain multiple target pigs;

[0035] The first data determination module is configured to input the pigsty image to be detected into a directional rotating bounding box detection model that uses sequential vertex representation to define the rotating bounding box of the target pig and an angle-weighted loss function to train to convergence, so as to output the first rotating bounding box data containing the position of the target pig, the size of the target pig, and the first orientation angle.

[0036] The second data determination module is configured to extract the historical orientation angles of the target pig that have completed head-tail orientation correction in the historical trajectory status data of the target pig in multi-frame pig house images, construct a historical information window, calculate the circumferential median of the historical orientation angles in the historical information window to determine a reference orientation angle, calculate the difference in the shortest circumferential arc length between the first orientation angle and the reference orientation angle, perform flip correction on the first orientation angle according to the difference in the shortest circumferential arc length to generate a second orientation angle, and output a second rotated bounding box data containing the position of the target pig, the size of the target pig, and the second orientation angle;

[0037] The trajectory prediction data determination module is configured to determine a multi-dimensional state vector containing the target pig's position, target pig size, second orientation angle, and the first-order angular velocity corresponding to the second orientation angle; input the multi-dimensional state vector into a preset extended state Kalman filter, and based on the historical trajectory state data of the target pig, predict the motion state and rotation state corresponding to the next frame of the pig house image, and generate trajectory prediction data containing the predicted target position, predicted target size, and third orientation angle;

[0038] The trajectory tracking control module is configured to match the second rotated bounding box data with the trajectory prediction data. If the match is successful, it binds the pig identification identifier corresponding to the target pig. At the same time, it inputs the second rotated bounding box data as an observation value into the extended state Kalman filter, and updates the historical trajectory state data in combination with the trajectory prediction data to determine the current trajectory state data. Based on the current trajectory state data, it outputs trajectory tracking control data that fuses the pig identification identifier, continuous time-series horizontal and vertical coordinates, and the second direction angle.

[0039] An electronic device provided for another purpose of this application includes a central processing unit and a memory, the central processing unit being configured to invoke and run a computer program stored in the memory to perform the steps of the multi-target pig trajectory tracking control method of this application.

[0040] A computer-readable storage medium is provided for another purpose of this application, which stores, in the form of computer-readable instructions, a computer program implemented according to the multi-target pig trajectory tracking and control method, which, when called by a computer, executes the steps included in the corresponding method.

[0041] Compared to existing technologies, this application addresses the problem that when abnormal observations, such as changes in lighting, frequent body occlusion between pigs, and errors in orientation angles, are directly fed into the Kalman filter used as a motion model, the state estimation inside the filter is rapidly contaminated, resulting in "state divergence" and thus causing serious deviations in trajectory prediction. This application provides, but is not limited to, the following beneficial effects:

[0042] Firstly, this application uses the sequential vertex representation method to define the rotating bounding box, binding a unique mapping relationship between the pig's head and tail orientation to the rotating box at the geometric representation level. It then trains the oriented rotating bounding box detection model using an angle-weighted loss function, ensuring that the first orientation angle output by the detection has unambiguous head and tail pointing meaning. Furthermore, it achieves precise correction of the orientation angle through the difference between the median of the circumference and the shortest arc length, and the final output second orientation angle further guarantees the accuracy of the orientation information. Compared to the shortcomings of existing rotating bounding boxes, which have a 180-degree periodicity and cannot distinguish between the pig's head and tail, this application achieves a complete representation of the pig's position, size, and precise head and tail orientation in a 2D pixel plane, filling the gap in the orientation perception dimension of existing technologies.

[0043] Secondly, this application inputs a multi-dimensional state vector, including the second orientation angle and its first-order angular velocity, into an extended state Kalman filter, incorporating the pig's rotational motion into the Kalman filter's prediction and update system. This overcomes the limitation of existing mainstream tracking methods that only track the pig's horizontal and vertical coordinates and ignore rotational motion, allowing the tracker to understand and accurately predict the pig's rotational posture changes. This design enables the trajectory prediction data to include not only position and size predictions but also to output accurate third orientation angles, achieving prediction of the pig's full motion state, including translation and rotation, thus ensuring the completeness and accuracy of trajectory prediction at the model level.

[0044] Thirdly, this application designs a dedicated direction outlier correction mechanism before updating the Kalman filter state. A stable reference direction angle is determined by the median of the historical information window, effectively identifying large-amplitude direction detection errors in a single frame. Furthermore, outlier correction is used to "clean up" the outliers, preventing erroneous direction observations from directly contaminating the internal state of the Kalman filter. This mechanism fundamentally prevents tracking state divergence, solving the pain points of existing technologies such as trajectory prediction bias, frequent identity switching (IDSW), and tracking loss caused by detection errors. Even in complex piggery environments with crowded herds, mutual occlusion, and varying lighting, it enables long-term, highly stable tracking of pig populations, significantly improving the robustness of multi-target tracking and the continuity of trajectory data.

[0045] Fourth, the trajectory tracking and control data output by this application integrates the unique identification of each pig, continuous temporal horizontal and vertical coordinates, and precise second orientation angles, providing a high-quality, multi-dimensional data foundation for downstream refined applications in smart farming that is unavailable from existing technologies. Based on this data, various precision farming management applications can be directly developed: precise statistics of individual feeding time can be obtained by determining the duration of a pig's head facing the feeding trough, enabling refined management of feed intake; timely warnings of aggressive abnormal behaviors such as tail biting can be issued by identifying "head-to-tail" contact patterns; early warnings of health abnormalities can be achieved by analyzing the orientation consistency of the pig herd; and social interaction behaviors of pigs can be analyzed based on continuous directional and positional trajectories. The implementation of these applications can effectively improve the level of refined management in pig farming, contributing to both improved farming efficiency and animal welfare. Attached Figure Description

[0046] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein:

[0047] Figure 1 This is a flowchart illustrating the multi-target pig trajectory tracking and control method in the embodiments of this application;

[0048] Figure 2 This is a flowchart of the multi-target pig trajectory tracking control method in the embodiments of this application;

[0049] Figure 3 This is a schematic diagram illustrating the annotation of the rotated bounding box corresponding to the target pig using the sequential vertex representation method in an embodiment of this application;

[0050] Figure 4 This is a schematic diagram of the directional outlier correction mechanism in the embodiments of this application;

[0051] Figure 5 This is a schematic diagram of the multi-target pig trajectory tracking and control device in the embodiments of this application;

[0052] Figure 6 This is a schematic diagram of the structure of the computer device in the embodiments of this application. Detailed Implementation

[0053] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application.

[0054] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this application means the presence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. It should be understood that when we say an element is “connected” or “coupled” to another element, it can be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein can include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any units and all combinations of one or more associated listed items.

[0055] Those skilled in the art will understand that, unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains. It should also be understood that terms such as those defined in general dictionaries should be understood to have the same meaning as in the context of the prior art, and should not be interpreted in an idealized or overly formal sense unless specifically defined as herein.

[0056] Those skilled in the art will understand that the terms "client," "terminal," and "terminal device" as used herein include both devices that receive wireless signals, devices that only possess wireless signal receiver capabilities without transmission capabilities, and devices with receiving and transmitting hardware, devices that have receiving and transmitting hardware capable of bidirectional communication over a bidirectional communication link. Such devices may include: cellular or other communication devices such as personal computers or tablets, having single-line displays, multi-line displays, or cellular or other communication devices without multi-line displays; PCS (Personal Communications Service) that can combine voice, data processing, fax, and / or data communication capabilities; PDAs (Personal Digital Assistants) that may include radio frequency receivers, pagers, internet / intranet access, web browsers, notebooks, calendars, and / or GPS (Global Positioning System) receivers; and conventional laptops and / or handheld computers or other devices that have and / or include radio frequency receivers. As used herein, "client," "terminal," and "terminal device" can be portable, transportable, installed in a means of transportation (air, sea, and / or land), or suitable and / or configured to operate locally and / or in a distributed manner, operating in any other location on Earth and / or in space. "Client," "terminal," and "terminal device" as used herein can also be a communication terminal, an internet access terminal, or a music / video playback terminal, such as a PDA, a MID (Mobile Internet Device), and / or a mobile phone with music / video playback capabilities, or a smart TV, set-top box, etc.

[0057] The hardware referred to by the names "server," "client," and "service node" in this application is essentially an electronic device with the equivalent capabilities of a personal computer. It is a hardware device with the necessary components revealed by the von Neumann architecture, such as a central processing unit (including an arithmetic logic unit and a control unit), memory, input devices, and output devices. The computer program is stored in its memory, and the central processing unit loads the program stored in the secondary storage into the main memory to run it, execute the instructions in the program, and interact with the input and output devices to complete specific functions.

[0058] It should be noted that the concept of "server" used in this application can also be extended to the case of server clusters. Based on the network deployment principles understood by those skilled in the art, the servers should be logically divided. Physically, these servers can be independent of each other but accessible through interfaces, or they can be integrated into a single physical computer or a computer cluster. Those skilled in the art should understand this flexibility and should not use it to constrain the implementation of the network deployment method in this application.

[0059] One or more of the technical features of this application, unless explicitly specified herein, can be deployed on a server and accessed by a client remotely calling the online service interface provided by the server, or can be directly deployed and run on a client for access.

[0060] Unless otherwise specified, the neural network models referenced or potentially referenced in this application may be deployed on a remote server and invoked remotely on the client, or deployed on a client with the capability to invoke directly. In some embodiments, when running on the client, the corresponding intelligence may be acquired through transfer learning in order to reduce the requirements on the client's hardware resources and avoid excessive consumption of the client's hardware resources.

[0061] Unless otherwise specified, all data involved in this application may be stored remotely on a server or on a local terminal device, as long as it is suitable for use by the technical solution of this application.

[0062] Those skilled in the art will understand that although the various methods in this application are described based on the same concept and thus present commonality among them, they can be performed independently unless otherwise specified. Similarly, the various embodiments disclosed in this application are all based on the same inventive concept; therefore, concepts expressed in the same way, as well as concepts that are appropriately changed for convenience but are expressed differently, should be understood equivalently.

[0063] Unless otherwise expressly stated, the various embodiments disclosed in this application can be combined in a cross-cutting manner to flexibly construct new embodiments, as long as such combination does not depart from the inventive spirit of this application and can meet the needs of the prior art or solve a certain deficiency in the prior art. Those skilled in the art should be aware of such modifications.

[0064] Please see Figure 1 The multi-target pig trajectory tracking control method of this application, in one embodiment, includes:

[0065] Step S10: Obtain an image of the pigsty to be detected containing multiple target pigs;

[0066] A multi-target pig trajectory tracking and control system in a terminal device can acquire images of a pigsty containing multiple target pigs. Specifically, the multi-target pig trajectory tracking and control system includes a direction detection module and a robust tracking module. The direction detection module is configured to perform deep learning model inference on the input pigsty image and output a rotated bounding box containing head and tail orientation information for each target pig. The robust tracking module is connected to the direction detection module and includes an extended state Kalman filter, an orientation outlier corrector, and a data association unit. The extended state Kalman filter's state vector includes the pig's orientation angle and angular velocity in addition to the horizontal and vertical coordinates, used to predict and update the motion and rotation states of the tracking trajectory. The orientation outlier corrector is configured to receive newly detected orientation angles before the Kalman filter is updated, and identify and correct abnormal orientation angles by comparing them with historical trajectory orientation information. The data association unit is used to match the corrected detection results with the trajectory predicted by the Kalman filter.

[0067] Step S20: Input the image of the pigsty to be detected into a directional rotating bounding box detection model that uses sequential vertex representation to define the rotating bounding box of the target pig and an angle-weighted loss function to train until convergence, so as to output the first rotating bounding box data containing the position of the target pig, the size of the target pig and the first direction angle;

[0068] After acquiring images of a pigsty containing multiple target pigs, the images are input into a convergent directional rotation box detection model trained using a sequential vertex representation to define the rotated bounding boxes of the target pigs and an angle-weighted loss function. The model outputs first rotated bounding box data containing the target pig's position, size, and a first orientation angle. The basic network architecture of the directional rotation box detection model is a target detection model. The rotated bounding box represents the spatial position and head-tail orientation of the target pig. The first orientation angle is the orientation angle of the rotated bounding box corresponding to the target pig, used to represent the head-tail orientation of the target pig. The target pig's position represents the coordinates of the center point of the target pig's rotated bounding box, and the target pig's size represents the width and height of the target pig's rotated bounding box.

[0069] In some embodiments, the target detection model refers to a computer vision model built on a deep learning architecture, used to automatically identify target categories and locate target spatial positions from images, including YOLO series models, Mask R-CNN models, etc.

[0070] In some embodiments, in the orientation detection module, this application employs Sequential-vertices (SV-OBB) to define the rotated bounding box. Unlike traditional rotated bounding boxes (RBB), this method strictly defines the arrangement order of the four vertices of the bounding box (e.g., clockwise or counterclockwise), and stipulates that the starting vertex is always located on the left side of the pig's head and distributed clockwise, thereby uniquely encoding the head and tail orientation of the target pig at the geometric representation level of data annotation and model output.

[0071] To enable the orientation-rotated bounding box detection model of this application to effectively learn this representation, the model is trained using an angle-weighted loss function. This angle-weighted loss function, in addition to measuring the geometric similarity between the predicted and ground truth bounding boxes, introduces a penalty term consisting of the dot product of their direction vectors. This penalty term reaches its maximum when the predicted direction is opposite to the ground truth direction, thereby applying a strong gradient during model optimization and forcing the model to learn and output the correct orientation angle.

[0072] In some embodiments, the step of defining the rotated bounding box of the target pig using sequential vertex representation includes:

[0073] Step S201: Call the preset sequential vertex representation method, for the target pig in the pigsty image to be detected, determine multiple vertices of the rotating bounding box corresponding to the target pig, and encode the multiple vertices in a clockwise or counterclockwise order, so that the encoding order of the multiple vertices forms a unique mapping relationship with the head and tail orientation of the target pig.

[0074] Step S202: Based on the coordinates of multiple vertices after ordered encoding, calculate the target pig position, target pig size, and first orientation angle of the rotated bounding box.

[0075] Specifically, in At any given moment, the multi-target pig trajectory tracking and control system receives a frame of image from the pigsty. Pigsty Images The orientation detection module, which receives input into the multi-target pig trajectory tracking and control system, please refer to... Figure 3 , adopt as Figure 3 The diagram shows the annotation of the rotated bounding box corresponding to the target pig using sequential vertex representation. When annotating the data, the four vertices are clicked in a clockwise order. and ensure the edge Always corresponding to the head region of the target pig, where the first vertex It is the top left corner of the target pig's head, the second corner. It is the top right corner of the target pig's head, with the four vertices arranged in a clockwise order, and the center point and the edge... The line connecting the midpoints is the directional angle vector.

[0076] As shown in steps S201 to S202 above, the sequential vertex representation method is used to define the rotated bounding box. By utilizing the unique mapping relationship between the vertex encoding order and the head and tail orientation of the pig, a precise and unambiguous representation of the spatial position and orientation of the target pig is achieved. This method effectively solves the orientation misjudgment problem caused by the ambiguity of the orientation definition in traditional rotated boxes, improves the accuracy and stability of orientation angle calculation, provides a solid data foundation for subsequent trajectory prediction and tracking control, and significantly enhances the robustness and accuracy of the multi-target pig tracking system.

[0077] In some embodiments, the step of constructing the angle-weighted loss function includes:

[0078] Step S2001: Obtain the basic loss term for target detection used to calculate the positioning and classification deviation between the predicted and actual rotated boxes;

[0079] Step S2002: Construct an angle penalty loss term based on the cosine of the difference between the predicted and actual directions of the target pig, so as to apply a targeted penalty to the direction prediction deviation.

[0080] Step S2003: Introduce loss balance hyperparameters, and perform weighted fusion of the target detection basic loss term and the angle penalty loss term to obtain the angle-weighted loss function, thereby completing the construction of the angle-weighted loss function.

[0081] Specifically, an angle-weighted loss function is used to train the orientation and rotation box detection model. This angle-weighted loss function can penalize incorrect orientation predictions and guide the model to output an orientation angle consistent with the orientation angle. .

[0082] Specifically, the total loss function A basic loss term for object detection A penalty loss item from one angle The weighted fusion yields the following expression:

[0083]

[0084] in, This represents the angle-weighted loss function, used for the overall optimization objective of model training, balancing the errors of localization, classification, and orientation prediction; This represents the basic loss term for object detection, which calculates the deviation between the model's predicted rotated box and the ground truth box in terms of object localization and category classification, such as errors in bounding box position, size, and category probability. This represents the loss balance hyperparameter, used to adjust the angle penalty loss term. The weights in the angle-weighted loss function control the degree of influence of the direction prediction error on model training. This represents the angle penalty loss term, a penalty term specifically designed to address orientation prediction bias, used to constrain the model output orientation angle to be consistent with the true orientation.

[0085] Furthermore, the angle penalty loss item The goal is to minimize the difference between the predicted and actual orientation angles, using an angle penalty loss term. The expression is represented as:

[0086]

[0087] in, This represents the angle penalty loss term; a larger value indicates a more severe deviation in direction prediction. This represents the model's predicted orientation angle, which is determined by the orientation rotation box detecting the head and tail orientation angles of the target pig output by the model. This indicates the actual orientation angle, which is the angle at which the head and tail of the target pig are actually facing, as manually labeled. This represents the angle difference between the predicted and actual direction angles, characterizing the deviation angle of the direction prediction. The cosine of the angle difference between the predicted and actual direction angles is used to measure the similarity between two direction vectors: when... When the predicted direction angle is completely consistent with the actual direction angle, then... The value is 1. When the value is 0, there is no direction penalty; when When the predicted direction angle is completely opposite to the actual direction angle, then... The value is −1. The value is 2, at which point the maximum directional penalty is applied.

[0088] In some embodiments, the network structure of the directional rotating box detection model integrates an attention mechanism module to enhance the model's ability to extract features from the visible parts of the pigs (such as the head, ears, and tail) when pigs occlude each other, thereby improving detection recall and accuracy. The output of the directional detection module is the detection result of each target pig detected in the current frame of the pigsty image. The constructed set of detection results Among them, the test results for each target pig Each contains the target pig's location, target pig size, and first orientation angle. The first rotated bounding box data. Subsequently, the detection result set. The data is input into the robust tracking module, which is responsible for comparing the new detection results with the existing historical trajectory data of pigs in the database. Establish a connection.

[0089] Step S30: Extract the historical orientation angles of the target pig that have completed head-tail orientation correction from the historical trajectory status data of the target pig in the multi-frame pig house images, construct a historical information window, calculate the circumferential median of the historical orientation angles in the historical information window to determine the reference orientation angle, calculate the difference in the shortest circumferential arc length between the first orientation angle and the reference orientation angle, perform flip correction on the first orientation angle according to the difference in the shortest circumferential arc length to generate the second orientation angle, and output the second rotated bounding box data containing the position of the target pig, the size of the target pig and the second orientation angle;

[0090] The pigsty image to be detected is input into a directional rotation box detection model trained to convergence using a sequential vertex representation to define the rotation bounding box of the target pig and an angle-weighted loss function. After outputting the first rotation bounding box data containing the target pig's position, target pig size, and first orientation angle, the historical orientation angles of the target pig that have completed head-tail orientation correction in the historical trajectory state data of the pigsty images of multiple frames are extracted to construct a historical information window. The circumferential median of the historical orientation angles in the historical information window is calculated to determine the reference orientation angle. The shortest circumferential arc length difference between the first orientation angle and the reference orientation angle is calculated. The first orientation angle is flipped and corrected according to the shortest circumferential arc length difference to generate a second orientation angle. The second rotation bounding box data containing the target pig's position, target pig size, and second orientation angle is output.

[0091] In some embodiments, this application designs an outlier correction mechanism for outlier repair and processing of input data before the Kalman filter state is updated. The specific steps of this mechanism are as follows: First, for a tracking trajectory to be updated, extract the relatively stable direction angles filtered over the past N frames to form a historical information window; second, calculate the circumferential median of all direction angles within the historical information window to obtain a reference direction angle unaffected by a single extreme value; then, calculate the shortest arc length distance between the first direction angle of the newly detected target pig in the current frame and the reference direction angle; finally, if the shortest arc length distance exceeds a preset arc length threshold (e.g., ...), ... If the first direction angle of the target pig is determined to be an outlier, it is corrected by flipping it 180 degrees to obtain a direction angle more consistent with the historical trajectory. Finally, this "cleaned" and reliable observation is used to update the Kalman filter. This mechanism effectively prevents instantaneous and erroneous detection directions from contaminating the tracking state, thereby preventing state divergence and greatly enhancing the stability and continuity of the trajectory.

[0092] In a specific embodiment, the steps of extracting historical orientation angles from the historical trajectory status data of the target pig in multi-frame pigpen images, which have already undergone head-tail orientation correction, to construct a historical information window, and calculating the median of the historical orientation angles within the historical information window to determine the reference orientation angle, include:

[0093] Step S301: For the target pig whose orientation angle needs to be corrected, extract the historical orientation angle of the target pig that has completed head and tail orientation correction in the historical trajectory state data of the target pig in multiple frames of pig house images;

[0094] For the target pig whose orientation angle needs to be corrected, the orientation outlier corrector in the robust tracking module is activated to extract the historical orientation angles that have been corrected for head and tail orientation from the historical trajectory status data of the past N frames of pig house images.

[0095] Step S302: Based on a preset window length, filter the historical orientation angles to construct a historical information window representing the stable orientation characteristics of the target pig;

[0096] Based on a preset window length, the above historical orientation angles are filtered to construct a historical information window that represents the stable orientation characteristics of the target pig.

[0097] Step S303: Calculate the shortest arc distance from the candidate direction angle to each historical direction angle within the historical information window, take the candidate direction angle with the smallest sum of the shortest arc distances as the median of the circle, and use the median of the circle as the reference direction angle for correcting the head and tail orientation of the target pig.

[0098] Iterate through the candidate orientation angles and calculate the shortest arc distance from each candidate orientation angle to each historical orientation angle within the historical information window. Take the candidate orientation angle with the smallest sum of shortest arc distances as the median of the circle, and use this median as the reference orientation angle for correcting the head and tail orientation of the target pig. .

[0099] In a further specific embodiment, the step of calculating the difference in the shortest circumferential arc length between the first direction angle and the reference direction angle, and performing a flip correction on the first direction angle based on the difference in the shortest circumferential arc length to generate the second direction angle, includes:

[0100] Step S3001: Obtain the first direction angle and reference direction angle corresponding to the target pig;

[0101] Step S3002: Calculate and determine the shortest circumferential arc length difference between the first direction angle and the reference direction angle, wherein the shortest circumferential arc length difference represents the shortest arc length distance between the first direction angle and the reference direction angle within the circumference.

[0102] Obtain the first direction angle corresponding to the target pig. With reference direction angle Calculate the first direction angle With reference direction angle The shortest arc distance within the circumference Its calculation formula is expressed as:

[0103] ;

[0104] in, The difference in the shortest arc length of the circle represents the shortest arc length distance between the first direction angle and the reference direction angle within the circumference, and is used to measure the direction deviation. The first orientation angle is the uncorrected head and tail orientation angle of the pig directly output by the model. Represents the reference orientation angle, a stable orientation reference value calculated from the circumferential median of historical orientation angles; This represents the absolute angular difference between the first direction angle and the reference direction angle; This represents the angle difference along the other side of the circumference, and the minimum of the two values ​​is taken to ensure that the angle difference is within the range specified by the circle. Within the range.

[0105] Step S3003: Determine whether the difference in the shortest arc length of the circumference exceeds a preset arc length threshold. If it does, perform a 180-degree flip correction on the first direction angle to generate the second direction angle of the target pig. If it does not exceed the threshold, use the first direction angle as the second direction angle of the target pig.

[0106] Determine the difference in the shortest arc length of the circumference Does it exceed the preset arc length threshold? If it exceeds, then the first direction angle is determined. If the first orientation angle is an outlier, a 180-degree flip correction is performed to generate a second orientation angle for the target pig. If the first orientation angle is not exceeded, the first orientation angle is used as the second orientation angle for the target pig. The formula for calculating the second orientation angle of the target pig is as follows:

[0107]

[0108] in, This represents the second orientation angle, the final reliable head and tail orientation angle of the pig after outlier correction; The first orientation angle is the uncorrected head and tail orientation angle of the pig directly output by the model. It represents pi (π) and signifies a 180-degree rotation. Modulus The calculation ensures that the corrected angle value remains constant. Within the effective circumference range, avoid angle overflow. The difference in the shortest arc length of the circle represents the shortest arc length distance between the first direction angle and the reference direction angle within the circumference, and is used to measure the direction deviation. This represents the preset arc length threshold, which can be set to... Those skilled in the art can determine the preset arc length threshold as needed based on the actual application scenario, without making any limitations here.

[0109] After correcting the orientation angle of the target pig using the above calculation formula, the output includes the target pig's position, target pig size, and second orientation angle. The second rotated bounding box data.

[0110] Step S40: Determine a multidimensional state vector containing the target pig's position, target pig size, second orientation angle, and the first-order angular velocity corresponding to the second orientation angle; input the multidimensional state vector into a preset extended state Kalman filter, and based on the historical trajectory state data of the target pig, predict the motion state and rotation state corresponding to the next frame of the pig house image, and generate trajectory prediction data containing the predicted target position, predicted target size, and third orientation angle;

[0111] A historical information window is constructed by extracting the historical orientation angles of the target pig in the historical trajectory state data of multi-frame pigpen images that have completed head-tail orientation correction. The median of the historical orientation angles within the historical information window is calculated to determine the reference orientation angle. The shortest arc length difference between the first orientation angle and the reference orientation angle is calculated. The first orientation angle is flipped and corrected according to the shortest arc length difference to generate a second orientation angle. After outputting the second rotation bounding box data containing the target pig's position, target pig size, and second orientation angle, a multidimensional state vector containing the target pig's position, target pig size, second orientation angle, and the first-order angular velocity corresponding to the second orientation angle is determined. The multidimensional state vector is input into a preset extended state Kalman filter. Based on the historical trajectory state data of the target pig, the motion state and rotation state corresponding to the next frame of the pigpen image are predicted, generating trajectory prediction data containing the predicted target position, predicted target size, and third orientation angle.

[0112] In some embodiments, to enable the tracker to understand and predict the rotational movement of the target pig, this application extends the standard Kalman filter to determine an extended state Kalman filter, incorporating a direction angle into its state vector. and angular velocity ( Wherein, the state vector Defined as a ten-dimensional column vector, its specific form is as follows:

[0113] ,

[0114] in, The coordinates of the center point of the rotated bounding box of the target pig; The x-coordinate of the center point of the rotated bounding box of the target pig; The ordinate of the center point of the rotated bounding box of the target pig; This indicates the width of the rotated bounding box of the target pig; Indicates the height of the rotated bounding box of the target pig; This indicates the orientation angle of the target pig, which represents the angle at which the pig's head and tail are facing. The first-order velocity, representing the x-coordinate of the center point of the rotating bounding box of the target pig, characterizes the rate of change of the pig's horizontal position over time. The first-order velocity of the ordinate of the center point of the rotating bounding box of the target pig represents the rate of change of the pig's vertical position over time. The first-order velocity of the width of the rotating bounding box of the target pig, and the rate of change of the longitudinal dimension of the pig over time; The first-order velocity of the height of the rotating bounding box of the target pig represents the rate of change of the pig's longitudinal dimension over time. This represents the first-order angular velocity of the target pig. This represents the transpose operator.

[0115] In some embodiments, for each target pig, the existing historical trajectory state data The multi-dimensional state vector, containing the target pig's position, size, second orientation angle, and the corresponding first-order angular velocity, is input into a preset extended state Kalman filter. Based on the target pig's historical trajectory data, the extended state Kalman filter predicts the motion and rotation states of the pigpen in the next frame, and predicts its position at the next moment. Trajectory prediction data including predicted target location, predicted target size, and third-order azimuth angle. .

[0116] Step S50: Match the second rotated bounding box data with the trajectory prediction data. If the match is successful, bind the pig identification corresponding to the target pig. At the same time, input the second rotated bounding box data as an observation into the extended state Kalman filter. Combine the trajectory prediction data to update the historical trajectory state data to determine the current trajectory state data. Based on the current trajectory state data, output trajectory tracking control data that fuses the pig identification, continuous time-series horizontal and vertical coordinates, and the second direction angle.

[0117] A multidimensional state vector is determined, containing the target pig's position, size, second orientation angle, and the first-order angular velocity corresponding to the second orientation angle. This multidimensional state vector is input into a preset extended state Kalman filter. Based on the target pig's historical trajectory state data, the motion and rotation states corresponding to the next frame of the pigpen image are predicted. Trajectory prediction data containing the predicted target position, size, and third orientation angle is generated. Then, second rotation bounding box data is matched with the trajectory prediction data. If the match is successful, the pig's identification identifier is bound to the target pig. Simultaneously, the second rotation bounding box data is input as an observation into the extended state Kalman filter. The historical trajectory state data is updated in conjunction with the trajectory prediction data to determine the current trajectory state data. Based on the current trajectory state data, trajectory tracking control data fusing the pig's identification identifier, continuous temporal horizontal and vertical coordinates, and the second orientation angle is output.

[0118] In some embodiments, the step of matching the second rotated bounding box data with the trajectory prediction data further includes:

[0119] If the second rotated bounding box data does not match the trajectory prediction data, new trajectory status data is initialized based on the second rotated bounding box data, and a unique pig identification identifier is assigned to the new trajectory status data; at the same time, historical tracking trajectories that have not matched any second rotated bounding box data for a long time are deleted.

[0120] In a specific embodiment, the data association unit is responsible for matching the second rotated bounding box data with the trajectory prediction data. This embodiment adopts a hierarchical matching strategy, which includes: first, matching the Kalman-predicted position with a high-confidence second rotated bounding box (using intersection-over-union ratio or Mahalanobis distance); then, for unmatched trajectories, attempting a second matching with a low-confidence second rotated bounding box to handle the decrease in detection confidence caused by occlusion. If the match is successful, the second rotated bounding box data is uniquely bound to the corresponding target pig identification, establishing an association between the detection data and the tracking trajectory; if the match is unsuccessful: a new tracking trajectory is initialized based on the second rotated bounding box data, and a unique pig identification is assigned to the new trajectory; historical tracking trajectories that have not been successfully matched with any second rotated bounding box data for a long time are deleted.

[0121] Furthermore, for successfully matched trajectory prediction data and second rotated bounding box data, the second rotated bounding box data is used as an observation input to the extended state Kalman filter. Combining the trajectory prediction data (predicted values) and the observations (second rotated bounding box data), the historical trajectory state data of the target pig is updated to determine the current trajectory state data. Finally, based on the current trajectory state data, trajectory tracking control data fusing pig identification, continuous temporal x and y coordinates, and the second orientation angle is output. For unmatched detection boxes, a new trajectory is initialized; for trajectories that have not matched for a long time, deletion is performed.

[0122] As can be seen from the above embodiments, compared with the prior art, this application addresses the problems in the prior art where abnormal observations, such as changes in lighting, frequent body occlusion between pigs, and errors in orientation angles, are directly fed into the Kalman filter used as a motion model, leading to rapid contamination of the state estimation inside the filter, resulting in "state divergence" and thus causing serious deviations in trajectory prediction. This application includes, but is not limited to, the following beneficial effects:

[0123] Firstly, this application uses the sequential vertex representation method to define the rotating bounding box, binding a unique mapping relationship between the pig's head and tail orientation to the rotating box at the geometric representation level. It then trains the oriented rotating bounding box detection model using an angle-weighted loss function, ensuring that the first orientation angle output by the detection has unambiguous head and tail pointing meaning. Furthermore, it achieves precise correction of the orientation angle through the difference between the median of the circumference and the shortest arc length, and the final output second orientation angle further guarantees the accuracy of the orientation information. Compared to the shortcomings of existing rotating bounding boxes, which have a 180-degree periodicity and cannot distinguish between the pig's head and tail, this application achieves a complete representation of the pig's position, size, and precise head and tail orientation in a 2D pixel plane, filling the gap in the orientation perception dimension of existing technologies.

[0124] Secondly, this application inputs a multi-dimensional state vector, including the second orientation angle and its first-order angular velocity, into an extended state Kalman filter, incorporating the pig's rotational motion into the Kalman filter's prediction and update system. This overcomes the limitation of existing mainstream tracking methods that only track the pig's horizontal and vertical coordinates and ignore rotational motion, allowing the tracker to understand and accurately predict the pig's rotational posture changes. This design enables the trajectory prediction data to include not only position and size predictions but also to output accurate third orientation angles, achieving prediction of the pig's full motion state, including translation and rotation, thus ensuring the completeness and accuracy of trajectory prediction at the model level.

[0125] Thirdly, this application designs a dedicated direction outlier correction mechanism before updating the Kalman filter state. A stable reference direction angle is determined by the median of the historical information window, effectively identifying large-amplitude direction detection errors in a single frame. Furthermore, outlier correction is used to "clean up" the outliers, preventing erroneous direction observations from directly contaminating the internal state of the Kalman filter. This mechanism fundamentally prevents tracking state divergence, solving the pain points of existing technologies such as trajectory prediction bias, frequent identity switching (IDSW), and tracking loss caused by detection errors. Even in complex piggery environments with crowded herds, mutual occlusion, and varying lighting, it enables long-term, highly stable tracking of pig populations, significantly improving the robustness of multi-target tracking and the continuity of trajectory data.

[0126] Fourth, the trajectory tracking and control data output by this application integrates the unique identification of each pig, continuous temporal horizontal and vertical coordinates, and precise second orientation angles, providing a high-quality, multi-dimensional data foundation for downstream refined applications in smart farming that is unavailable from existing technologies. Based on this data, various precision farming management applications can be directly developed: precise statistics of individual feeding time can be obtained by determining the duration of a pig's head facing the feeding trough, enabling refined management of feed intake; timely warnings of aggressive abnormal behaviors such as tail biting can be issued by identifying "head-to-tail" contact patterns; early warnings of health abnormalities can be achieved by analyzing the orientation consistency of the pig herd; and social interaction behaviors of pigs can be analyzed based on continuous directional and positional trajectories. The implementation of these applications can effectively improve the level of refined management in pig farming, contributing to both improved farming efficiency and animal welfare.

[0127] Please see Figure 5A multi-target pig trajectory tracking and control device provided for one of the purposes of this application includes a pigsty image acquisition module 1100, a first data determination module 1200, a second data determination module 1300, a trajectory prediction data determination module 1400, and a trajectory tracking and control module 1500. The system includes a pigsty image acquisition module 1100, configured to acquire a pigsty image containing multiple target pigs; a first data determination module 1200, configured to input the pigsty image to be detected into a convergent directional rotation box detection model trained using a sequential vertex representation to define the rotation bounding boxes of the target pigs and an angle-weighted loss function, to output first rotation bounding box data containing the target pig's position, target pig size, and first orientation angle; and a second data determination module 1300, configured to extract historical orientation angles of the target pigs that have completed head-tail orientation correction from the historical trajectory state data of multiple frames of pigsty images to construct a historical information window, calculate the circumferential median of the historical orientation angles within the historical information window to determine a reference orientation angle, calculate the shortest circumferential arc length difference between the first orientation angle and the reference orientation angle, perform flip correction on the first orientation angle based on the shortest circumferential arc length difference to generate a second orientation angle, and output a second data determination module containing the target pig's position, target pig size, and second orientation angle. The second rotating bounding box data; the trajectory prediction data determination module 1400 is configured to determine a multi-dimensional state vector containing the target pig's position, target pig size, second orientation angle, and the first-order angular velocity corresponding to the second orientation angle; input the multi-dimensional state vector into a preset extended state Kalman filter, and predict the motion state and rotation state corresponding to the next frame of the pig house image based on the historical trajectory state data of the target pig, generating trajectory prediction data containing the predicted target position, predicted target size, and third orientation angle; the trajectory tracking control module 1500 is configured to match the second rotating bounding box data with the trajectory prediction data, and if the match is successful, bind the pig identification corresponding to the target pig, and simultaneously input the second rotating bounding box data as an observation into the extended state Kalman filter, and update the historical trajectory state data in combination with the trajectory prediction data to determine the current trajectory state data; based on the current trajectory state data, output trajectory tracking control data that fuses the pig identification, continuous time-series horizontal and vertical coordinates, and the second orientation angle.

[0128] Based on any embodiment of this application, please refer to Figure 6 Another embodiment of this application also provides an electronic device, which can be implemented by a computer device, such as... Figure 6The diagram shows the internal structure of a computer device. The computer device includes a processor, a computer-readable storage medium, a memory, and a network interface connected via a system bus. The computer-readable storage medium stores an operating system, a database, and computer-readable instructions. The database may store control information sequences. When the computer-readable instructions are executed by the processor, they enable the processor to implement a multi-target pig trajectory tracking control method. The processor of the computer device provides computing and control capabilities, supporting the operation of the entire computer device. The memory of the computer device may store computer-readable instructions. When these computer-readable instructions are executed by the processor, they enable the processor to execute the multi-target pig trajectory tracking control method of this application. The network interface of the computer device is used for communication with a terminal. Those skilled in the art will understand that… Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0129] In this embodiment, the processor is used to execute... Figure 5 The specific functions of each module are defined within the device, and the memory stores the program code and various data required to execute these modules. A network interface is used for data transmission between the user terminal and the server. In this embodiment, the memory stores the program code and data required to execute all modules in the multi-target pig trajectory tracking and control device of this application, and the server can call the server's program code and data to execute the functions of all modules.

[0130] This application also provides a storage medium storing computer-readable instructions, which, when executed by one or more processors, cause the one or more processors to perform the steps of the multi-target pig trajectory tracking and control method described in any embodiment of this application.

[0131] This application also provides a computer program product, including a computer program / instructions that, when executed by one or more processors, implement the steps of the multi-target pig trajectory tracking and control method described in any embodiment of this application.

[0132] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. This computer program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. The aforementioned storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.

[0133] The above description is only a partial embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.

Claims

1. A multi-target pig trajectory tracking control method, characterized in that, include: Acquire images of pigsties containing multiple target pigs to be detected; The image of the pigsty to be detected is input into a directional rotating bounding box detection model that is trained to convergence using a sequential vertex representation to define the rotating bounding box of the target pig and an angle-weighted loss function, so as to output the first rotating bounding box data containing the position of the target pig, the size of the target pig, and the first orientation angle. Extract the historical orientation angles of the target pig that have completed head-tail orientation correction from the historical trajectory status data of the pig house images in multiple frames to construct a historical information window. Calculate the circumferential median of the historical orientation angles within the historical information window to determine the reference orientation angle. Calculate the shortest circumferential arc length difference between the first orientation angle and the reference orientation angle. Based on the shortest circumferential arc length difference, perform a flip correction on the first orientation angle to generate a second orientation angle. Output the second rotated bounding box data containing the target pig's position, target pig size, and the second orientation angle. A multidimensional state vector is determined, which includes the target pig's position, target pig size, second orientation angle, and the first-order angular velocity corresponding to the second orientation angle. The multidimensional state vector is input into a preset extended state Kalman filter, and based on the historical trajectory state data of the target pig, the motion state and rotation state corresponding to the next frame of the pig house image are predicted, generating trajectory prediction data including the predicted target position, predicted target size, and third orientation angle. The second rotated bounding box data is matched with the trajectory prediction data. If the match is successful, the pig identification corresponding to the target pig is bound. At the same time, the second rotated bounding box data is used as an observation value and input into the extended state Kalman filter. The historical trajectory state data is updated in combination with the trajectory prediction data to determine the current trajectory state data. Based on the current trajectory state data, trajectory tracking control data that fuses the pig identification, continuous time-series horizontal and vertical coordinates, and the second direction angle is output.

2. The multi-target pig trajectory tracking and control method according to claim 1, characterized in that, The steps for defining the rotated bounding box of the target pig using sequential vertex representation include: The preset sequential vertex representation is invoked to determine multiple vertices of the rotating bounding box corresponding to the target pig in the pigsty image to be detected, and the multiple vertices are encoded in a clockwise or counterclockwise order so that the encoding order of the multiple vertices forms a unique mapping relationship with the head and tail orientation of the target pig. Based on the coordinates of multiple vertices after ordered encoding, the target pig position, target pig size, and first orientation angle of the rotated bounding box are calculated.

3. The multi-target pig trajectory tracking control method according to claim 1, characterized in that, The steps to construct the angle-weighted loss function include: Obtain the basic loss term for target detection used to calculate the localization and classification deviation between the predicted and actual rotated bounding boxes; An angle penalty loss term is constructed based on the cosine of the difference between the predicted and actual directions of the target pigs, in order to apply a targeted penalty to the direction prediction deviation. By introducing a loss balancing hyperparameter, the target detection basic loss term and the angle penalty loss term are weighted and fused to obtain the angle-weighted loss function, thus completing the construction of the angle-weighted loss function.

4. The multi-target pig trajectory tracking and control method according to claim 1, characterized in that, The steps of extracting historical orientation angles from the historical trajectory status data of the target pig in multi-frame pigpen images, constructing a historical information window with head-tail orientation correction completed, and calculating the median of the historical orientation angles within the historical information window to determine the reference orientation angle include: For the target pig whose orientation angle needs to be corrected, extract the historical orientation angle of the target pig that has already been corrected for head and tail orientation in the historical trajectory state data of the target pig in multiple frames of pig house images; Based on a preset window length, the historical orientation angles are filtered to construct a historical information window that characterizes the stable orientation features of the target pig; Calculate the shortest arc distance from the candidate orientation angle to each historical orientation angle within the historical information window, take the candidate orientation angle with the smallest sum of the shortest arc distances as the median of the circle, and use the median of the circle as the reference orientation angle for correcting the head and tail orientation of the target pig.

5. The multi-target pig trajectory tracking and control method according to claim 1, characterized in that, The steps of calculating the difference in the shortest circumferential arc length between the first orientation angle and the reference orientation angle, and performing a flip correction on the first orientation angle based on the difference in the shortest circumferential arc length to generate the second orientation angle, include: Obtain the first direction angle and the reference direction angle corresponding to the target pig; The shortest arc length difference between the first direction angle and the reference direction angle is calculated and determined, wherein the shortest arc length difference represents the shortest arc length distance between the first direction angle and the reference direction angle within the circumference. Determine whether the difference in the shortest arc length of the circumference exceeds a preset arc length threshold. If it does, perform a 180-degree flip correction on the first direction angle to generate the second direction angle of the target pig. If it does not exceed the threshold, use the first direction angle as the second direction angle of the target pig.

6. The multi-target pig trajectory tracking and control method according to claim 1, characterized in that, The step of matching the second rotated bounding box data with the trajectory prediction data further includes: If the second rotated bounding box data does not match the trajectory prediction data, new trajectory status data is initialized based on the second rotated bounding box data, and a unique pig identification identifier is assigned to the new trajectory status data; at the same time, historical tracking trajectories that have not matched any second rotated bounding box data for a long time are deleted.

7. The multi-target pig trajectory tracking and control method according to any one of claims 1 to 6, characterized in that, The basic network architecture of the directional rotating bounding box detection model is a target detection model; the rotating bounding box represents the spatial position and head and tail orientation of the target pig; the first orientation angle is the orientation angle of the rotating bounding box corresponding to the target pig, used to represent the head and tail orientation of the target pig.

8. A multi-target pig trajectory tracking and control device, characterized in that, include: The pigsty image acquisition module is configured to acquire images of pigsties to be detected that contain multiple target pigs; The first data determination module is configured to input the pigsty image to be detected into a directional rotating bounding box detection model that uses sequential vertex representation to define the rotating bounding box of the target pig and an angle-weighted loss function to train to convergence, so as to output the first rotating bounding box data containing the position of the target pig, the size of the target pig, and the first orientation angle. The second data determination module is configured to extract the historical orientation angles of the target pig that have completed head-tail orientation correction in the historical trajectory status data of the target pig in multi-frame pig house images, construct a historical information window, calculate the circumferential median of the historical orientation angles in the historical information window to determine a reference orientation angle, calculate the difference in the shortest circumferential arc length between the first orientation angle and the reference orientation angle, perform flip correction on the first orientation angle according to the difference in the shortest circumferential arc length to generate a second orientation angle, and output a second rotated bounding box data containing the position of the target pig, the size of the target pig, and the second orientation angle; The trajectory prediction data determination module is configured to determine a multi-dimensional state vector containing the target pig's position, target pig size, second orientation angle, and the first-order angular velocity corresponding to the second orientation angle; input the multi-dimensional state vector into a preset extended state Kalman filter, and based on the historical trajectory state data of the target pig, predict the motion state and rotation state corresponding to the next frame of the pig house image, and generate trajectory prediction data containing the predicted target position, predicted target size, and third orientation angle; The trajectory tracking control module is configured to match the second rotated bounding box data with the trajectory prediction data. If the match is successful, it binds the pig identification identifier corresponding to the target pig. At the same time, it inputs the second rotated bounding box data as an observation value into the extended state Kalman filter, and updates the historical trajectory state data in combination with the trajectory prediction data to determine the current trajectory state data. Based on the current trajectory state data, it outputs trajectory tracking control data that fuses the pig identification identifier, continuous time-series horizontal and vertical coordinates, and the second direction angle.

9. An electronic device comprising a central processing unit and a memory, characterized in that, The central processing unit is used to invoke and run a computer program stored in the memory to perform the steps of the method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, It stores, in the form of computer-readable instructions, a computer program implemented according to any one of claims 1 to 7, which, when invoked by a computer, executes the steps included in the corresponding method.