Repository navigation
fix(calib3d): read distCoeffs in standard order in initWideAngleProjMap 🤖🤖🤖 - #30797
Conversation
There was a problem hiding this comment.
Status: 🟡 Yellow
The coefficient unpacking now matches the documented calib3d order and the undistortPoints call used earlier in the same function. The focused nonzero-p1 regression fails under the old indexing and pins the corrected map values. I found no actionable issue; LGTM pending exact-head CI.
|
This bug is on 4.x too (calib3d/src/undistort.dispatch.cpp:693), and bug fixes go to 4.x, which is merged into 5.x regularly. Please retarget to 4.x. |
There was a problem hiding this comment.
With 8+ coefficients the 1 must be in the numerator: kr = (1 + ((k3*r2 + k2)*r2 + k1)r2)/(1 + ((k6r2 + k5)*r2 + k4)*r2), as in initUndistortRectifyMap and undistortPoints. As written, the map is off by about 14 px.
| Mat mapxy(dsize, CV_32FC2); | ||
| double k1 = k[0], k2 = k[1], k3 = k[2], p1 = k[3], p2 = k[4], k4 = k[5], k5 = k[6], k6 = k[7], s1 = k[8], s2 = k[9], s3 = k[10], s4 = k[11]; | ||
| double k1 = k[0], k2 = k[1], p1 = k[2], p2 = k[3], k3 = k[4], k4 = k[5], k5 = k[6], k6 = k[7], s1 = k[8], s2 = k[9], s3 = k[10], s4 = k[11]; | ||
| double fx = cameraMatrix.at<double>(0,0), fy = cameraMatrix.at<double>(1,1), cx = scenter.x, cy = scenter.y; |
There was a problem hiding this comment.
scenter is read before cameraMatrix is filled, so cx/cy are always 0 and the map is shifted by about 400 px for a real camera matrix. Please read them from cameraMatrix after the conversion and drop scenter.
| map1, map2, PROJ_SPHERICAL_EQRECT, 0.0); | ||
|
|
||
| EXPECT_NEAR(map1.at<float>(350, 450), 227.979f, 1e-2); | ||
| EXPECT_NEAR(map2.at<float>(350, 450), 228.751f, 1e-2); |
There was a problem hiding this comment.
This test passes with both bugs above still present, since only p1 is set and cx = cy = 0. Please round-trip the map through undistortPoints with a real principal point and 8 coefficients, next to regression_14467 in test_undistort.cpp.
initWideAngleProjMap unpacked the distortion coefficients as (k1, k2, k3, p1, p2, ...) while the documented order, and the one used by initUndistortRectifyMap, is (k1, k2, p1, p2, k3, ...). With a nonzero p1 the map came out wrong (e.g. dist=[0,0,0.1,0,0] gave u=212.139, v=197.349 instead of u=227.979, v=228.751). Reorder the unpacking to match the standard model. Also fix two further issues in the same function: the radial factor used kr = 1 + (num-1)/(den) instead of the rational model kr = (1 + k1*r2 + k2*r4 + k3*r6)/(1 + k4*r2 + k5*r4 + k6*r6), which is off by about 14 px with 8 coefficients, and the principal point was read from scenter before the camera matrix was converted, so cx/cy were always 0 and the map was shifted by about 400 px for a real camera matrix. Read cx/cy from the converted camera matrix and drop scenter. Add a regression test next to regression_14467: with a real principal point and 8 coefficients it round-trips the map through undistortPoints and checks the result against the spherical projection. Fixes opencv#30744 Signed-off-by: SIDDARTHA REDDY <[email protected]> Signed-off-by: Siddartha Reddy Chinthala <[email protected]>
434ff3b to
be0972f
Compare
|
Addressed all three points in be0972f (retargeted to 4.x): the unpacking now reads (k1, k2, p1, p2, k3, ...), kr uses the rational model (1 + k1r2 + k2r4 + k3r6)/(1 + k4r2 + k5r4 + k6r6), and cx/cy are read from the converted camera matrix with scenter dropped. The new test Calib3d_initWideAngleProjMap.issue_30744 in test_undistort.cpp uses a real principal point and 8 coefficients and round-trips the map through undistortPoints; it fails with each bug present and passes with the fix. Repro on 4.x gives u=227.979, v=228.751 as expected, and the 15 undistort tests pass. |
There was a problem hiding this comment.
Status: 🟡 Yellow
The update resolves the three review findings: it uses the standard distortion-coefficient order, applies the rational radial model, and reads the principal point after converting the camera matrix. The replacement regression now round-trips a map with a real principal point and eight coefficients, so each corrected path is exercised. I found no remaining actionable issue; exact-head CI is still in progress.
Fixes #30744
initWideAngleProjMapunpackeddistCoeffsas(k1, k2, k3, p1, p2, ...)while the documented coefficient order, and the one
initUndistortRectifyMapuses, is
(k1, k2, p1, p2, k3, ...). With a nonzero tangential coefficientthe projection map came out wrong. This reorders the unpacking to the
standard model and adds a regression test.
Retargeted to 4.x per review (the function lives in
modules/calib3dthere).Also fixed two further issues in the same function from the review: the
radial factor now uses the rational model
kr = (1 + k1*r2 + k2*r4 + k3*r6)/(1 + k4*r2 + k5*r4 + k6*r6)(was off byabout 14 px with 8 coefficients), and the principal point is now read from
the converted camera matrix instead of
scenter(which was read beforethe conversion, so cx/cy were always 0 and the map was shifted by about
400 px for a real camera matrix).
Repro from the issue (distCoeffs
[0, 0, 0.1, 0, 0], fx=fy=500,PROJ_SPHERICAL_EQRECT, 640x480, pixel (450, 350)):New test
Calib3d_initWideAngleProjMap.issue_30744inmodules/calib3d/test/test_undistort.cpp(next toregression_14467) usesa real principal point and 8 coefficients and round-trips the map through
undistortPoints; it fails with each of the three bugs present and passeswith the fix. The 15 undistort tests pass.
Note: this PR was prepared with AI assistance; the fix and the test were
verified by building OpenCV from source and running the issue's repro and
the new regression test locally.
under GPL or other license that is incompatible with OpenCV
repository, if applicable
project CMake