Reputation: 1581
My opencv_version
is: 4.1.0-pre
I have follow code:
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
function works properly, how ever first call to remap
yields exception:
OpenCV(4.1.0-pre) Error: Assertion failed (!ssize.empty()) in remapBilinear, file /home/olga/opencv/modules/imgproc/src/imgwarp.cpp, line 666
Here is calibration_matrix
and distortion_coefficients
from 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. ]
Upvotes: 0
Views: 1609
Reputation: 8284
You were trying to apply the image remapping to an empty image.
The parameters are
remap(src, dst, mapx, mapy);
Your input view
was an empty mat.
The most relevant image would probably be your input image, so
remap(temp , rview, map1, map2, INTER_LINEAR);
Upvotes: 1