-215 opencv data_error ai_generated true

cv::error: OpenCV(4.6.0) /modules/calib3d/src/solvepnp.cpp:123: error: (-215:断言失败) !cvIsNaN(distCoeffs.at<double>(i)) 在函数'solvePnP'中

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

其他格式: JSON · Markdown 中文 · English
87%修复率
83%置信度
1证据数
2023-05-12首次发现

版本兼容性

版本状态引入弃用备注
4.6.0 active
4.7.0 active
4.8.0 active

根因分析

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

English

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

generic

官方文档

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

解决方案

  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)`

无效尝试

常见但无效的做法:

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

    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% 失败

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

  3. Increasing the termination criteria iterations for solvePnP. 70% 失败

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