# Depth-Oriented Gray Image for Unseen Pig Detection in Real Time
## 1 Introduction
To overcome these limitations, recently developed foundation models have emerged as transformative tools for object detection and segmentation. These models, trained on extensive datasets, demonstrate high adaptability to diverse tasks and environments. The Segment Anything Model (SAM) [14] offers robust segmentation performance with minimal user input, effectively separating foreground and background across varied conditions. Large Mask Inpainting (LaMa) [15] enhances masked areas by leveraging surrounding pixels, achieving high performance in background restoration tasks. Additionally, Depth Anything [16] uses depth information to accurately distinguish objects' physical positions from the background, maintaining stable performance even in challenging lighting conditions or complex facility layouts. By analyzing the depth information in c and f, it becomes evident that leveraging depth-based techniques could provide a promising solution to the aforementioned errors. To address these issues, this study proposes a method for generating Depth-Oriented Gray (DOG) images using foundation models such as the SAM, LaMa, and Depth Anything. This approach establishes the RoI in unseen environments and effectively generalizes the brightness of objects and backgrounds in test images. The proposed method improves detection accuracy by accurately distinguishing between foreground and background, even in complex environments. Foundation models are transformer-based architectures that require significant processing time and high-performance computing resources. However, the proposed method achieves real-time processing by utilizing foundation models only during the initialization phase, significantly enhancing both detection accuracy and speed. The contribution of this study is as follows:  
* This study proposes a new method that utilizes foundation models, including the SAM, LaMa, and Depth Anything, to accurately separate the foreground and background based on depth information in pigpens. The method effectively generates depth background images and establishes the RoI, even in test environments with diverse lighting conditions and high background complexity. * The proposed method generates DOG images by combining HSV-Value, inverted HSV-Saturation images, and the generated depth background images. This approach is designed to maintain high detection and generalization performance, leveraging depth information to address the accuracy degradation issues observed in conventional detection models when applied to unseen test environments. * This study proposes a cost-effective approach to utilizing depth information without requiring additional depth sensors by leveraging the Depth Anything model. In unseen test environments, depth background images are generated only once using  
Figure 1: Comparison of YOLO detection results and Depth Anything results. **(a,d)** Input images, **(b,e)** YOLO detection results, and **(c,f)** Depth Anything results. The primary reason for errors in YOLO detection results is that, unlike foundation models, it has not been trained on a sufficiently diverse range of environmental data. GPU-based Depth Anything. Subsequently, input images are processed in real time using CPU-based DOG image generation. This method enables operation on systems equipped with low-cost CPUs and GPUs, significantly reducing system setup costs.