I am using OpenCV to calibrate images taken using cameras with fish-eye lenses.
The functions I am using are:
findChessboardCorners(...);
to find the corners of the calibration pattern.cornerSubPix(...);
to refine the found corners.fisheye::calibrate(...);
to calibrate the camera matrix and the distortion coefficients.fisheye::undistortImage(...);
to undistort the images using the camera info obtained from calibration.
While the resulting image does appear to look good (straight lines and so on), my issue is that the function cut away too much of the image.
This is a real problem, as I am using four cameras with 90 degrees between them, and when so much of the sides are cut off, there is no overlapping area between them which is needed as I am going to stitch the images.
I looked into using fisheye::estimateNewCameraMatrixForUndistortRectify(...)
but I could not get it to give good results, as I do not know what I should put in as the R
input, as the rotation vector output of fisheye::calibrate
is 3xN (where N is the number of calibration images) and fisheye::estimateNewCameraMatrixForUndistortRectify
requires a 1x3 or 3x3.
The images below show an image of my undistortion result, and an example of the kind of result I would ideally want.
Undistortion:
Example of wanted result:
I think I have ran into a similar issue, looking for the "alpha" knot in getOptimalNewCameraMatrix for fisheye.
Original shot:
I calibrated it with cv2.fisheye.calibrate, got the K and D parameters
This is what I get with
And I think it chops too much. I want to see the whole Rubik's cube
I fix it with
TADA!
I stacked the same problem. And if FOV of your camera ~ 180 degrees, I think you will not be able to undistort 100% of initial image surface. More detailed explanation I placed here
You are doing fine, you just have to use
getOptimalNewCameraMatrix()
to setnewCameraMatrix
inundistort()
. In order to get all pixels visible, you have to setalpha
to 1 ingetOptimalNewCameraMatrix()
.As mentioned by Paul Bourke here:
To get a projection without image cropping, (and your camera has ~180 degrees FOV) you can project the fisheye image in a square using something like this:
Source code: