I calibrated a wide angle camera (~120° horizontal, ~110° vertical) using the Pinhole camera model. The result is quite good but large areas of the image are discarded.
So I'm trying to use the getOptimalNewCameraMatrix function (using alpha = 1) to calculate the newCameraMatrix and then pass it to cv::undistord, but the resulting frame is really distorted.
.
The code I use is:
// Matrices calculation
data.rms = calibrateCamera(objectPoints, imagePoints, data.size, data.cameraMatrix,
data.distCoeffs, data.rvecs, data.tvecs, settings.calibFlags);
if(!settings.cropCorrected) {
Rect roi;
data.newCameraMatrix = getOptimalNewCameraMatrix(data.cameraMatrix, data.distCoeffs,
data.size, 1, data.size, &roi, true);
}
// Undistort
cv::undistort(in, corrected, cameraMatrix, distCoeffs, newCameraMatrix);
This is simple but there is something not working. I have already tried to use roi to crop the inner area, in the hope that it would have been anyway bigger than without the additional matrix, but in fact it was much smaller.
How can i resolve the situation?