Pig behavior recognition and tracking in group-housed livestock are effective aids for health and welfare monitoring in commercial settings. However, due to demanding farm conditions, the targets in the pig videos are heavily occluded and overlapped, and there are illumination changes, which cause error switches of pig identify (ID) in the tracking process and decrease the tracking quality. To solve these problems, this study proposed an improved DeepSORT algorithm for object tracking, which contained three processes. Firstly, two detectors, YOLOX-S and YOLO v5s, were developed to detect pig targets and classify four types of pig behaviors including lying, eating, standing, and other. Then, the improved DeepSORT was developed for pig behavior tracking and reducing error changes of pig ID by improving trajectory processing and data association. Finally, we established the public dataset annotation of group-housed pigs, with 3600 images in a total from 12 videos, which were suitable for pig tracking applications. The advantage of our method includes two aspects. One is that the trajectory processing and data association are improved by aiming at pig-specific scenarios, which are indoor scenes, and the number of pig target objects is stable. This improvement reduces the error switches of pig ID and enhances the stability of the tracking. The other is that the behavior classification information from the detectors is introduced into the tracking algorithm for behavior tracking. In the experiments of pig detection and behavior recognition, the YOLO v5s and YOLOX-S detectors achieved a high precision rate of 99.4% and 98.43%, a recall rate of 99% and 99.23, and a mean average precision (mAP) rate of 99.50% and 99.23%, respectively, with an AP.5:.95 of 89.3% and 87%. In the experiments of pig behavior tracking, the improved DeepSORT algorithm based on YOLOX-S obtained multi-object tracking accuracy (MOTA), ID switches (IDs), and IDF1 of 98.6%,15, and 95.7%, respectively. Compared with DeepSORT, it improved by 1.8% and 6.8% in MOTA and IDF1, respectively, and IDs had a significant decrease, with a decline of 80%. These experiments demonstrate that the improved DeepSORT can achieve pig behavior tracking with stable ID values under commercial conditions and provide scalable technical support for contactless automated pig monitoring.