1 | initial version |
If I were you I would start with something even much simpler than what @berak suggested. Instead of calibrating the camera, have a reference object of known size and location in your image.
From here on, you simply have to convert the pixels to the reference object's metric in order to determine the distance of any other object(s) from the reference object. This and this blog posts do exactly that. The first one shows you how to measure the size of objects whilst the latter discusses distance. I would recommend reviewing the first link followed by the second one.
Thereafter you can go ahead and generalize the concept all together.
2 | No.2 Revision |
If I were you I would start with something even much simpler than what @berak suggested. Instead of calibrating the camera, have a reference object of known size and location in your image.
From here on, you simply have to convert the pixels to the reference object's metric in order to determine the distance of any other object(s) from the reference object. This and this blog posts do exactly that. The first one shows you how to measure the size of objects whilst the latter discusses distance. I would recommend reviewing the first link followed by the second one.
Thereafter you can go ahead and generalize the concept all together.
PS: I am suggesting this method first because judging by your recent questions, you sound like a newbie and I wouldn't want you to get lost copy pasting code without having a general grasp of what is actually happening.