# 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`
- **Domain:** opencv
- **Category:** data_error
- **Error Code:** `-215`
- **Verification:** ai_generated
- **Fix Rate:** 87%

## Root Cause

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

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 4.6.0 | active | — | — |
| 4.7.0 | active | — | — |
| 4.8.0 | active | — | — |

## Workarounds

1. **Check and clean distortion coefficients: `distCoeffs = np.nan_to_num(distCoeffs, nan=0.0)` before calling solvePnP.** (85% success)
   ```
   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.** (90% success)
   ```
   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)`** (80% success)
   ```
   If distortion coefficients are not needed, pass an empty array: `cv2.solvePnP(objPoints, imgPoints, cameraMatrix, None)`
   ```

## Dead Ends

- **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% fail)
- **Changing the camera index in VideoCapture.** — Using a different camera index does not fix the distortion data. (80% fail)
- **Increasing the termination criteria iterations for solvePnP.** — Increasing the number of iterations does not eliminate NaN in input. (70% fail)
