When adding a virtual object to an existing image, it is important to match the original camera parameters as closely as possible. If the image is synthetic, obtaining the parameters from the creator would be ideal. Otherwise, some parameters can be inferred by analyzing the image.
For this analysis, let's assume a pinhole camera model with the optical axis at the center of the image. Parallel lines in the scene will converge at a vanishing point. In this specific image, we can accurately determine only one vanishing point:
The parallel lines in the image are also parallel to the ground plane, indicating that the vanishing point lies on the horizon. The horizon appears slightly below the center of the image, suggesting that the camera is pitched upwards.
Calculating the exact pitch, we find that the vanishing point is approximately 0.022 image heights (15 pixels) below the center of the image. This allows us to express the camera pitch in terms of the vertical field of view:
pitch = arctan(2 * tan(vfov/2) * 0.022)
We can also determine the yaw of the camera relative to the parallel lines. The vanishing point is about 0.010 image heights right of center, indicating a slight leftward yaw of the camera.
yaw = arctan(2 * tan(vfov/2) * -0.010)
In our three.js application, I adjusted the camera configuration section of the code accordingly:
var FOV = 75;
[...]
camera.position.x = 0;
camera.position.y = 200;
camera.position.z = 512;
var lookTarget = new THREE.Vector3().copy(camera.position);
var tanScale = 2 * Math.tan(FOV/2 * Math.PI/180);
lookTarget.x += -0.010 * tanScale;
lookTarget.y += 0.022 * tanScale;
lookTarget.z += -1;
camera.lookAt(lookTarget);
camera.updateProjectionMatrix();
To minimize perspective distortion, I moved the camera back and adjusted the field of view to 75 degrees. This resulted in the texture converging at the vanishing point more naturally:
Increasing the size of the floor geometry may be necessary to fully display the end of the floor due to the assumed depth resulting from a smaller field of view. Adjusting the field of view can fine-tune the texture foreshortening without altering the position of the vanishing point. Estimating the focal length of the image may be challenging, but in images with more features, it could be achievable, allowing inference of the field of view as well.