From 2bfcbe14594c0798045113ba940a97547ee2685c Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Tue, 6 Dec 2016 14:16:37 +0100 Subject: [PATCH] fisheye::undistortPoints: sanitize theta values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the current camera model is only valid up to 180° FOV for larger FOV the undistort loop does not converge. Clip values so we still get plausible results for super fisheye images > 180°. --- modules/calib3d/src/fisheye.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/calib3d/src/fisheye.cpp b/modules/calib3d/src/fisheye.cpp index 32dc15c3f2..df68cf1905 100644 --- a/modules/calib3d/src/fisheye.cpp +++ b/modules/calib3d/src/fisheye.cpp @@ -377,6 +377,12 @@ void cv::fisheye::undistortPoints( InputArray distorted, OutputArray undistorted double scale = 1.0; double theta_d = sqrt(pw[0]*pw[0] + pw[1]*pw[1]); + + // the current camera model is only valid up to 180° FOV + // for larger FOV the loop below does not converge + // clip values so we still get plausible results for super fisheye images > 180° + theta_d = min(max(-CV_PI/2., theta_d), CV_PI/2.); + if (theta_d > 1e-8) { // compensate distortion iteratively