undistort function
- InputArray src,
- InputArray cameraMatrix,
- InputArray distCoeffs, {
- OutputArray? dst,
- InputArray? newCameraMatrix,
Transforms an image to compensate for lens distortion. The function transforms an image to compensate radial and tangential lens distortion. The function is simply a combination of initUndistortRectifyMap (with unity R ) and remap (with bilinear interpolation). See the former function for details of the transformation being performed. Those pixels in the destination image, for which there is no correspondent pixels in the source image, are filled with zeros (black color). A particular subset of the source image that will be visible in the corrected image can be regulated by newCameraMatrix. You can use getOptimalNewCameraMatrix to compute the appropriate newCameraMatrix depending on your requirements. The camera matrix and the distortion parameters can be determined using calibrateCamera. If the resolution of images is different from the resolution used at the calibration stage, fx,fy,cx and cy need to be scaled accordingly, while the distortion coefficients remain the same.
Implementation
Mat undistort(
InputArray src,
InputArray cameraMatrix,
InputArray distCoeffs, {
OutputArray? dst,
InputArray? newCameraMatrix,
}) {
dst ??= Mat.empty();
newCameraMatrix ??= Mat.empty();
cvRun(
() => ccalib3d.cv_undistort(
src.ref,
dst!.ref,
cameraMatrix.ref,
distCoeffs.ref,
newCameraMatrix!.ref,
ffi.nullptr,
),
);
return dst;
}