0

opencv_version的是:4.1.0-pre

我有以下代码:

FileStorage fs("camera.yml", FileStorage::READ);
Mat cameraMatrix;
Mat distCoeffs;
fs["camera_matrix"] >> cameraMatrix;
fs["distortion_coefficients"] >> distCoeffs;
fs.release();

Mat image;
string fileName = "view000.bmp";
image = imread(fileName, IMREAD_COLOR);   // Read the file

Mat temp = image.clone();
undistort(temp, image, cameraMatrix, distCoeffs);

Size imageSize = image.size();
Mat view, rview, map1, map2;
initUndistortRectifyMap(cameraMatrix, distCoeffs, Mat(),
                    getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, 1, imageSize, 0),
                    imageSize, CV_16SC2, map1, map2);

remap(view, rview, map1, map2, INTER_LINEAR);

undistort函数正常工作,如何第一次调用remap产生异常:

OpenCV(4.1.0-pre) 错误:remapBilinear 中的断言失败 (!ssize.empty()),文件 /home/olga/opencv/modules/imgproc/src/imgwarp.cpp,第 666 行

这是calibration_matrixdistortion_coefficients来自camera.yml

camera_matrix: !!opencv-matrix
   rows: 3
   cols: 3
   dt: d
   data: [ 6.6979083645491733e+02, 0., 3.5720142378760517e+02, 0.,
       6.6818397497437070e+02, 2.2958328379477018e+02, 0., 0., 1. ]
distortion_coefficients: !!opencv-matrix
   rows: 5
   cols: 1
   dt: d
   data: [ -9.1630887760709781e-02, 6.3870694676062587e-02,
       -2.9224237615839681e-04, 8.0315318960669040e-04, 0. ]
4

1 回答 1

1

您试图将图像重新映射应用到空图像。

参数是

remap(src, dst, mapx, mapy);

你的输入view是一个空垫子。

最相关的图像可能是您的输入图像,所以

remap(temp , rview, map1, map2, INTER_LINEAR);
于 2019-03-27T12:30:52.177 回答