Actually there is no need to involve an orthographic camera. Here is how you can get the appropriate perspective transform.
If you calibrated the camera using cv::calibrateCamera
, you obtained a camera matrix K
a vector of lens distortion coefficients D
for your camera and, for each image that you used, a rotation vector rvec
(which you can convert to a 3x3 matrix R
using cv::rodrigues
, doc) and a translation vector T
. Consider one of these images and the associated R
and T
. After you called cv::undistort
using the distortion coefficients, the image will be like it was acquired by a camera of projection matrix K * [ R | T ]
.
Basically (as @DavidNilosek intuited), you want to cancel the rotation and get the image as if it was acquired by the projection matrix of form K * [ I | -C ]
where C=-R.inv()*T
is the camera position. For that, you have to apply the following transformation:
Hr = K * R.inv() * K.inv()
The only potential problem is that the warped image might go outside the visible part of the image plane. Hence, you can use an additional translation to solve that issue, as follows:
[ 1 0 | ]
Ht = [ 0 1 | -K*C/Cz ]
[ 0 0 | ]
where Cz is the component of C along the Oz axis.
Finally, with the definitions above, H = Ht * Hr
is a rectifying perspective transform for the considered image.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…