A method and a system for counting pigs in a pig house are provided. The system includes a computing device and an imaging device. The computing device has a processor and a storage device storing computer executable code. The computer executable code is configured to: receive images captured from one end to the other end of the house; detect keypoints in the images using a neural network; identify pig skeletons by associating several related keypoints; track the skeletons in the images to obtain trajectories; divide each image into an activated zone and a deactivated zone; designate a spatial value of 0 for the skeletons in the activated zone and a spatial value of 1 for the skeletons in the deactivated zone; summate first order difference of the spatial values for each trajectory to obtain a trajectory count; and add the trajectory counts to obtain pig count.
展开▼