Hello,
I’m trying to use the polynomial lens distortion correction, but I’m having trouble getting vpi.WarpMap.polynomial_correction()
to accept my input. I think I’m using the proper parameters as described here, but when I run the code below it fails on line 201 with the error:
Traceback (most recent call last):
File "./cudatest.py", line 415, in <module>
dewarped = processor.linear_dewarp(flipped_image)
File "./cudatest.py", line 187, in linear_dewarp
grid = vpi.WarpGrid((image.width, image.height))
TypeError: polynomial_correction(): incompatible function arguments. The following argument types are supported:
1. (grid: vpi.WarpGrid, *, Kin: numpy.ndarray[numpy.float32], X: numpy.ndarray[numpy.float32], Kout: numpy.ndarray[numpy.float32], rcoeffs: numpy.ndarray[numpy.float32], tcoeffs: numpy.ndarray[numpy.float32] = array([], dtype=float32)) -> vpi.WarpMap
2. (grid: vpi.WarpGrid, *, K: numpy.ndarray[numpy.float32], X: numpy.ndarray[numpy.float32], rcoeffs: numpy.ndarray[numpy.float32], tcoeffs: numpy.ndarray[numpy.float32] = array([], dtype=float32)) -> vpi.WarpMap
Invoked with: <vpi.WarpGrid(regions=([, array([[1., 1., 1.],
[1., 1., 1.]], dtype=float32), array([[1., 1., 1., 1.],
[1., 1., 1., 1.],
[1., 1., 1., 1.]], dtype=float32), array([0.1, 0.1], dtype=float32), array([0., 0.], dtype=float32)
Note that the invoked with:
section seems to match the second supported argument type. I’m not sure what’s wrong.
Any help is appreciated.
######### CODE #########
184 def linear_dewarp(self, image, k1=0.1, k2=0.1, k3=0, k4=0, k5=0, p1=0, p2=0):
185 # Create a dense warp map for warping the distorted image into the corrected output.
186
187 grid = vpi.WarpGrid((image.width, image.height))
188
189 # Create the undistortion warp map from the radial and tangential coefficients.
190 Kin = np.ones((2, 3), dtype=np.float32) # Camera intrinsic parameters
191 K = Kin
192 X = np.ones((3, 4), dtype=np.float32) # Camera extrinsic parameters that define the camera center position and it's heading i n the world coordinates.
193 Kout = np.ones((2, 3), dtype=np.float32) # New camera intrinsic parameters applied to the undistorted image. Set Kout the sam e as Kin if missing (monocular camera).
194 rcoeffs = np.array([k1, k2], dtype=np.float32) # The radial distortion coefficients.
195 #rcoeffs = np.array([k1, k2, k3, k4, k5], dtype=np.float32) # The radial distortion coefficients.
196
197 tcoeffs = np.array([p1, p2], dtype=np.float32) # The tangential distortion coefficients.
198
199
200 #warp = vpi.WarpMap.polynomial_correction(grid, Kin, X, Kout, rcoeffs, tcoeffs)
201 warp = vpi.WarpMap.polynomial_correction(grid, K, X, rcoeffs, tcoeffs)
202
203 with vpi.Backend.CUDA:
204 output = image.remap(warp, interp=vpi.Interp.CATMULL_ROM, border=vpi.Border.ZERO)
205 return output