Abstract:Pig counting plays a crucial role in the management of slaughterhouse production and the estimation of assets. In response to the existing challenges of labor-intensive manual counting and elevated error rates within the pig counting processes of slaughterhouses, a meticulous pig counting methodology was introduced, leveraging an improved integration of YOLO v5 and StrongSORT. Initially, the improved YOLO v5 model incorporated real aspect loss and aspect ratio to enhance the performance of the loss function. Additionally, an efficient channel attention (ECA) mechanism was introduced into the Neck layer to augment the model’s recognition capabilities in complex environments. Subsequently, a detection mechanism was constructed based on StrongSORT to facilitate the re-identification of pigs. Finally, a pig counting method utilizing area ID information detection was introduced based on the StrongSORT framework. Experimental results demonstrated that the enhanced YOLO v5 algorithm achieved a pig recognition accuracy of 93.78%, a recall rate of 91.98%, and a mean average precision (mAP) of 96.29%, with a recognition speed of 500 frames per second (f/s). This represented a significant improvement of 1.14 percentage points in recall, 0.89 percentage points in mAP, and an 85.0% increase in frame rate compared with that of the YOLO v5s model. The accuracy of combining the improved YOLO v5 with the StrongSORT area counting method for pig counting was 98.46%, and the counting speed was 73f/s, which was 1.54 percentage points higher than the manual counting accuracy, 9.23 percentage points higher than the original model counting accuracy, and 21.87% higher than the counting speed. The pig counting method proposed demonstrated high accuracy and was well-suited for the enumeration of pigs in slaughterhouse settings.