Unable to serialize vpi.warp type object in python 3 using json, pickle and marshal - Vision Programming Interface, Jetson

Hi,

I tried serializing vpi.warpmap object using json.dumps(), pickle.dumps() and marshal.dumps() methods. However, I am getting the error - ‘Object of type WarpMap is not JSON serializable’.
Are VPI objects serializable? My end goal is to store the warpmap in a file and retrieve it later.
Can you kindly help.

Thanks

Hi,

VPI doesn’t support serialization currently.
Please convert it into other formats, ex numpy, first.

Thanks.

Thank you for the reply. I am able to convert a vpi.warpmap object to numpy array. However, I am unable to convert numpy array back to a vpi.warpmap object. My end goal is to use this warpmap in vpi.remap function for distortion correction.

Thanks

Hi,

You can manually serialize the parameter.
For example:

Serialize

# Create an uniform grid
grid = vpi.WarpGrid(imgSize)

# Create undistort warp map from the calibration parameters and the grid
undist_map = vpi.WarpMap.fisheye_correction(grid,
                                            K=camMatrix[0:2,:], X=np.eye(3,4), coeffs=coeffs,
                                            mapping=vpi.FisheyeMapping.EQUIDISTANT)

import pickle
with open('warpMap.pickle', 'wb') as f:
    pickle.dump([imgSize,camMatrix[0:2,:],np.eye(3,4),coeffs,vpi.FisheyeMapping.EQUIDISTANT], f)

Deserialize

with open('warpMap.pickle', 'rb') as f:
    [size,K,X,coeffs,mapping] = pickle.load(f)

grid = vpi.WarpGrid(size)

# Create undistort warp map from the calibration parameters and the grid
undist_map = vpi.WarpMap.fisheye_correction(grid, K=K, X=X, coeffs=coeffs, mapping=mapping)

Thanks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.