OpenCV - 鱼眼校准值(重复使用 JSON 文件中保存的值)

OpenCV - Fisheye Calibration Values (Reuse values saved in JSON file)

我已经校准了我的鱼眼相机以获得新的矩阵和参数。我已将它们保存在 JSON 文件中。现在我再次使用 JSON 文件来校准我的相机时遇到了问题。

引用自https://github.com/mesutpiskin/opencv-fisheye-undistortion/blob/master/src/python/fisheye_calibration_undistortion.py

''''
I have realized the K has a different structure. e.g.
<class 'numpy.ndarray'>
[[ 2.01424373e+06  0.00000000e+00  6.50364504e+02]
 [ 0.00000000e+00  2.04712849e+06 -5.14192522e+02]
 [ 0.000000

00e+00  0.00000000e+00  1.00000000e+00]]
''''

保存值,'K':np.asarray(K).tolist()(读取时需要转换回来???)

'''
data = {'dim1': dim1,'dim2':dim2,'dim3': dim3,'K': np.asarray(K).tolist(),'D':np.asarray(D).tolist(),'new_K':np.asarray(new_K).tolist(),'scaled_K':np.asarray(scaled_K).tolist(),'balance':balance}
                
import json
with open("fisheye_calibration_data.json", "w") as f:
    json.dump(data, f)    
'''

正在从 JSON 中读取值(这里有问题)

'''
with open('fisheye_calibration_data.json') as json_file:

    data = json.load(json_file)
    dim1 = data["dim1"]
    dim2 = data["dim2"]
    dim3 = data["dim3"]
    K = data["K"]
    D = data["D"]
    new_K = data["new_K"]
    scaled_K = data["scaled_K"]
    balance = data["balance"]
    
new_K = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(scaled_K, D, dim2, np.eye(3), balance=balance)

map1, map2 = cv2.fisheye.initUndistortRectifyMap(scaled_K, D, np.eye(3),new_K, dim3, cv2.CV_16SC2)
    
undistorted_img = cv2.remap(frame, map1, map2,interpolation=cv2.INTER_LINEAR,borderMode=cv2.BORDER_CONSTANT) 
'''

获得错误:

-----------------ERROR_----------------------
    new_K = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(scaled_K, D,dim2, np.eye(3), balance=balance)

TypeError: Expected cv::UMat for argument 'K'

dim1 = 元组(数据["dim3"]) K = np.array(数据["K"])