<p>That's an ill-posed problem (you can not measure depth with a single RGB camera) and a topic of resent research. I found this <a href="https://arxiv.org/pdf/1901.09402.pdf" rel="nofollow noreferrer">survey paper</a>. Most often a depth image is learned from an RGB image using convolutional neural networks. </p>

<p>However, if you use a lot of prior information about your scene (all objects are circular within in the image and the partially visible circles corresponds to the ones which are in the background), then you might be able to do something with heuristical methods like, thresholding, edge detection or hough transforms, but it won't be easy.</p>
How to detect the relative depth of pixels on a image?
<p>I am trying to obtain the relative depth of pixels of an image. For example, the image in <a href="https://www.awn.com/news/nvidia-unveils-quadro-rtx-worlds-first-ray-tracing-gpu" rel="nofollow noreferrer">https://www.awn.com/news/nvidia-unveils-quadro-rtx-worlds-first-ray-tracing-gpu</a> . I don't need the precise distance of each pixel, which I believe would be impossible, but I would like to get something as "the green ball is further than the other balls". Is it possible using OpenCV in python? The codes I generated can identify each ball, but not their relative distance or depth, so they are pretty much useless to my intents.</p>