Abstract:The milking process is a high-risk phase for stress responses and animal welfare issues in dairy cows; automated monitoring of abnormal behaviors is crucial for improving milking management and ensuring cow welfare. Aiming to address the challenges in herringbone milking parlors, such as limited space, multiple cows entering the field of view simultaneously, frequent occlusions, and erratic individual trajectories, the detection of abnormal cow behaviors was investigated based on facial landmark trajectories, specifically tailored to the unique environment of herringbone milking parlors. Using DeepLabCut as the keypoint detection module, stall position constraints and cow-face orientation constraints were introduced to correct multi-cow trajectories, and combined scenario-specific behavioral features with rule-based classification to achieve event-level anomaly detection. Experimental results showed that the dual-constraint fusion correction based on stall position and cow face orientation reduced the number of keypoint ID changes for multiple cows from 18. 500 to 0. 125, while increasing accuracy from 93. 83% to 99. 96% . In event-level detection of abnormal behavior, the precision, recall, false negative rate, and false positive rate for single-cow abnormal behavior events were 96. 55% , 96. 55% , 3. 45% , and 3. 45% , respectively. For multi-cow interactive abnormal behavior event-level detection, the precision, recall, false negative rate, and false positive rate were 85. 71% , 100% , 0, and 14. 29% , respectively. The keypoint detection module achieved a precision of 98. 69% , a recall of 98. 61% , a mean average precision of 97. 22% , and a standardized mean error of 5. 31% . This method can provide a viable solution for the automatic detection of abnormal behaviors in fixed-view milking scenarios, offering good interpretability and engineering applicability.