Development of a computer vision system to detect inactivity in group-housed pigs

Christopher Chijioke Ojukwu, Y. X. Feng, Guifeng Jia, Haitao Zhao, Hequn TaInternational Journal of Agricultural and Biological Engineering 2020 · DOI

TL;DR

Researchers have developed "DepInact," a computer vision system that uses overhead depth cameras to automatically monitor inactivity in group-housed pigs. By tracking individual pigs over time and flagging those that remain immobile for more than a minute, the system achieved an 85.7% accuracy rate, offering a promising automated tool for early illness detection in precision livestock farming.

What Problem Does This Paper Address?

In the world of swine farming, a pig that doesn't move is often a pig that is in trouble. Excessive inactivity is a primary clinical sign of illness, stress, or injury. However, in modern group-housing environments, monitoring individual behavior is a Herculean task for human workers. Manual inspection is time-consuming, subjective, and prone to error.

While computer vision (CV) has been applied to farming before—mostly for weighing animals or detecting lameness (problems of motion)—there is a significant gap in technology designed to monitor lack of motion. The challenge is twofold: first, identifying individual pigs when they are huddled together (a common behavior), and second, distinguishing between a pig that is naturally resting and one that is pathologically inactive over a specific duration.

Methods

The authors developed a system called DepInact, implemented in Matlab, which utilizes a top-down Microsoft Kinect sensor.

The technical pipeline involves several key steps:

  1. Depth Imaging: Unlike standard RGB cameras, depth sensors are less affected by the variable lighting conditions of a barn. The camera was mounted 2.6 meters above the pen floor.
  2. Segmentation & Filtering: The system converts depth data into grayscale and then binary images. It specifically filters out standing pigs (assuming they are active) and uses "blob analysis" to identify lying or squatting pigs. Blobs are filtered by size (2,000 to 13,000 pixels) to ensure the system is looking at individual animals rather than the floor or a large huddle.
  3. The Logic Loop: The core innovation is the temporal comparison. The algorithm compares a "new image" to an "old image." If the mean depth value of a pig at specific coordinates remains within a certain threshold ($\alpha$) across 15 consecutive loops (sampled every 4 seconds), the pig is flagged as inactive.
  4. Support Mapping: The system maintains a "support map" that tracks the coordinates and "inactive timer" for each identified pig, allowing it to keep tabs on individuals even as others move around them.

Datasets

The study used a custom dataset collected from a professional pig farm in Anhui Province, China.

  • Subjects: Landrace × Yorkshire crossbred sows (1-2 years old).
  • Data Volume: 656 pairs of synchronized depth and color images.
  • Sampling: Images were captured every 4 seconds during the pigs' most active morning hours (08:00 to 11:00).
  • Ground Truth: Manual verification was performed by humans reviewing the color images to identify every instance where a pig remained inactive for at least 60 seconds.

Key Insights and Ideas

  • The "Contact" Workaround: One of the biggest hurdles in group housing is "over-segmentation"—when two pigs touching each other look like one giant blob to a computer. The authors realized that because active pigs eventually move to eat or drink, an inactive pig will eventually "emerge" as a single, detectable blob. The system is designed to catch them at that moment.
  • Depth over Color: By using depth data, the researchers avoided the "camouflage" effect where a pig's skin color might blend into a dirty floor, a common failure point for traditional RGB cameras.
  • The Threshold "Goldilocks Zone": The researchers found that the sensitivity threshold ($\alpha$) isn't linear. If the threshold is too low, tiny sensor noises are interpreted as movement; if it's too high, actual shifts in posture are ignored. They identified 75 pixels as the optimal threshold for maximizing correct identifications.

Key Results

  • Accuracy: The system correctly identified 6 out of 7 inactivity scenarios confirmed by human observers, resulting in an 85.7% accuracy rate.
  • Efficiency: The algorithm processed the 656-image batch in approximately 105 seconds, suggesting it is capable of near real-time monitoring.
  • Proof of Concept: The study successfully demonstrated that a 60-second inactivity window (15 loops at 4-second intervals) is a viable metric for triggering a digital alarm for farmers.

Limitations and Future Work

The authors are transparent about the system being a prototype with room for growth:

  • Complex Segmentation: The current logic still struggles with pigs in constant physical contact. The authors suggest that integrating Machine Learning (specifically deep learning for instance segmentation) could help the system "learn" to tell two touching pigs apart more reliably.
  • Scalability: The pixel-size filters for "a single pig" are currently hard-coded. Future versions would need to automatically adjust based on the age and growth stage of the pigs.
  • Clinical Validation: While the system detects inactivity, more research is needed to determine exactly how many minutes of inactivity constitute a medical emergency for different pig breeds and ages to minimize false alarms.

Summary updated

Abstract

Excessive inactivity in farm animals can be an early indication of illness. Traditional way for detecting excessive inactivity in pigs relies on manual inspection which can be laborious and especially time-consuming. This paper proposed a computer vision system that could detect inactivity of individual pigs housed in group pens which is potential in alarming the farmer of the animals concerned. The system recorded sequential depth images for the animals in a pen and implemented a proposed image processing and logic analysis scheme named as ‘DepInact’ to keep track of the inactive time of group-housed individual pigs over time. To verify the robustness and accuracy of the developed system, a total of 656 pairs of corresponding depth data and color images, consecutively taken 4 s apart from each other, were attained. The verification process involved manually identifying all pigs using the color images captured. The results of identification of all pigs that were inactive for more than the preset period of time by DepInact were compared to those by manual inspection through the color images captured. An accuracy of 85.7% was achieved using the verification data, thus demonstrating that the developed system is a viable alternative to manual detection of inactivity of group-housed pigs. Nevertheless, more research is still needed to improve the accuracy of the developed system. Keywords: Matlab, computer vision, sows, machine vision, depth image, pigs, inactivity DOI: 10.25165/j.ijabe.20201301.5030 Citation: Ojukwu C C, Feng Y Z, Jia G F, Zhao H T, Tan H Q. Development of a computer vision system to detect inactivity in group-housed pigs. Int J Agric & Biol Eng, 2020; 13(1): 42–46.
BibTeX
@article{ojukwu2020development,
  author = {Christopher Chijioke Ojukwu and Y. X. Feng and Guifeng Jia and Haitao Zhao and Hequn Ta},
  title = {{Development of a computer vision system to detect inactivity in group-housed pigs}},
  journal = {International Journal of Agricultural and Biological Engineering},
  year = {2020},
  doi = {10.25165/j.ijabe.20201301.5030},
}
Figure