I made a blender add-on for matching the camera position, rotation and focal length to the view in a photograph. All that is required is having a perspective view of a rectangle in the image.
You can find the add-on on https://github.com/mrossini-ethz/camera-calibration-pvr along with instructions about how to install and use it. Here is a short version of the usage for users that are experienced with blender:
- Use the photograph as a background image in the 3D viewport.
- Create a new plane mesh.
- In top view and in edit mode, move the vertices of the plane to the corners of the rectangle in the photograph.
- Leave edit mode and press the Camera Calibration button in the tool shelf (in the Misc tab).
The image below uses this method to insert 3D shapes into a photgraph. To match the perspective, the grid lines on the paper are used to define a rectangle. In case it is not obvious: The dragon as well as the array of cubes have been added using blender. Credit to the dragon model goes to Stanford Computer Graphics Laboratory (https://graphics.stanford.edu/data/3Dscanrep/).
I am aware that there is another add-on that does practically the same. However, I have never gotten that one to work for me. Consider this as an alternative, especially if you had similar experiences.
The current version is still somewhat experimental. I welcome any suggestions that may simplify the usage or add new features. This thread is not only intended to spread the word, but also to receive feedback to improve the add-on.