Abstract:
In the context of fence farming, cattle monitoring mainly relied on manual inspections. When cattle escaped near the edge of the fence, it was difficult for traditional regulatory means to detect and intervene in time, resulting in the loss of cattle and economic losses to farmers. To address this, a cattle area monitoring and boundary-crossing early warning method was proposed. It is based on instance segmentation and multi-object tracking, named STWBD (Segment Tracking with Boundary Detection). The goal was to monitor cattle activities in real time within the fenced area and provide intelligent early warnings of potential boundary-crossing behaviors. This method aimed to enhance the safety management level of fenced cattle farming.Firstly, an improved RDL-YOLO11n-seg instance segmentation model was constructed. The C3K2-RetBlock module was introduced to the original YOLO11n-seg, which enhanced the model's response capability to the spatial displacement of cattle. It combined the C2DA structure to improve the expression of multi-scale features. The Segment-LSCD module was employed to optimize the segmentation head, which facilitated the collaborative processing of object detection and instance segmentation. The above improvements made the model more accurate in capturing cattle contours and postures. As a result, it enhanced spatial perception and real-time monitoring of cattle within the fenced area.Next, the DeepOCSORT algorithm assigned an identity ID to each cattle, allowing continuous tracking in different scenarios. This algorithm effectively handled challenges such as small target scale, severe occlusion, poor lighting, and cattle close to the boundary. It ensured continuity and stability of multi-object tracking, giving reliable trajectory data for later boundary-crossing behavior detection.In terms of fence boundary design, this study combined the actual structure of cattle shed fences to construct a polygonal electronic fence, which defined the safe activity area of cattle. To achieve continuous analysis of movement trajectories and position distribution of cattle, the system integrated functions such as trajectory visualization, real-time speed tracking, and real-time statistics of cattle population. On this basis, the STWBD method can monitor the boundary-crossing behavior of cattle in real time and trigger intelligent early warnings promptly.Experimental results showed that the precision, recall, and segmentation accuracy of the RDL-YOLO11n-seg model reached 94.9%, 87.4%, and 92.5% respectively, which were 2.0, 3.1, and 3.1 percentage points higher than the original model, and the model parameters were reduced by 17.8%, with a floating-point operation count of 8.6 GFLOPs. The high order tracking accuracy (HOTA), multiple object tracking accuracy (MOTA), and identity F1-Score (IDFI) of DeepOCSORT were 81.4%, 91.6%, and 95.8%, and the precision, recall and F1 score of escape event detection were 96.2%, 100% and 98.1%, respectively. The research results showed that this method can efficiently monitor the movement trajectories of cattle in small-scale fenced farming environments and effectively identify boundary-crossing escape events, providing reliable technical support for intelligent early warning and supervision of cattle. This method provides real-time access to cattle population, distribution, and movement patterns, while enabling risk prediction through trajectory and speed analysis. It supports proactive management and loss prevention, offering a scientific basis for the secure and efficient management of confined cattle farming.