我使用OpenCV和Python进行了鱼眼镜头校准。我正在尝试使用校准数据将Python代码转换为Java。我正试图用Java改造鱼眼图像。 Python代码正在运行。但我在Java中遇到错误。可能是什么原因。
Python代码:
#all dims = (340,240)
img = cv2.imread("distort_frame.png")
scaled_K = K * dim1[0] / DIM[0] dimension.
scaled_K[2][2] = 1.0
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(img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
和Java
Mat K = new Mat(3, 3, CV_32FC1);
Mat scaled_K = new Mat(3, 3, CV_32FC1);
Mat new_K = new Mat(3, 3, CV_32FC1);
Mat R = new Mat();
Mat D = new Mat();
//--intrinsic
K.put(0, 0, 127.84727138433931);
K.put(0, 1, 0);
K.put(0, 2, 173.0489304268767);
K.put(1, 0, 0);
K.put(1, 1, 127.84747052767318);
K.put(1, 2, 117.5848550330597);
K.put(2, 0, 0);
K.put(2, 1, 0);
K.put(2, 2, 1);
//---scaled_intrinsic
scaled_K.put(0, 0, 127.84727138433931);
scaled_K.put(0, 1, 0);
scaled_K.put(0, 2, 173.0489304268767);
scaled_K.put(0,0, 0);
scaled_K.put(0,1, 127.84747052767318);
scaled_K.put(0,2, 117.5848550330597);
scaled_K.put(1,0, 0);
scaled_K.put(1,1, 0);
scaled_K.put(1,2, 1);
//---new_intrinsic
new_K.put(0, 0, 55.18592909321585);
new_K.put(0, 1, 0);
new_K.put(0, 2, 179.88774876928983);
new_K.put(0,0, 0);
new_K.put(0,1, 55.186015054455254);
new_K.put(0,2, 117.52214917278232);
new_K.put(1,0, 0);
new_K.put(1,1, 0);
new_K.put(1,2, 1);
//--distCoeffs
D.put(0, 0, 0.02957361362801916);
D.put(0, 1, 0.06734495775748955);
D.put(0, 2, -0.1607790665018164);
D.put(0, 3, 0.09278155706511662);
//--R
R.put(0, 0, 1);
R.put(0, 1, 0);
R.put(0, 2, 1);
R.put(1,0, 0);
R.put(1,1, 1);
R.put(1,2, 0);
R.put(2,0, 0);
R.put(2,1, 0);
R.put(2,2, 1);
//image size
Size dim = new Size(340,240);
Mat map1 = new Mat();
Mat map2 = new Mat();
Calib3d.initUndistortRectifyMap(scaled_K,D,R,new_K,dim,CV_32FC1,map1,map2);
Mat frame = Imgcodecs.imread("distort_frame.png");
Mat undistort_frame = new Mat();
Imgproc.remap(frame,undistort_frame,map1,map2,INTER_LINEAR);
Imgcodecs.imwrite("undistort_frame.png",undistort_frame);
我收到错误" Calib3d.initUndistortRectifyMap(scaled_K,D,R,new_K,dim,CV_32FC1,map1,map2); "
OpenCV Error: Assertion failed ((K.depth() == 5 || K.depth() == 6) && (D.depth() == 5 || D.depth() == 6)) in cv::fisheye::initUndistortRectifyMap, file C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\calib3d\src\fisheye.cpp, line 425
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\calib3d\src\fisheye.cpp:425: error: (-215) (K.depth() == 5 || K.depth() == 6) && (D.depth() == 5 || D.depth() == 6) in function cv::fisheye::initUndistortRectifyMap
]