Given an image of a rectangle (and assuming I could find the corners of that rectangle), what is the math I would need to determine where I am relative to the center of the rectangle, assuming that I am on a flat plane with the rectangle affixed to the wall. I have worked out the math to solve this problem if the camera is at the height of the rectangle, but I need to solve for a camera that is a couple feet below the rectangle. Here is what I have so far:
Beforehand, you could measure the height of the rectangle at say, 10 feet, to find the height (in px) in the image, once that is done, you can dynamically figure out the distance by averaging h1 and h2, and multiplying by the predetermined ratio. As the camera approaches 90° on either side of the rectangle, w approaches 0, so since the ratio of w/h is known before hand, you can use that to figure out what the width would be if you were viewing the rectangle straight on at a given distance. Then, you take the ratio of w to w', giving you a ratio ranging from 1 (when viewing straight on), to 0 (at 90°). Take the arccos of that, and you should get a degree measure, giving you all you need to have polar coordinates of the location of the camera based on the image.
However, when the camera is not at the height of the rectangle, there is vertical warping that will happen as well. How can I account for this in the calculations?