Object detection inside a compartment

Hi everyone, I’m working on a project where I need to detect an object inside a compartment. I’m considering two ways to handle this.

The first approach is to train a YOLO model to identify the object and the compartment separately, and then use Python math to calculate if the object is physically inside. The compartment has a grille/mesh gate (see-through). It is important to note that the photos will be taken by clients, so the camera angle will vary significantly from photo to photo.

The second approach I thought of is to train the YOLO model to specifically identify the “object inside” and “object outside” as two different classes. Is valid to say that on the future I will need measure the object size based on the gate size, because there are same objects that has amost the shape but a different size.

Which method do you think is best to handle these variable angles?

The first approach is more deterministic and explainable. Although the model can learn relationships, it also increases the data requirement for the model to “understand” the exact relationship.