Hi,
I’m trying to visualize the undistorted images after performing a basic camera calibration using the cv.undistort() and cv.getOptimalNewCameraMatrix() functions. The problem is that I’m not sure how to retain all the original pixels without distorting the image.
I first assumed that in order to do so, the only thing I needed was to use an alpha=1 when calling the function getOptimalNewCameraMatrix(). But the image looks like squeezed and the region inside the ROI looks different compared to the image provided using an alpha=0. I guess it is because it is trying to fit the new undistorted image to the original resolution of the image which has a different aspect ratio?
Is there a way to undistort the image, don’t lose any pixels in the process but also don’t stretch out the result because of a change in the aspect ratio?
Here are some of the different configurations I tried using the parameters alpha, croping and centerPrincipalPoint:
Calibration matrix:
[[10328.62 0. 719.12]
[ 0. 10131.19 903.98]
[ 0. 0. 1. ]]
Distortion coefficients:
[[ 20.99 -424.72 0.84 -0.39 9315.43]]
- Undistorted image without using a new calibration matrix:
- Undistorted image using a alpha=0
new matrix[
[11534.85 0. 685.07]
[ 0. 11104.3 1002.86]
[ 0. 0. 1. ]] - Undistorted image using alpha=1 (cropped and no cropped):
new matrix:
[[10926.47 0. 680.3 ]
[ 0. 9342.57 924.02]
[ 0. 0. 1. ]]
I also tried using the parameter centerPrincipalPoint=True, which gives newCalibration matrix with fx/fy that is the same for both the new and original matrix. (There I expect that there is no distortion here), but gives a strange output for alpha=0
-
Undistorted image using alpha=0 and centerPrincipalPoint=True
new matrix:
[[80212.26 0. 959.5 ]
[ 0. 78679.02 539.5 ]
[ 0. 0. 1. ]] -
Undistorted image using alpha=1 and centerPrincipalPoint=True with and without cropping.
new matrix:
[[5561.07 0. 959.5 ]
[ 0. 5454.77 539.5 ]
[ 0. 0. 1. ]]
I know the distortion that the distortion coefficient and the original matrix that OpenCV found during the calibration are wrong, but I still would like to understand how can I get the undistorted image.
I hope I have explained myself.
Do you have any suggestions to achieve this? I would like to obtain an undistorted image that does not lose any of the original pixels and it is not squeezed because of the original resolution of the image.
Thanks,