-215 opencv data_error ai_generated true

cv::error: OpenCV(4.6.0) /modules/calib3d/src/solvepnp.cpp:123: error: (-215:Assertion failed) !cvIsNaN(distCoeffs.at<double>(i)) in function 'solvePnP'

ID: opencv/calib3d-solvepnp-distortion-nan

Also available as: JSON · Markdown · 中文
87%Fix Rate
83%Confidence
1Evidence
2023-05-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.6.0 active
4.7.0 active
4.8.0 active

Root Cause

The distortion coefficients vector contains NaN (Not a Number) values, causing solvePnP to fail.

generic

中文

畸变系数向量包含NaN(非数字)值,导致solvePnP失败。

Official Documentation

https://docs.opencv.org/4.6.0/d9/d0c/group__calib3d.html

Workarounds

  1. 85% success Check and clean distortion coefficients: `distCoeffs = np.nan_to_num(distCoeffs, nan=0.0)` before calling solvePnP.
    Check and clean distortion coefficients: `distCoeffs = np.nan_to_num(distCoeffs, nan=0.0)` before calling solvePnP.
  2. 90% success Re-run camera calibration with valid checkerboard images to generate proper distortion coefficients.
    Re-run camera calibration with valid checkerboard images to generate proper distortion coefficients.
  3. 80% success If distortion coefficients are not needed, pass an empty array: `cv2.solvePnP(objPoints, imgPoints, cameraMatrix, None)`
    If distortion coefficients are not needed, pass an empty array: `cv2.solvePnP(objPoints, imgPoints, cameraMatrix, None)`

中文步骤

  1. Check and clean distortion coefficients: `distCoeffs = np.nan_to_num(distCoeffs, nan=0.0)` before calling solvePnP.
  2. Re-run camera calibration with valid checkerboard images to generate proper distortion coefficients.
  3. If distortion coefficients are not needed, pass an empty array: `cv2.solvePnP(objPoints, imgPoints, cameraMatrix, None)`

Dead Ends

Common approaches that don't work:

  1. Setting all NaN values to 0 without re-calibrating. 60% fail

    Replacing NaN with 0 may still cause poor results if the original calibration was bad; it's a temporary patch.

  2. Changing the camera index in VideoCapture. 80% fail

    Using a different camera index does not fix the distortion data.

  3. Increasing the termination criteria iterations for solvePnP. 70% fail

    Increasing the number of iterations does not eliminate NaN in input.