# A Review of Posture Detection Methods for Pigs Using Deep Learning
## 2 Data Acquisition and Sub-Tasks for Pig Posture Detection
### Sub-Tasks for Image-Based Pig Posture Detection
#### 2.2.1 Pig Localization  
Pig localization refers to finding the precise position of all pigs and then either separating the contours of pigs from the background [35], framing them with bounding boxes [38], or generating a series of key points to represent their outline [39] in a given image or a specific video frame, which are exemplified in Figure 3 (The images used for this figure was sourced from the datasets of Psota [40], and the same applies to Figures 4-7). This is a fundamental issue in the computer vision field and also a precondition for pig posture detection. Figure 4: Example of pig posture classification. Figure 3: Examples of pig localization: (**a**) Example of pig localization by contours; (**b**) Example of pig localization by bounding boxes; (**c**) Example of pig localization by key points. (Blue marks indicate left and right neck, purple marks indicate left and right shoulder, green marks indicate left and right abdomen, red marks indicate left and right hip, and yellow marks indicate left and right tail [39]). Figure 2: The processes of utilizing acquired data to address real-world problems. Figure 5: (**a**) Example of pig segmentation mask; (**b**) Example of pig identification and tracking. Figure 6: A typical two-stage model pipeline for pig posture detection. Figure 7: A typical one-stage model diagram for pig posture detection. (The image is divided into grids, and within each grid cell, bounding boxes, confidence scores, and class probabilities for different posture types are predicted simultaneously). In early pig posture detection practices, pig localization was accomplished by extracting the binary contours of pigs from the background, which can be implemented by the threshold segmentation algorithm and watershed transformation [7; 41]. However, posture detection with this scheme largely depends on the effect of segmentation algorithms since the contour quality has a direct influence on the feature extraction of contours, which will further influence the posture classification [42]. The sliding window technique once attracted great interest as a standard method in inchoate object detection models, such as pedestrian detection [43], which scans all possible locations in an image at different scales to determine the presence of any target within a window [44]. Using sliding windows and integrating principal component analysis convolution, [PERSON] et al. [45] obtained a recall rate of up to 99.21% and a classification accuracy of 95.21% on pig detection when using 500 windows. The use of sliding windows can ensure that every area in an image can be noted by the detector, resulting in an omission detection rate and misdetection rate lower than those of You Only Look Once (YOLO) [46] and a detection speed faster than that of the Faster region convolutional neural network (Faster R-CNN) [47]. However, the sliding window also has the disadvantages of low computational efficiency and the reliance of window size and ratio on manual design. To optimize the sliding window, a conception of region proposals [48] within the \"recognition using regions\" paradigm [49] was proposed in region-based convolutional neural networks (R-CNN) [48] series object detectors, which can selectively generate category-independent object proposals for the input image instead of scanning through the whole image. In R-CNN and Fast R-CNN, selective search [50] is used to generate object proposals that will be further estimated whether there is any object within the region by SVM. The most popular model in the R-CNN series used for pig posture detection is Faster R-CNN, which performs region proposals by a region proposal network (RPN) [47] and introduces the creation of anchor boxes that can generate high-quality region proposals cost-effectively. Application of Faster R-CNN to pig posture detection enables timely localization of pig position with a high average precision (AP) of 87.4% [51].