From 8ed1945ccd52501f5ab22bdec6aa1f91f1e2cfd4 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Wed, 27 Apr 2016 14:47:52 +0200 Subject: [PATCH] calibrationMatrixValues: consider principalPoint in FOV computation The FOV depends on the principal point location. Use formula of viz::Camera. --- modules/calib3d/src/calibration.cpp | 6 ++++-- modules/calib3d/test/test_cameracalibration.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index bd759d294b..8ae9bb2c12 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -3356,8 +3356,10 @@ void cv::calibrationMatrixValues( InputArray _cameraMatrix, Size imageSize, } /* Calculate fovx and fovy. */ - fovx = 2 * atan(imageSize.width / (2 * K(0, 0))) * 180.0 / CV_PI; - fovy = 2 * atan(imageSize.height / (2 * K(1, 1))) * 180.0 / CV_PI; + fovx = atan2(K(0, 2), K(0, 0)) + atan2(imageSize.width - K(0, 2), K(0, 0)); + fovy = atan2(K(1, 2), K(1, 1)) + atan2(imageSize.height - K(1, 2), K(1, 1)); + fovx *= 180.0 / CV_PI; + fovy *= 180.0 / CV_PI; /* Calculate focal length. */ focalLength = K(0, 0) / mx; diff --git a/modules/calib3d/test/test_cameracalibration.cpp b/modules/calib3d/test/test_cameracalibration.cpp index 49d73fc616..329a825245 100644 --- a/modules/calib3d/test/test_cameracalibration.cpp +++ b/modules/calib3d/test/test_cameracalibration.cpp @@ -875,8 +875,8 @@ void CV_CalibrationMatrixValuesTest::run(int) ny = goodAspectRatio; } - goodFovx = 2 * atan( imageSize.width / (2 * fx)) * 180.0 / CV_PI; - goodFovy = 2 * atan( imageSize.height / (2 * fy)) * 180.0 / CV_PI; + goodFovx = (atan2(cx, fx) + atan2(imageSize.width - cx, fx)) * 180.0 / CV_PI; + goodFovy = (atan2(cy, fy) + atan2(imageSize.height - cy, fy)) * 180.0 / CV_PI; goodFocalLength = fx / nx;