Real-time detection and target tracking method for moving animals
By collecting and processing animal motion posture image data, training the YOLOv8 model and combining it with the DeepSORT algorithm, using the Kalman filter and the Hungarian algorithm, the problem of low animal detection accuracy and poor tracking stability in the existing technology has been solved, and the detection of moving animals has been achieved. Efficient and stable detection and tracking.
Patent Information
- Application Number
- CN202410906468.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2024-08-30
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing animal detection and tracking technology has low detection accuracy and poor tracking stability in complex environments, especially for animals in motion.
By collecting image data sets of various animals in various motion postures, cleaning and enhancing the data, training the YOLOv8 model for target detection, combining the DeepSORT algorithm for target tracking, and using the Kalman filter and Hungarian algorithm to achieve efficient and stable detection of animals. with tracking.
It improves the detection accuracy and tracking stability of animals in motion, and has important application value in fields such as animal behavior research and farm management.
Smart Images

Figure CN118570258A
Abstract
Description
Technical Field
[0001] The invention relates to animal detection and tracking, and in particular to a real-time detection and target tracking method for animals in motion. Background Art
[0002] Existing animal detection and tracking technologies face many challenges in practical applications, such as low detection accuracy and poor tracking stability, especially for animals in motion. As an advanced target detection algorithm, YOLOv8 has high detection speed and accuracy, but the detection effect in complex environments still needs to be improved. Summary of the invention
[0003] The purpose of the present invention is to overcome the deficiencies of the prior art and provide a method for real-time detection and target tracking of animals in motion, thereby effectively improving detection accuracy and tracking stability.
[0004] The object of the present invention is achieved through the following technical solution: a real-time detection and target tracking method for animals in motion, comprising the following steps: S1. Collecting image data sets of multiple animals, wherein the image data sets contain animal images of each animal in various motion postures; S2. Label some images in the image dataset, train the YOLOv8 model with the labeled images, and then perform target detection on the unlabeled images based on the trained model; S3. Train the target tracking model based on the target information detected by YOLOv8, and use the trained model to achieve target tracking.
[0005] The beneficial effect of the present invention is that the present invention realizes efficient and stable detection and tracking of animals in motion by combining the fast detection capability of YOLOv8 and the precise tracking capability of DeepSORT, and has important application value in the fields of animal behavior research, farm management, etc. BRIEF DESCRIPTION OF THE DRAWINGS
[0006] Figure 1 The present invention is a flow chart of the method. DETAILED DESCRIPTION
[0007] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings, but the protection scope of the present invention is not limited to the following.
[0008] like Figure 1 As shown, a real-time detection and target tracking method for animals in motion includes the following steps: S1. Collecting image data sets of multiple animals, wherein the image data sets contain animal images of each animal in various motion postures; S101. In order to build a diverse and comprehensive animal image dataset, we collected images of various animals (such as pigs, chickens, ducks, etc.), mainly animals in various movements. A1, the collection process takes into account a variety of scenarios, including: - Different lighting conditions (such as day, night, cloudy, etc.) - Different shooting angles (such as looking down, looking from the side, looking up, etc.) - Different shooting distances (such as close-up, mid-range, long-range, etc.) - Movement status (such as walking, running, jumping, etc.) A2, cleaning the collected images of various animals: First, we use PhotoKit and Amemori to make the images clear or delete the unclear images; Then, by calculating the mean square error (MSE), we can get the similarity of the images in the dataset. When the similarity of some of the images is greater than the set threshold, we only keep one as valid data; S102. For each image of a moving animal, repeat step S101 to complete all the movement postures that need to be recorded; S103. For all images obtained in step S102, data processing is performed on the images to effectively expand the data set; The data enhancement method includes a series of GANs enhancement, image conversion and cropping, image flipping, noise addition, brightness and grayscale change, etc., to process the image, ensuring that each image is processed at least once. This enriches the original image data set, simulates complex and diverse environments as much as possible, and ensures that the trained model has strong environmental adaptability.
[0009] We collected images of various animals in motion and created a dataset of moving animal images. We photographed various animal postures in different lighting, angles, and distances to enhance the diversity and robustness of the data. We collected and organized about 7,000 images of 20 types of motion of 7 different animals.
[0010] In the dataset, sick animals and healthy animals may differ in the following ways: Activity level: Sick animals may show lower activity levels, while healthy animals may be more active.
[0011] Behavioral patterns: Sick animals may change their usual behavior patterns, such as reducing exploratory behavior or social interactions.
[0012] Eating and drinking: Sick animals may eat and drink less, while healthy animals will usually have a normal eating pattern.
[0013] Sleep and rest: Sick animals may have increased resting time and altered sleep patterns, whereas healthy animals may have more regular sleep patterns.
[0014] Stress Response: Sick animals may have a heightened stress response to environmental changes or stressors.
[0015] Reproductive behavior: In adult animals, illness may affect reproductive behavior, such as mating frequency or reproductive success.
[0016] Behavioral responses: Sick animals may respond to certain stimuli at different times or in different ways than healthy animals.
[0017] S2. Label some images in the image dataset, train the YOLOv8 model with the labeled images, and then perform target detection on the unlabeled images based on the trained model; Specifically, we label various animals and their postures in the data set we have compiled, use the labeled images to train the YOLOv8 model, and then use the trained YOLOv8 model to recognize images without posture annotations, extract the head and limb parts of all images in the image set of various moving animals, and obtain a set of various animal movement postures; The workload of data annotation is significantly reduced by using a semi-supervised learning method that annotates some images and then automatically identifies the motion dynamics of the remaining images based on the YOLOv8 model. S201. From the collected image collection of moving animal postures, select 15% of the images of animals in various postures, use labeling software Labelimg to annotate the moving postures of various animals, and create a dataset in the format of a YOLO dataset; S202. Build a YOLOv8 target detection model based on the YOLOv8 algorithm, and train the YOLOv8 target detection model using the collected data set; S203. Use the trained YOLOv8 target detection model to predict the motion of the unlabeled images in the motion animal posture image to obtain the motion posture of the animal in the unlabeled image; S204. After the motion posture detection is completed, we will crop all the images in the motion animal posture image set, retaining only the image part of the motion posture, and use Kalman filter, Gaussian filter, etc. to smooth the object motion trajectory, use threshold detection, time window and other methods to remove animal motion abnormal points, and finally obtain a set of motion postures of various animals.
[0018] S3. Train the target tracking model based on the target information detected by YOLOv8, and use the trained model to achieve target tracking; The target information detected by YOLOv8 is passed to DeepSORT, and the head and limb postures of some images in the animal's motion posture set are labeled. The labeled images are used to train the deployed DeepSORT model, and then the trained DeepSORT model is used to track the target by matching the target features and motion prediction results in consecutive frames. The step S3 comprises: S301. Select 15% of the images for each action from the set of animal motion postures detected by YOLOv8, use the Labelimg image annotation tool to annotate the head and limb postures, and obtain a JSON file after annotation to form a dataset in the VOC dataset format; S302. Construct a DeepSORT model and use a dataset built in the VOC dataset format to train the feature extraction capability of the DeepSORT model. The head and limbs are used in DeepSORT training in order to accurately extract the movement posture changes of the limbs from the image. Although DeepSORT tracking relies on the detection frame provided by YOLOv8, it relies on the Kalman filter to match and track the movements of each animal based on the changes in the movements of the limbs and head during tracking. S303. Use the trained DeepSORT model to match the motion features and motion prediction results in consecutive frames: The DeepSORT algorithm extracts the appearance features and motion features of animals, combines the Kalman filter and the Hungarian algorithm to achieve stable tracking of animals, and uses the trained DeepSORT model to match the motion features and motion prediction results in consecutive frames: DeepSORT extracts feature vectors from the YOLOv8 detection frame, which reflects the overall appearance features of the animal in the detection frame, and then uses the Kalman filter in DeepSORT to predict the position of the target. When the animal is occluded or disappears temporarily, DeepSORT uses the Hungarian algorithm to associate the detection frame of the current frame with the tracking result of the previous frame, and predicts the feature vector and target position of the current frame; The operation of DeepSORT relies on the dynamic model and measurement model of the Kalman filter system, as well as the noise covariance matrix of these models. Here is an example of a running chicken: Assume that the state vector is The dynamic model can be expressed as F is the state transfer matrix: The measurement model is used to relate the predicted states to the actual measured values: Where H is the measurement matrix Process noise covariance matrix Q: The measurement noise covariance matrix R is: The recursive steps of the Kalman filter are as follows: 1. Predicted status 2. Update steps DeepSORT uses these results for tracking and matching, and combines them with the Kalman filter to repeatedly update the calculation for state estimation, predict the future position of the object, and reduce errors.
[0019] S304. Discarding unmatched trackers. Once the detection box and the tracker are matched, DeepSORT will update the state of the tracker, including position, speed, and appearance features, and the unmatched detection box will initialize a new tracker, and the unmatched tracker will be deleted after multiple unmatched times.
[0020] In the embodiments of the present application, the detection and tracking results are optimized, including removing false detections and missed detections, and improving the accuracy of detection and tracking.
[0021] In an embodiment of the present application, a multi-head detector can be added, especially a detection head for tiny objects, thereby significantly improving the model's ability to detect small targets; by using feature pyramids, feature fusion, upsampling, downsampling and attention mechanism technologies, false detections and missed detections can be reduced; by adding attention mechanisms such as CBAM (Convolutional BlockAttention Module), the model's ability to focus on key features can be improved, thereby reducing false detections.
[0022] We will compare the actual detection and tracking results with the true value, and in each frame, update the state of the animal based on the Kalman filter's prediction and observation data. If a new animal is detected or the match fails, a new track is initialized or the mismatched track is deleted. If the gap exceeds the set threshold, the YOLOv8 and DeepSORT models will be adjusted or retrained. DeepSORT dynamically updates the Kalman filter to predict the future position of the animal, and combines it with current detection data to correlate and correct for occlusions and interactions.
[0023] Let’s take a running chicken as an example: Then the state transfer matrix is: The YOLOv8 model provides the actual detection position (x, y) of the chicken. The Kalman filter associates the predicted position with the detection result of YOLOv8, uses the Kalman gain to correct the prediction error, and then updates the state vector and error covariance matrix based on the association result. The above prediction and update steps are repeated in each frame image, and the state vector and covariance matrix are continuously adjusted to achieve real-time tracking and matching of the target.
[0024] The Kalman gain calculation formula is as follows: The Kalman filter is able to handle short periods of occlusion. When an animal is occluded, the Kalman filter makes predictions based on the motion state of the previous frames. When the animal reappears, the measured data is correlated with the predicted data to continue tracking. When multiple objects interact, DeepSORT matches the motion trajectory and feature information of each object to maintain correct tracking. In severe interaction situations, predictions can still be made based on the current image position.
[0025] The Kalman filter is a recursive algorithm that updates and predicts the future position of an object using current state estimates and observations.
[0026] State prediction: predict the current state (position and speed) based on the state and speed at the previous moment.
[0027] Update step: Compare the detection result at the current moment with the predicted result, update the predicted state through the observed value, and reduce the error.
[0028] Data association: In each frame, the YOLOv8 detection box provides the current position of the animal. DeepSORT uses these positions (including overall posture information) and the predicted motion trajectory for data association (data association can use the Hungarian algorithm technology). By associating the objects detected in the current frame with the predicted objects, the consistency of tracking is ensured.
[0029] Feature extraction and matching: DeepSORT not only relies on location information, but also uses features in the detection box (such as appearance features) for matching. These features are extracted from the detection box provided by YOLOv8, including color histograms, depth features, etc.
[0030] Specific methods for handling occlusion and interaction: Occlusion handling: When the detection box is missing (i.e. the object is occluded), the Kalman filter can still make predictions based on the motion information of the previous frames. The system will continue to predict its position until the detection box appears again. Through time series analysis, the motion trajectory of the target is analyzed using the continuous frames in the video sequence. Even if the target is occluded in some frames, the occluded part can be inferred from the information of the previous and next frames.
[0031] Interaction processing: During the training phase, the dataset is enhanced by adding simulated occlusions to improve the model's robustness to occlusions. When multiple objects interact, DeepSORT matches each object's motion trajectory and feature information to try to maintain correct tracking. In the case of severe interactions, judgments can be made based on a combination of short-term and long-term features.
[0032] In an embodiment of the present application, the tracking data is reviewed regularly to identify possible false detections or missed detections. MOTChallenge is used for evaluation to calculate MOTA and MOTP values. MOTA indicators include missed detections, false detections, ID errors, and position errors, while MOTP evaluates the average Euclidean distance between the target position estimate and their true position. The tracking effect is evaluated by these two values to reduce overlap and mislabeling.
[0033] In the embodiments of the present application, taking MOTA and MOTP as examples: Save the DeepSORT tracking results as a format file compatible with the MOTChallenge format (comma-delimited CSV file), where each line represents a detection result (for example: frame, id, x, y, width, height, confidence, class, visibility). In addition, the real value data also needs to be a CSV file in the MOTChallenge format. Then use the built-in functions of MOTChallenge to calculate the MOTA and MOTP values and evaluate the tracking effect. The higher the MOTA value of the result, the better the performance of our DeepSORT tracking system, and the higher the MOTP value, the more accurate our tracker is in estimating the target position. If the MOTA and MOTP values are not high, we need to modify our model.
[0034] The above is a preferred embodiment of the present invention. It should be understood that the present invention is not limited to the form disclosed herein, and should not be regarded as excluding other embodiments, but can be used in other combinations, modifications and environments, and can be modified within the scope of the concept described herein through the above teachings or the technology or knowledge of the relevant field. The changes and modifications made by those skilled in the art do not depart from the spirit and scope of the present invention, and should be within the scope of protection of the claims attached to the present invention.
Claims
1. A method for real-time detection and target tracking of animals in motion, characterized in that: The following steps are involved: S1. Collecting image data sets of multiple animals, wherein the image data sets contain animal images of each animal in various motion postures; S2. Label some images in the image dataset, train the YOLOv8 model with the labeled images, and then perform target detection on the unlabeled images based on the trained model; S3. Train the target tracking model based on the target information detected by YOLOv8, and use the trained model to achieve target tracking.
2. The method for real-time detection and target tracking of animals in motion according to claim 1, characterized in that: In the step S1, for each animal image in various motion postures, it is necessary to collect the animal images in various motion postures under different lighting conditions, different shooting angles and different shooting distances.
3. The method for real-time detection and target tracking of animals in motion according to claim 1, characterized in that: After the image data set is acquired in step S1, it is necessary to perform data enhancement on the images in the image data set. The data enhancement method includes one or more of image flipping, adding noise, and changing brightness.
4. The method for real-time detection and target tracking of animals in motion according to claim 1, characterized in that: The step S2 comprises: S201. Select 15% of the images of animals in various postures from the image dataset, use labeling software Labelimg to select and annotate the motion posture areas of various animals, and create a dataset in the format of the YOLO dataset; S202. Build a YOLOv8 target detection model based on the YOLOv8 algorithm, and train the YOLOv8 target detection model using the dataset; S203. Use the trained YOLOv8 target detection model to perform target detection on the unlabeled image in the motion animal posture image to obtain the motion posture area of the unlabeled image animal, that is, the detection frame part of YOLOv8; S204. After the motion posture area detection is completed, all images in the motion animal posture image set will be cropped to retain only the image part of the motion posture area, and a Kalman filter or a Gaussian filter will be used to smooth the object motion trajectory, and a threshold detection or time window method will be used to remove animal motion abnormal points, and finally a motion posture area image set of various animals will be obtained.
5. The method for real-time detection and target tracking of animals in motion according to claim 1, characterized in that: The step S3 comprises: S301. From the animal motion posture area image set detected by YOLOv8, select 15% of the images for each action, use Labelimg image annotation tool to annotate the head and limb postures, and obtain a JSON file after annotation to form a dataset in VOC dataset format; S302. Construct a DeepSORT model and use a dataset built in the VOC dataset format to train the feature extraction capability of the DeepSORT model. The head and limbs are used in DeepSORT training in order to accurately extract the movement posture changes of the limbs from the image. Although DeepSORT tracking relies on the detection frame provided by YOLOv8, it relies on the Kalman filter to match and track the movements of each animal based on the changes in the movements of the limbs and head during tracking. S303. Using the trained DeepSORT model to match the motion features and motion prediction results in consecutive frames: DeepSORT extracts feature vectors from the YOLOv8 detection frame, which reflects the overall appearance features of the animal in the detection frame, and then uses the Kalman filter in DeepSORT to predict the position of the target. When the animal is occluded or disappears temporarily, DeepSORT uses the Hungarian algorithm to associate the detection frame of the current frame with the tracking result of the previous frame, and predicts the feature vector and target position of the current frame; S304. Discarding unmatched trackers. Once the detection box and the tracker are matched, DeepSORT will update the state of the tracker, including position, speed, and appearance features, and the unmatched detection box will initialize a new tracker, and the unmatched tracker will be deleted after multiple unmatched times.
Citation Information
Patent Citations
Lightweight pedestrian tracking method in complex scene
CN115984969A
