Next Article in Journal
Quality of Red Clover Forage in Different Organic Production Systems
Next Article in Special Issue
Prediction of Feed Quantity for Wheat Combine Harvester Based on Improved YOLOv5s and Weight of Single Wheat Plant without Stubble
Previous Article in Journal
Effect of Photoperiod on Dry Matter Accumulation and Partitioning in Potato
Previous Article in Special Issue
Open-Set Sheep Face Recognition in Multi-View Based on Li-SheepFaceNet
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

RpTrack: Robust Pig Tracking with Irregular Movement Processing and Behavioral Statistics

1
College of Mathematics and Informatics, South China Agricultural University, Guangzhou 510642, China
2
College of Engineering, South China Agricultural University, Guangzhou 510642, China
*
Author to whom correspondence should be addressed.
Agriculture 2024, 14(7), 1158; https://doi.org/10.3390/agriculture14071158
Submission received: 23 May 2024 / Revised: 2 July 2024 / Accepted: 10 July 2024 / Published: 16 July 2024
(This article belongs to the Special Issue Computer Vision and Artificial Intelligence in Agriculture)

Abstract

:
Pig behavioral analysis based on multi-object tracking (MOT) technology of surveillance videos is vital for precision livestock farming. To address the challenges posed by uneven lighting scenes and irregular pig movements in the MOT task, we proposed a pig MOT method named RpTrack. Firstly, RpTrack addresses the issue of lost tracking caused by irregular pig movements by using an appropriate Kalman Filter and improved trajectory management. Then, RpTrack utilizes BIoU for the second matching strategy to alleviate the influence of missed detections on the tracking performance. Finally, the method utilizes post-processing on the tracking results to generate behavioral statistics and activity trajectories for each pig. The experimental results under conditions of uneven lighting and irregular pig movements show that RpTrack significantly outperforms four other state-of-the-art MOT methods, including SORT, OC-SORT, ByteTrack, and Bot-SORT, on both public and private datasets. The experimental results demonstrate that RpTrack not only has the best tracking performance but also has high-speed processing capabilities. In conclusion, RpTrack effectively addresses the challenges of uneven scene lighting and irregular pig movements, enabling accurate pig tracking and monitoring of different behaviors, such as eating, standing, and lying. This research supports the advancement and application of intelligent pig farming.

1. Introduction

Pig farming holds a significant position in the livestock industry. In the field of pig farming, the application of precision livestock farming can reduce production costs, enhance productivity, improve animal welfare, meet food demand, and boost economic benefits [1,2]. To achieve precision livestock farming for pigs, MOT technology is crucial for the pig industry. It enables timely monitoring of the health and behavior of pigs via individual pig re-identification and behavioral analysis in video surveillance [3]. This technology provides the foundation for the realization of precision pig farming.
In recent research, several MOT methods have been applied and expanded to the livestock industry. For example, Zhang et al. introduced an online method for detecting and tracking multiple pigs, which removed the need for manual annotations or actual pig IDs and operated effectively both in daytime and nighttime conditions [4]. Cowton et al. [5] integrated Faster R-CNN [6] with two online multi-object tracking techniques, namely SORT and DeepSORT [7], creating a comprehensive system for individual pig localization and tracking. This system also extracted behavior-related metrics from RGB camera data, achieving impressive performance with MOTA and IDF1 scores reaching 92% and 73.4%, respectively. Guo et al. [8] proposed a weighted association algorithm for three multi-object tracking methods, namely JDE [9], FairMOT [10], and YOLOv5s-DeepSORT, to optimize pig re-identification, improve tracking performance, and reduce ID switches. Tu et al. [11] combined YOLOv5 [12,13] with an improved DeepSORT algorithm to achieve highly accurate pig tracking, with a re-identification accuracy rate of up to 99.9%. Kim et al. improved YOLOv4 and DeepSORT to reduce computational expense while maintaining high accuracy in pig counting, which enabled real-time execution with an accuracy rate of 99.44% [14]. Odo et al. [15] utilized YOLOv4 [16] and YOLOv7 [17] detectors, combined with the DeepSORT and centroid tracking algorithms, to quantify ear-biting behavior in pigs. This approach achieved a detection accuracy of 98% and a tracking false positive rate of 14%. Han et al. proposed a detection-based tracking approach that utilized a YOLOv5 detector trained specifically for cattle detection to generate detection results. This method was designed to overcome challenges posed by scale variations, random movements, and occlusions in farm conditions when tracking cattle [18]. These algorithms all utilized the appearance information of targets during the association phase. However, due to the high similarity in appearance among the pigs’ targets in the scenes and the uneven lighting conditions, the appearance information of the targets might be unreliable. Additionally, using appearance information is time-consuming and may not yield significant benefits in such scenarios.
Therefore, there are many studies that do not use the appearance information of targets in the data association phase for pig MOT under video surveillance monitoring. Yigui et al. proposed an improved pig-counting algorithm based on the YOLOv5+DeepSORT model, which achieves stable pig counting in a breeding environment with a 98.4% pig-counting correlation coefficient [19]. Zheng et al. [20] proposed a MOT method that effectively addressed the issues of false negatives and false positives resulting from complex environmental conditions in individual cow detection and tracking. Van der Zande et al. [21] combined YOLOv3 [22] with the SORT algorithm to achieve pig detection and tracking to monitor individual pig activity. These algorithms only used the target’s motion information during the association phase, combined with the Hungarian algorithm, to achieve cross-frame target association. Due to the irregular movement patterns of targets in livestock tracking scenarios, which include variations in speed and sudden changes in direction, using Kalman Filters (KFs) in the traditional manner may not yield accurate bounding box positions, leading to the loss of target tracking. Additionally, the above research primarily focuses on the identification or automatic tracking of pig behaviors, lacking analysis of the time of the pig’s different behaviors, such as eating, standing, and lying, according to the post-processing of the tracking results.
To address the aforementioned issues, based on the SORT algorithm [23], this paper introduces a robust pig-tracking method named RpTrack. Firstly, in the detection phase, this method utilizes the robust YOLOX [24] detector to generate detection results for each video frame. Then, in the association phase, RpTrack effectively deals with ID switches caused by irregular pig movement in pig tracking scenarios. This is achieved through improved trajectory management combined with a KF appropriate for pig tracking. Furthermore, it incorporates BIoU to mitigate the influence of missed detections due to uneven lighting conditions on tracking performance. Finally, we monitor and analyze the time of the pig’s different behaviors, such as eating, standing, and lying, according to the post-processing of the tracking results throughout the video.

2. Materials and Methods

2.1. Materials

The video data were obtained in two parts: one part was provided by T. Psota et al. [25], and the other part was captured at the Lejiazhuang Breeding Base in Sanshui District, Foshan City, Guangdong Province, China. The cameras were installed directly above the central area of the pig breeding zone, capturing the entire area from a downward perspective. The resolution of the camera was 2560 × 960 pixels, the frame rate was 25 fps, and the video data were stored in MP4 format. In the subsequent data processing, we selected 27 videos, with 23 1-min videos and 4 10-min videos cropped from the one part for the public dataset and 18 1-min videos chosen from the other part for the private dataset. Notably, the annotated dataset from T. Psota et al. was labeled with each pig’s shoulder, tail, and ID for all frames of each video and could not be used for mainstream MOT tasks. Therefore, we annotated all video segments, including the public and private datasets, using DarkLabel1.3 software at 5 frames per second (fps) to evaluate the tracking performance of pig behaviors. The video scenes are illustrated in Figure 1. It includes daytime sparse and daytime dense scenes, as shown in Figure 1a,b, and nighttime even light and uneven light scenes, as shown in Figure 1c,d.
In this study, all videos in both datasets were manually annotated using the DarkLabel software. The annotation includes the identity, position, and behavior categories of the pigs. The behaviors are categorized into four types (“stand”, “lie”, “eat,” and “other”). Examples of behavioral classification for some pigs are shown in Figure 2. To compare the tracking performance of the proposed method in different scenarios, this paper selected 15 videos from the public dataset as test videos. Additionally, 9 videos from the private dataset were chosen as test videos. Meanwhile, based on manual observations, videos with a higher number of pigs and more occlusions were categorized as pig-dense videos and vice versa as pig-sparse videos. Additionally, videos with relatively even lighting conditions were labeled as even lighting scenes, and videos with uneven lighting conditions were labeled as uneven lighting scenes, as shown in Figure 1. Table 1 presents a detailed description of the test video environments in both the public and private datasets. Note: No. 01, 05, 11, and 15 are 10 min videos; the rest are 1 min videos.

2.2. Methods

The robust pig tracking method named RpTrack is illustrated in Figure 3. Firstly, during the input phase, the YOLOX detector is used to obtain the detection results, including the bounding box positions, behavior categories, and confidence scores. Meanwhile, the improved trajectory prediction is applied to predict the current position for each trajectory in the trajectory set (except in the case of the first frame). Then, during the tracking phase, the current detection results and the trajectory prediction results are taken as inputs. The first matching is based on Intersection over Union (IoU). Unmatched detections and trajectories in the first matching are performed in a second matching based on BIoU. Finally, after completing the entire video tracking process, behavioral statistic information can be obtained on the behavioral states of the pigs and their activity trajectories within the video. Compared to the SORT method, RpTrack made improvements in three key components: the Kalman Filter, the trajectory management, and the BIoU. The following sections describe each of these components in detail.

2.2.1. Improved Kalman Filter

In the SORT algorithm, the KF [26] state vector used is denoted as x = [ x c , y c , s , a , x ^ c , y ^ c , s ^ ] T . Here, ( x c , y c ) represents the center coordinates of the target, s and a , respectively, denote the area and aspect ratio of the bounding box, and [ x ^ c , y ^ c , s ^ ] is the velocity corresponding to these parameters.
In the pig tracking environment, this type of state vector may struggle to obtain accurate bounding box shapes. The predicted bounding boxes might not completely and accurately surround the pigs, thereby affecting the overall performance of the tracker. The KF state vector used in the RpTrack algorithm is denoted by x = [ x c , y c , w , h , x ^ c , y ^ c , w ^ , h ^ ] T as in the Bot-SORT [27] algorithm. Here, ( x c , y c ) represents the center coordinates of the target, w and h , respectively, denote the width and height of the bounding box, and [ x ^ c , y ^ c , w ^ , h ^ ] is the velocity corresponding to these parameters. This state vector can provide more accurate bounding box shapes.
The visualization results of the KF state vector bounding boxes used in SORT and RpTrack are compared in Figure 4. The red dashed line and the green solid line represent the visualization results of the KF state vector bounding boxes in SORT and RpTrack, respectively. It can be observed that the green solid line can more completely and accurately surround the pigs. Therefore, RpTrack can enhance tracking performance compared with SORT.

2.2.2. Improved Trajectory Management

The tracking scenarios for pedestrians typically exhibit different movement patterns compared to those for pigs. In pig tracking, the irregular movements of pigs make it challenging to apply pedestrian tracking methods directly. This often results in unsatisfactory tracking results. Most current motion-based MOT methods rely on utilizing position information observed across the entire trajectory for prediction. However, this approach is not effective in handling the irregular movement patterns of pigs. Therefore, in this study, we employ the position information observed in the last K frames of a trajectory ( K is a hyperparameter) to predict the trajectory’s position in the next frame. This approach allows for more accurate position predictions and addresses the issue of irregular pig movements. Improvements in the storage of trajectory information are necessary.
The improved trajectory information storage is illustrated in Figure 5b. Each long block represents a list for storing motion information, where K is the maximum length of the list. Each colored block in a long block represents the motion information stored in a trajectory. The list representing the storage of motion information for a trajectory can be denoted as T = { [ ( x i 1 , P i 1 ) , ( x i 2 , P i 2 ) , , ( x i k , P i k ) ] , s i , c i } i = 1 N t , where k K . Here, i denotes the trajectory index, x i k represents the KF state recording the position information of trajectory i for the last k frames, P i k indicates the corresponding covariance matrix for x i k , s i represents the state of trajectory i (tracked or lost), c i denotes the behavior category of trajectory i (“stand”, “lie”, “eat”, and “other”), N t represents the number of trajectories in frame t , and ( x i k , P i k ) denotes the motion information of trajectory i recording the position information of the last k frames. The storage of trajectory information before improvement is depicted in Figure 5a, where each trajectory stores only one motion information, recording all observed position information for the trajectory. Additionally, each trajectory does not store the behavior state.
To achieve accurate trajectory predictions, we made improvements to the trajectory prediction module. These improvements allowed the position information observed in the last K frames to be used to predict the position of the trajectory in the next frame. Figure 6 depicts the trajectory prediction procedure. If the trajectory state is “lost” or the behavior state is “lie”, KF prediction processing is not applied to the trajectory, which is subsequently directly used in the association phase. If not, all the motion information stored for the trajectory is processed with the KF prediction, and the results are used in the association phase. Note: For each trajectory, only the prediction result of the motion information recording the most frames of position information is used for the association phase.
The comparison between the improved and unimproved trajectory prediction results is depicted in Figure 7. In Figure 7, the green solid line represents the results obtained with the improved trajectory prediction, while the red dashed line represents the results without improvement. The more accurately the bounding box surrounds the pigs, the more accurate the prediction result. Figure 7a–c represent three motion patterns: slow movement, sudden turning, and fast movement. It can be observed that under all three different motion patterns, the improved trajectory prediction consistently yields more accurate results.
To maintain the accuracy of the stored motion information for trajectories, improvements are required in the trajectory update module. The specific implementation details are illustrated in Algorithm 1.
Algorithm 1: Improved trajectory update
Input: t = { [ ( x 1 , P 1 ) , ( x 2 , P 2 ) , , ( x k , P k ) ] , s , c } : represents the storage information for trajectory t , x k represents the KF state recording the position information of trajectory t over the last k frames, with P k as the corresponding covariance matrix, s indicates the trajectory state (lost or tracked), and c represents the behavior category of trajectory t .
d = { l , c d } : l indicates the position of detection d matched with trajectory t , where c d denotes the behavior category of the detected target.
K : indicates the maximum length of the trajectory information storage list.
Output: t = { [ ( x 1 , P 1 ) , ( x 2 , P 2 ) , , ( x k , P k ) ] , s , c } : represents the updated storage information for trajectory t , x k represents the updated Kalman filter state, P k represents the corresponding updated covariance matrix for x k , c denotes the behavior category of the trajectory, and s reflects the trajectory state.
1 /*update historical KF state vectors and KF covariance matrixes*/
2 Step 1: Initialize an empty set
3  t ' ← ∅
4 Step 2: Initialize KF for detection d
5  x , P ← KF initialization d
6  t ' t ' { x , P } /*store current motion information*/
7 Step 3:update motion information
8  if s == Tracked then
9   for i ← 1 to k  do
10    if i < K  then /*ensure that maximum K frames of position information are recorded*/
10      x i , P i ← KF update x i , P i , x /*conduct KF update*/
11      t ' t ' { x i , P i }
12  t t '
13  c c d /*update trajectory behavior category*/
14 Return t

2.2.3. BIoU (Buffered IoU)

In the MOT task, motion-based target association algorithms commonly employ the IoU metric. The calculation of IoU is depicted in the left part of Figure 8, where A = ( w A , h A ) and B = ( w B , h B ) , respectively, denote the bounding box information for detection and trajectory, w A and h A , respectively, denote the width and height of detection A, w B and h B , respectively, represent the width and height of trajectory B, and S 1 corresponds to the area of overlap between A and B, while S 2 represents the area of their union.
To accurately associate targets with irregular motion patterns and similar appearances, Yang et al. introduced the BIoU (Buffered Intersection over Union) metric [28]. The computation of BIoU is illustrated in the right part of Figure 8, where A = ( b w A , b h A ) and   B   = ( b w B , b h B ) denote the extended bounding box information and b represents a hyperparameter expansion factor. S 1 represents the extended area of overlap and S 2 corresponds to the extended area of their union. (Note that, as in [28], the value of b defaults to 1.5.)

3. Experiments

3.1. Experimental Platform and Parameter Settings

To validate the performance of the proposed RpTrack method in indoor pig tracking and behavioral statistics, three experiments were conducted: (1) a pig tracking experiment to analyze the performance of the RpTrack method; (2) a pig behavior statistics experiment to measure the duration of various behaviors for each pig in the videos; (3) an ablation experiment to evaluate the influences of the improved Kalman Filter, the improved trajectory management, and the BIoU on the tracking performance.
All experiments in this paper were conducted on the same computer, using Linux as the experiment platform with the Ubuntu 20.04 operating system. The hardware configuration included a 12th Gen Intel(R) i9-12900KF CPU, NVIDIA (Santa Clara, CA, USA) GeForce RTX 3090 GPU, 32GB of RAM, PyTorch version 1.11.1, Python version 3.7, and CUDA version 11.3.

3.2. Evaluation Metrics for Multi-Objective Tracking

We selected High Order Tracking Accuracy (HOTA) [29], Multiple Object Tracking Accuracy (MOTA) [30], and Identification F1 (IDF1) as the evaluation metrics for MOT of pigs. HOTA introduces a higher-dimensional tracking accuracy metric, which comprehensively assesses the performance of trackers. MOTA is used to measure the performance of the detector in detecting targets and the tracker in maintaining trajectories. IDF1 is employed to assess the stability of the tracker.
Additionally, in this study, the evaluation of algorithm performance also used two other metrics: the total number of identity switches (IDSW) and the frames per second (FPS) processed by the algorithm.

3.3. Tracking Results

To validate the performance of the proposed RpTrack algorithm, we used the public dataset, consisting of 11 videos, and the private dataset, containing nine videos, as the test videos. Due to the different farming environments and large differences in pig breeds and appearance between the public and private datasets, we used two different YOLOX-X models to complete the tracking experiments. The tracking experiment results of RpTrack are presented in Table 2.
As shown in Table 2, in the public dataset, video 0802 achieved the highest HOTA (92.1%). For all test videos, RpTrack achieved MOTA and IDF1 values of over 96% and 98%, respectively. It also maintained a frame rate (FPS) of 65 or higher. This indicates that RpTrack performs well in terms of tracking pigs in the public dataset while maintaining a fast-tracking speed. However, the tracking performance of videos 11 and 15 is much lower than the other videos, which is due to the existence of a large number of occlusions in videos 11 and 15, resulting in missed and false detections. This, in turn, results in low tracking performance, as shown by the red dashed boxes in Figure 9a,b. In the private dataset, video 0015 achieved the highest HOTA (85.5%). Except for video 0018, all other videos exhibited MOTA and IDF1 values of 97% and above. Except for videos 0010 and 0018, all videos had an ID Switch (IDSW) count of 0. The average FPS for the test videos was 71 or higher, demonstrating that RpTrack excels in terms of tracking accuracy and speed in the private dataset environment. Furthermore, video 0018 has a lower performance compared to the other test videos. This is mainly due to false and missed detections caused by low lighting conditions, as depicted by the red dashed bounding boxes in Figure 9c. The results of the RpTrack method in the public and private datasets indicate that the method has excellent tracking accuracy and real-time performance and can be applied to video surveillance pig tracking in complex scenarios.

3.4. Comparison of Different MOT Algorithms

For both the public and private datasets, the experimental results for SORT, C-BIoU [28], ByteTrack [31], OC-SORT [32], Bot-SORT, and the proposed RpTrack are presented in Table 3. In both datasets, RpTrack outperforms other methods in terms of HOTA, MOTA, IDF1, and IDSW while maintaining a high FPS.
The results demonstrate that the proposed RpTrack outperforms SORT, C-BIoU, ByteTrack, OC-SORT, and Bot-SORT in the pig tracking scenarios. This is attributed to the improved Kalman Filter, the improved trajectory management, and BIoU in RpTrack. These improvements effectively handle irregular pig movement, false detections, and missed detections, reducing ID switches and enhancing tracking performance. Therefore, the RpTrack algorithm’s performance metrics are superior to other algorithms, indicating the effectiveness of RpTrack for MOT of pigs in complex scenarios.
The visualization results of Bot-SORT, ByteTrack, OC-SORT, and RpTrack methods in both the public and private datasets are presented in Figure 10 and Figure 11. In these figures, the red-dashed bounding boxes indicate pigs that have lost track, and the yellow arrows represent pigs with ID switches. In Figure 10, in the 90th frame of video 0102, two pigs in the upper right corner suddenly move rapidly. In the subsequent three frames, Bot-SORT, ByteTrack, and OC-SORT lose track of these pigs and exhibit ID switches, while RpTrack can accurately track both pigs. In Figure 11, in the 152nd frame of video 0018, a pig in the lower left corner was lost due to uneven light from the 153rd frame to the 163rd frame. When the pig reappears in the 164th frame, only RpTrack can correctly track it, while the other algorithms fail to track the pig.
To further compare the overall tracking performance among different trackers, Figure 12 displays the pig tracking trajectories in selected videos. Figure 11a,d show the real activity trajectories and tracking trajectories of all individual pigs in video 0102 and video 0013, respectively, with labels on the right indicating the trajectory colors and their corresponding IDs. Figure 12b,c,e depict the real activity trajectories of pigs with IDs 3 and 6 in video 0102 and ID 10 in video 0013. These figures also show the tracking trajectories of each tracker. Taking video 0102 as an example, in Figure 12a, RpTrack produces tracking trajectories most similar to the real trajectories (GT). The number of trajectories matches that in the GT, indicating that RpTrack maintains consistent pig IDs throughout the tracking process. Additionally, Figure 11b shows the actual trajectory of a pig in video 0102 and the tracking trajectory of each tracker. It can be observed that Bot-SORT, OC-SORT, and ByteTrack all show ID switches when tracking a pig with GT ID 3, while RpTrack can correctly track this pig. A comprehensive analysis combining Table 3 and Figure 10, Figure 11 and Figure 12 demonstrates that RpTrack exhibits the best tracking performance, accurately tracking pigs in complex scenarios.

3.5. Behavioral Statistics

To validate the accuracy of individual pig behavior identification and statistical analysis based on the RpTrack tracking method, this study employs the training dataset labeled with four distinct behavior categories (“stand”, “lie”, “eat,” and “other”) to train a YOLOX detector. The combination of the YOLOX detector and RpTrack tracker accomplishes simultaneous tracking and behavior statistics of pigs. The real behavior statistics of individual pigs in certain videos and the behavior statistics generated by RpTrack are presented in Figure 13. The horizontal axis represents pig identities, while the vertical axis indicates the number of frames in which the behavior duration. Bars with arrows represent the real behavior statistics, followed by adjacent bars illustrating RpTrack’s behavior statistics. Different colors, such as blue, orange-red, green, and orange, correspond to the four behavior categories (“stand”, “lie”, “eat,” and “other”), respectively. The greater the similarity between the actual behavior results and RpTrack’s behavior results, the more accurate RpTrack’s behavior statistics were considered. For pig ID 5 in video 0902, the real statistics for the blue, orange-red, and orange parts closely match the RpTrack behavioral statistics, indicating that RpTrack’s results are accurate. Similar results were observed for other individual pigs. The experiment results indicate that the tracking method based on the YOLOX and RpTrack achieved relatively accurate behavior identification and statistical analysis of pig behaviors in the videos.

3.6. Ablation Experiments and Analysis

3.6.1. Effect of Different K Values in Improved Trajectory Management

In the improved trajectory management, in order to obtain a suitable value for the hyperparameter K , we performed an ablation study on both the public and private datasets to analyze the effect of different values of K on the tracking performance and the results are shown in Table 4.
According to the results in Table 4, the best tracking performance can be obtained with K = 2 in the public dataset and with K = 4 in the private dataset. The tracking performance can be improved in all cases after using the improved trajectory management. Figure 14 shows the visualization results obtained with and without the improved trajectory management. In the figure, the red-dashed bounding boxes indicate pigs cannot be tracked, and the yellow arrows represent pigs with ID switches. In this case, the pig with ID 2 was severely occluded at frame 1755, which led to a switch from ID 6 to 2. When the occluded pig reappeared at frame 1756, the pig failed to be retrieved correctly without the improved trajectory management, while it was able to be retrieved correctly after adopting the improved trajectory management. This demonstrates that the improved trajectory management is more accurate in predicting the target location.

3.6.2. Effect of Each Module in the RpTrack

To validate the performance of the improved Kalman Filter, the improved trajectory management, and BIoU in tracking, we conducted tests on both public and private datasets before and after the improvements, as indicated in Table 5. It can be observed that, compared to the original SORT, the improved Kalman Filter, the improved trajectory management, and the BIoU all lead to performance improvements.
Figure 15 shows a comparison of tracking results with and without ITM in video 0102 and with and without BIoU in video 0018. In video 0102 (green-dashed box), in the 90th frame, pigs with IDs 2 and 4 suddenly exhibit rapid movements. Subsequently, in frames 92 and 93, ITM loses tracking (as indicated by the red-dashed box), while ITM maintains accurate tracking. In video 0018 (blue-dashed box), after frame 152, pig ID 1 is lost due to a missed detection. When the pig reappears at frame 164, not using BIoU ensures tracking is lost (as depicted by the red-dashed box), while using BIoU maintains accurate tracking. This indicates that the improvements are effective in dealing with irregular pig movements and missed detections, which in turn improves tracking performance.

4. Conclusions and Limitation Discussion

The RpTrack method proposed in this paper utilizes YOLOX for pig detection and behavioral classification. It also leverages the improved KF and the improved trajectory management to address irregular pig movements. Additionally, it introduces BIoU to mitigate the issue of decreased tracking performance caused by missed detections resulting from uneven lighting. The summary is as follows:
  • Experiment results on both public and private datasets demonstrate that RpTrack achieves a competitive execution speed like the SORT method. In the public dataset, RpTrack achieves a HOTA of 73.2%, MOTA of 95.5, IDF1 of 85.6%, and IDSW of 148. In the private datasets, RpTrack’s performance achieves a HOTA of 80.8%, MOTA of 97.8%, IDF1 of 98.4, and IDSW of 6, surpassing other leading tracking methods in all performance metrics.
  • Visualization results comparisons confirm that the improved KF and the improved trajectory management effectively address the issue of ID switches caused by irregular pig movements. Furthermore, It is also demonstrated that BIoU can alleviate the problem of ID switches resulting from missed detections due to uneven lighting. These improvements enhance tracking stability.
  • Pig behaviors are categorized into “stand”, “lie”, “eat,” and “other”. Based on RpTrack’s more precise tracking results, it achieves more accurate pig behavior statistics.
RpTrack still has some limitations, as follows:
  • The improved trajectory management is sensitive to the hyperparameter K . Different values of K are used in different tracking environments to achieve better tracking results, and as K is larger, more computation is required (Section 3.6.1).
  • BIoU still has mismatch problems due to the bounding box extension.
  • The work in this paper focuses on improvements to the tracker, and the problems that would be faced by behavioral statistics are not studied in depth. Therefore, RpTrack fails to deal with the effect of ID switches on the results of behavioral statistics, but this is the direction of our future work.
The RpTrack method proposed in this paper effectively handles the challenges presented by irregular pig movements and uneven lighting in MOT of pigs. It demonstrates outstanding performance in tracking stability, accuracy, and behavioral statistics, providing support for research and applications in intelligent pig farming.

Author Contributions

Methodology, H.L. (Hua Lei); software, H.L. (Hua Lei); formal analysis, S.T. and E.L.; resources, S.T. and Y.L.; writing—original draft, H.L. (Hua Lei); writing—review and editing, S.T. and H.L. (Hua Lei); visualization, H.L. (Hua Lei) and H.L. (Hongxing Liu); supervision, S.T., Y.L., E.L., and H.L. (Hongxing Liu); project administration, S.T., Y.L., E.L., and H.L. (Hongxing Liu); funding acquisition, Y.L., E.L., and H.L. (Hongxing Liu). All authors have read and agreed to the published version of the manuscript.

Funding

This study was funded by key R&D project of Guangzhou (202206010091, 2024B03J1358, 2023B03J1363).

Institutional Review Board Statement

The animal experiment protocol was approved by the Ethics Committee for Research Animals of South China Agricultural University (Protocol number 2024F213).

Data Availability Statement

The raw data supporting the conclusions of this article will be made available by the authors upon request.

Conflicts of Interest

The authors declare no conflicts of interest.

References

  1. Tzanidakis, C.; Simitzis, P.; Arvanitis, K.; Panagakis, P. An overview of the current trends in precision pig farming technologies. Livest. Sci. 2021, 249, 104530. [Google Scholar] [CrossRef]
  2. Yin, M.; Ma, R.; Luo, H.; Li, J.; Zhao, Q.; Zhang, M. Non-contact sensing technology enables precision livestock farming in smart farms. Comput. Electron. Agric. 2023, 212, 108171. [Google Scholar] [CrossRef]
  3. Matthews, S.G.; Miller, A.L.; Plötz, T.; Kyriazakis, I. Automated tracking to measure behavioural changes in pigs for health and welfare monitoring. Sci. Rep. 2017, 7, 17582. [Google Scholar] [CrossRef] [PubMed]
  4. Zhang, L.; Gray, H.; Ye, X.; Collins, L.; Allinson, N. Automatic Individual Pig Detection and Tracking in Pig Farms. Sensors 2019, 19, 1188. [Google Scholar] [CrossRef] [PubMed]
  5. Cowton, J.; Kyriazakis, I.; Bacardit, J. Automated Individual Pig Localisation, Tracking and Behaviour Metric Extraction Using Deep Learning. IEEE Access 2019, 7, 108049–108060. [Google Scholar] [CrossRef]
  6. Girshick, R. Fast r-cnn. In Proceedings of the IEEE International Conference on Computer Vision, Santiago, Chile, 7–13 December 2015; pp. 1440–1448. [Google Scholar]
  7. Wojke, N.; Bewley, A.; Paulus, D. Simple online and realtime tracking with a deep association metric. In Proceedings of the: 2017 IEEE International Conference on Image Processing (ICIP), Beijing, China, 17–20 September 2017. [Google Scholar] [CrossRef]
  8. Guo, Q.; Sun, Y.; Orsini, C.; Bolhuis, J.E.; de Vlieg, J.; Bijma, P.; de With, P.H. Enhanced camera- based individual pig detection and tracking for smart pig farms. Comput. Electron. Agric. 2023, 211, 108009. [Google Scholar] [CrossRef]
  9. Wang, Z.; Zheng, L.; Liu, Y.; Li, Y.; Wang, S. Towards real-time multi-object tracking. In European Conference on Computer Vision; Springer: Berlin/Heidelberg, Germany, 2020; pp. 107–122. [Google Scholar]
  10. Zhang, Y.; Wang, C.; Wang, X.; Zeng, W.; Liu, W. Fairmot: On the fairness of detection and re–identification in multiple object tracking. Int. J. Comput. Vis. 2021, 129, 3069–3087. [Google Scholar] [CrossRef]
  11. Tu, S.; Liu, X.; Liang, Y.; Zhang, Y.; Huang, L.; Tang, Y. Behavior Recognition and Tracking Method of Group housed Pigs Based on Improved DeepSORT Algorithm. Nongye Jixie Xuebao/Trans. Chin. Soc. Agric. Mach. 2022, 53, 345–352. [Google Scholar] [CrossRef]
  12. Redmon, J.; Divvala, S.; Girshick, R.; Farhadi, A. You only look once: Unified, real-time object detection. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Las Vegas, NV, USA, 27–30 June 2016; pp. 779–788. [Google Scholar]
  13. Jocher, G.; Chaurasia, A.; Stoken, A.; Borovec, J.; Kwon, Y.; Fang, J.; Michael, K.; Montes, D.; Nadar, J.; Skalski, P. Ultralytics/yolov5: v6.1–TensorRT, TensorFlow edge TPU and OpenVINO export and inference. Zenodo 2022. [Google Scholar] [CrossRef]
  14. Kim, J.; Suh, Y.; Lee, J.; Chae, H.; Ahn, H.; Chung, Y.; Park, D. EmbeddedPigCount: Pig Counting with Video Object Detection and Tracking on an Embedded Board. Sensors 2022, 22, 2689. [Google Scholar] [CrossRef]
  15. Odo, A.; Muns, R.; Boyle, L.; Kyriazakis, I. Video Analysis Using Deep Learning for Automated Quantification of Ear Biting in Pigs. IEEE Access 2023, 11, 59744–59757. [Google Scholar] [CrossRef]
  16. Wang, C.Y.; Bochkovskiy, A.; Liao, H.Y.M. Scaled-YOLOv4: Scaling cross stage partial network. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, Nashville, TN, USA, 20–25 June 2021; pp. 13024–13033. [Google Scholar]
  17. Wang, C.Y.; Bochkovskiy, A.; Liao, H.Y.M. YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors. arXiv 2022, arXiv:2207. 02696. [Google Scholar]
  18. Han, S.; Fuentes, A.; Yoon, S.; Jeong, Y.; Kim, H.; Sun Park, D. Deep learning-based multi–cattle tracking in crowded livestock farming using video. Electron. Agric. 2023, 212, 108044. [Google Scholar] [CrossRef]
  19. Yigui, H.; Deqin, X.; Junbin, L.; Zhujie, T.; Kejian, L.; Miaobin, C. An Improved Pig Counting Algorithm Based on YOLOv5 and DeepSORT Model. Sensors 2023, 23, 6309. [Google Scholar] [CrossRef] [PubMed]
  20. Zheng, Z.; Li, J.; Qin, L. YOLO-BYTE: An efficient multi-object tracking algorithm for automatic monitoring of dairy cows. Comput. Electron. Agric. 2023, 209, 107857. [Google Scholar] [CrossRef]
  21. Van der Zande, L.E.; Guzhva, O.; Rodenburg, T.B. Individual detection and tracking of group housed pigs in their home pen using computer vision. Front. Animal Sci. 2021, 2, 669312. [Google Scholar] [CrossRef]
  22. Redmon, J.; Farhadi, A. Yolov3: An incremental improvement. arXiv 2018, arXiv:1804.02767. [Google Scholar]
  23. Bewley, A.; Ge, Z.; Ott, L.; Ramos, F.; Upcroft, B. Simple online and realtime tracking. In Proceedings of the 2016 IEEE International Conference on Image Processing (ICIP), Phoenix, AZ, USA, 25–28 September 2016. [Google Scholar] [CrossRef]
  24. Ge, Z.; Liu, S.; Wang, F.; Li, Z.; Sun, J. Yolox: Exceeding yolo series in 2021. arXiv 2021, arXiv:2107.08430. [Google Scholar]
  25. Psota, T.; Schmidt, E.; Mote, T.B.; Pérez, C.L. Long-Term Tracking of Group-Housed Livestock Using Keypoint Detection and MAP Estimation for Individual Animal Identification. Sensors 2020, 20, 3670. [Google Scholar] [CrossRef]
  26. Kalman, R.E. A New Approach to Linear Filtering and Prediction Problems. J. Basic Eng. 1960, 82, 35–45. [Google Scholar] [CrossRef]
  27. Aharon, N.; Orfaig, R.; Bobrovsky, B.-Z. BoT-SORT: Robust Associations Multi-Pedestrian Tracking. arXiv 2022, arXiv:2206.14651. [Google Scholar] [CrossRef]
  28. Yang, F.; Odashima, S.; Masui, S.; Jiang, S. Hard to Track. In Objects with Irregular Motions and Similar Appearances? Make It Easier by Buffering the Matching Space. In Proceedings of the 2023 IEEE/CVF Winter Conference on Applications of Computer Vision (WACV), Waikoloa, HI, USA, 3–7 January 2023. [Google Scholar] [CrossRef]
  29. Luiten, J.; Osep, A.; Dendorfer, P.; Torr, P.; Geiger, A.; Leal-Taixé, L.; Leibe, B. Hota: A Higher Order Metric for Evaluating Multi-object Tracking. Int. J. Comput. Vis. 2020, 129, 548–578. [Google Scholar] [CrossRef] [PubMed]
  30. Bernardin, K.; Stiefelhagen, R. Evaluating Multiple Object Tracking Performance: The CLEAR MOT Metrics. J. Image Video Proc. 2008, 2008, 246309. [Google Scholar] [CrossRef]
  31. Zhang, Y.; Sun, P.; Jiang, Y.; Yu, D.; Weng, F.; Yuan, Z.; Luo, P.; Liu, W.; Wang, X. ByteTrack: Multi-object Tracking by Associating Every Detection Box. In Computer Vision–ECCV; Springer Nature: Cham, Switzerland, 2022. [Google Scholar] [CrossRef]
  32. Cao, J.; Pang, J.; Weng, X.; Khirodkar, R.; Kitani, K. Observation-Centric SORT: Rethinking SORT for Robust Multi-Object Tracking. In Proceedings of the 2023 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), Vancouver, BC, Canada, 17–24 June 2023. [Google Scholar]
Figure 1. Dataset video scenes.
Figure 1. Dataset video scenes.
Agriculture 14 01158 g001
Figure 2. Examples of pig behavior classification. (a) Examples of “stand”, “lie,” and “eat” behavioral categories. (b) Examples of “stand”, “lie,” and “other” behavioral categories.
Figure 2. Examples of pig behavior classification. (a) Examples of “stand”, “lie,” and “eat” behavioral categories. (b) Examples of “stand”, “lie,” and “other” behavioral categories.
Agriculture 14 01158 g002
Figure 3. RpTrack tracking pipeline.
Figure 3. RpTrack tracking pipeline.
Agriculture 14 01158 g003
Figure 4. Comparison of visualization results of KF in SORT and RpTrack.
Figure 4. Comparison of visualization results of KF in SORT and RpTrack.
Agriculture 14 01158 g004
Figure 5. Improved before and after trajectory information storage: (a) the trajectory information storage before improvement. (b) The improved trajectory information storage.
Figure 5. Improved before and after trajectory information storage: (a) the trajectory information storage before improvement. (b) The improved trajectory information storage.
Agriculture 14 01158 g005
Figure 6. Trajectory prediction process. The red-bordered blocks indicate the motion information recording the most positional information.
Figure 6. Trajectory prediction process. The red-bordered blocks indicate the motion information recording the most positional information.
Agriculture 14 01158 g006
Figure 7. Comparison of trajectory prediction results with and without the improvement.
Figure 7. Comparison of trajectory prediction results with and without the improvement.
Agriculture 14 01158 g007
Figure 8. Calculation of IoU and BIoU.
Figure 8. Calculation of IoU and BIoU.
Agriculture 14 01158 g008
Figure 9. Tracking video environments. (a) Examples of video 11 missed detections. (b) Examples of video 15 missed detections. (c) Examples of video 0018 missed detections.
Figure 9. Tracking video environments. (a) Examples of video 11 missed detections. (b) Examples of video 15 missed detections. (c) Examples of video 0018 missed detections.
Agriculture 14 01158 g009
Figure 10. Comparison of RpTrack’s tracking results with other MOT algorithms in the public dataset.
Figure 10. Comparison of RpTrack’s tracking results with other MOT algorithms in the public dataset.
Agriculture 14 01158 g010
Figure 11. Comparison of RpTrack’s tracking results with other MOT algorithms in the private dataset.
Figure 11. Comparison of RpTrack’s tracking results with other MOT algorithms in the private dataset.
Agriculture 14 01158 g011
Figure 12. Comparison of target tracking trajectories for different methods.
Figure 12. Comparison of target tracking trajectories for different methods.
Agriculture 14 01158 g012
Figure 13. Comparison of actual behavioral statistics and tracking behavioral statistics for some videos.
Figure 13. Comparison of actual behavioral statistics and tracking behavioral statistics for some videos.
Agriculture 14 01158 g013
Figure 14. Comparison of visualization results on video 01 with and without the improved trajectory management, where (a) the results without the improved trajectory management and (b) the results with the improved trajectory management.
Figure 14. Comparison of visualization results on video 01 with and without the improved trajectory management, where (a) the results without the improved trajectory management and (b) the results with the improved trajectory management.
Agriculture 14 01158 g014
Figure 15. Comparison of tracking results with and without ITM or BIoU.
Figure 15. Comparison of tracking results with and without ITM or BIoU.
Agriculture 14 01158 g015
Table 1. Test video environments.
Table 1. Test video environments.
DatasetNo.SparseDenseDayNightLight
Public0102uniform
0402uniform
0502uniform
0602uniform
0702uniform
0802uniform
0902uniform
1002uneven
1102uniform
1202uniform
1502uniform
01uniform
05uniform
11uniform
15uniform
Private0010uniform
0011uniform
0012uneven
0013uniform
0014uniform
0015uniform
0016uniform
0017uniform
0018uneven
Table 2. Results of tracking experiments on the test video.
Table 2. Results of tracking experiments on the test video.
DatasetVideoHOTA/%MOTA/%IDF1/%IDSW/%FPS/(f/s)
Public dataset010290.699.9100.0073.8
040290.199.8100.0070.1
050284.899.8100.0073.6
060280.098.699.3069.0
070287.599.9100.0071.7
080292.1100.0100.0071.3
090288.896.698.3070.2
100273.897.198.6070.3
110288.897.198.6069.1
120286.097.198.5269.6
150277.698.499.2068.5
0177.096.693.9875.4
0579.098.894.41273.6
1161.894.271.85468.7
1566.491.878.96969.2
Private
dataset
001080.099.097.8265.7
001181.497.198.5069.7
001279.098.299.1069.6
001381.997.698.8069.6
001484.199.9100.0074.7
001585.599.699.8074.9
001686.199.899.9074.3
001781.299.9100.0073.6
001866.288.290.7474.8
Table 3. Comparison of RpTrack results with other MOT methods.
Table 3. Comparison of RpTrack results with other MOT methods.
DatasetMethodHOTA/%MOTA/%IDF1/%IDSWFPS/(f/s)
PublicSORT65.295.072.824275.3
ByteTrack61.692.872.622973.8
C-BIoU70.195.279.736979.1
OC-SORT70.295.281.016173.1
Bot-SORT69.195.178.831719.2
RpTrack73.295.585.614670.9
PrivateSORT77.797.493.02978.6
ByteTrack73.393.290.14179.3
C-BIoU76.895.491.74580.7
OC-SORT78.697.494.31878.1
Bot-SORT78.897.093.43537.4
RpTrack80.897.898.4672.9
Table 4. Effect of different values of K on tracking performance, where “-” indicates that the improved trajectory management is not used.
Table 4. Effect of different values of K on tracking performance, where “-” indicates that the improved trajectory management is not used.
PublicPrivate
K ValuesHOTA/%MOTA/%IDF1/%IDSWHOTA/%MOTA/%IDF1/%IDSW
-71.095.582.615279.497.896.711
172.195.484.215880.197.597.97
273.295.585.614879.497.696.610
372.195.584.615179.997.697.38
472.295.584.815480.797.798.36
572.395.585.114879.597.696.612
Table 5. Ablation experiments on the public and private datasets. IKF denotes the improved Kalman Filter, ITM denotes the improved trajectory management, and BIoU denotes Buffered IoU.
Table 5. Ablation experiments on the public and private datasets. IKF denotes the improved Kalman Filter, ITM denotes the improved trajectory management, and BIoU denotes Buffered IoU.
PublicPrivate
IKFITMBIoUHOTA/%MOTA/%IDF1/%IDSWHOTA/%MOTA/%IDF1/%IDSW
65.295.072.824277.797.493.029
70.595.581.814679.797.796.611
70.795.582.014280.297.897.28
73.295.585.614880.897.898.46
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Tu, S.; Lei, H.; Liang, Y.; Lyu, E.; Liu, H. RpTrack: Robust Pig Tracking with Irregular Movement Processing and Behavioral Statistics. Agriculture 2024, 14, 1158. https://doi.org/10.3390/agriculture14071158

AMA Style

Tu S, Lei H, Liang Y, Lyu E, Liu H. RpTrack: Robust Pig Tracking with Irregular Movement Processing and Behavioral Statistics. Agriculture. 2024; 14(7):1158. https://doi.org/10.3390/agriculture14071158

Chicago/Turabian Style

Tu, Shuqin, Hua Lei, Yun Liang, Enli Lyu, and Hongxing Liu. 2024. "RpTrack: Robust Pig Tracking with Irregular Movement Processing and Behavioral Statistics" Agriculture 14, no. 7: 1158. https://doi.org/10.3390/agriculture14071158

APA Style

Tu, S., Lei, H., Liang, Y., Lyu, E., & Liu, H. (2024). RpTrack: Robust Pig Tracking with Irregular Movement Processing and Behavioral Statistics. Agriculture, 14(7), 1158. https://doi.org/10.3390/agriculture14071158

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop