How to generate a VPI warpmap for polynomial distortion correction?

23 views Asked by At

I am able to follow the sample algorithm here: https://docs.nvidia.com/vpi/sample_fisheye.html#sample_fisheye_code for the fisheye lens correction algorithm but I want to use polynomial correction. I found the method

vpi.WarpMap.polynomial_correction(grid: vpi.WarpGrid, Kin: 2D array, X: 2D array, Kout: 2D array, rcoeffs: 1D array, tcoeffs: 1D array = None)

to replace

vpi.WarpMap.fisheye_correction(grid: vpi.WarpGrid, Kin: 2D array, X: 2D array, Kout: 2D array, coeffs: 1D array, mapping: vpi.FisheyeMapping)

but the parameter list is a bit different and I can not figure out how to create those parameters. There is no simple replacement for line 102's cv2.fisheye.calibrate(...) (how I orginally was able to generate the fisheye correction params) for polynomial distortion in the openCV documentation.

However, I am able to follow this tutorial https://docs.opencv.org/4.x/dc/dbb/tutorial_py_calibration.html undistort my photos but I want to use VPI. How can I generate a VPI warpmap for polynomial distortion correction? I tried doing vpi.WarpMap.polynomial_correction(grid=grid, K=camMatrix[0:2, :], X=np.eye(3, 4), rcoeffs=coeffs) where camMatrix is newcameramtx and coeffs is dist[0] generated from

ret, mtx, dist, rvecs, tvecs = cv.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)

newcameramtx, roi = cv.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h))

from that OpenCV tutorial but it does not work (the resulting image is distorted way too much).

Thank you! Any guidance is appreciated.

0

There are 0 answers