Merge pull request #19690 from hedgepigdaniel:fix/calibration_fisheye
authorDaniel Playfair Cal <daniel.playfair.cal@gmail.com>
Tue, 9 Mar 2021 15:09:08 +0000 (02:09 +1100)
committerGitHub <noreply@github.com>
Tue, 9 Mar 2021 15:09:08 +0000 (15:09 +0000)
* fix(samples/camera_calibration): set new camera matrix for fisheye

* fix(camera_calibration): ignore inapplicable flags for fisheye

samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp

index a6f87f41e8ef766d6b7212ea8921b0b3ee24d1c1..38961ec63e58504f4bbc0c95ede8db769c3283d0 100644 (file)
@@ -391,7 +391,12 @@ int main(int argc, char* argv[])
         {
             Mat temp = view.clone();
             if (s.useFisheye)
-              cv::fisheye::undistortImage(temp, view, cameraMatrix, distCoeffs);
+            {
+                Mat newCamMat;
+                fisheye::estimateNewCameraMatrixForUndistortRectify(cameraMatrix, distCoeffs, imageSize,
+                                                                    Matx33d::eye(), newCamMat, 1);
+                cv::fisheye::undistortImage(temp, view, cameraMatrix, distCoeffs, newCamMat);
+            }
             else
               undistort(temp, view, cameraMatrix, distCoeffs);
         }
@@ -519,7 +524,7 @@ static bool runCalibration( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat
 {
     //! [fixed_aspect]
     cameraMatrix = Mat::eye(3, 3, CV_64F);
-    if( s.flag & CALIB_FIX_ASPECT_RATIO )
+    if( !s.useFisheye && s.flag & CALIB_FIX_ASPECT_RATIO )
         cameraMatrix.at<double>(0,0) = s.aspectRatio;
     //! [fixed_aspect]
     if (s.useFisheye) {
@@ -586,7 +591,7 @@ static void saveCameraParams( Settings& s, Size& imageSize, Mat& cameraMatrix, M
     fs << "board_height" << s.boardSize.height;
     fs << "square_size" << s.squareSize;
 
-    if( s.flag & CALIB_FIX_ASPECT_RATIO )
+    if( !s.useFisheye && s.flag & CALIB_FIX_ASPECT_RATIO )
         fs << "fix_aspect_ratio" << s.aspectRatio;
 
     if (s.flag)