Calculate square's 3d rotation and position from it's dimension and pixel coordinates

36 Views Asked by At

Let assume that I have a picture of a square table and I want to put 3d cube on top of it like this : table image

and I have this information : pixel coordinates

How can I calculate the transformation matrix? I believe that the answer is in the perspective coordinates but I couldn't figure it out.