A deep learning approach that can calculate distance to obstacles
Actually, I don't think this is a problem that could be solved just from the image because it could be a small object that is really close or and big object really far. As far as I know, self driving cars use sensors for this. From what I found here, you would need the actual height of the object to calculate it from one image.

I strongly suspect you could also calculate the distance by having two images and then using the distance between the two cameras, and the Pythagorean theorem to calculate it. But that's just conjecture.