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

- **ID:** `opencv/calib3d-solvepnp-distortion-nan`
- **领域:** opencv
- **类别:** data_error
- **错误码:** `-215`
- **验证级别:** ai_generated
- **修复率:** 87%

## 根因

畸变系数向量包含NaN（非数字）值，导致solvePnP失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 4.6.0 | active | — | — |
| 4.7.0 | active | — | — |
| 4.8.0 | active | — | — |

## 解决方案

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

## 无效尝试

- **Setting all NaN values to 0 without re-calibrating.** — Replacing NaN with 0 may still cause poor results if the original calibration was bad; it's a temporary patch. (60% 失败率)
- **Changing the camera index in VideoCapture.** — Using a different camera index does not fix the distortion data. (80% 失败率)
- **Increasing the termination criteria iterations for solvePnP.** — Increasing the number of iterations does not eliminate NaN in input. (70% 失败率)
