# cv::error: (-215：断言失败) map1.size().area() > 0 在函数 'cv::undistort' 中

- **ID:** `opencv/undistort-empty-map`
- **领域:** opencv
- **类别:** assertion_error
- **错误码:** `-215`
- **验证级别:** ai_generated
- **修复率:** 89%

## 根因

undistort 接收到空或未初始化的 map（map1），因为 initUndistortRectifyMap 未被调用，或由于相机矩阵参数无效而产生了空输出。

## 版本兼容性

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

## 解决方案

1. ```
   在 undistort 之前始终调用 initUndistortRectifyMap。示例：newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h)); mapx, mapy = cv2.initUndistortRectifyMap(mtx, dist, None, newcameramtx, (w,h), 5); dst = cv2.remap(img, mapx, mapy, cv2.INTER_LINEAR)。检查 mapx.size > 0。
   ```
2. ```
   如果直接使用 cv2.undistort，确保相机矩阵和畸变系数不为 None 且形状正确：mtx 必须是 3x3 float64，dist 必须是 1xN 或 Nx1。
   ```
3. ```
   验证相机矩阵有效性：if np.any(np.isnan(mtx)) or np.any(np.isinf(mtx)): raise ValueError('Invalid camera matrix')。必要时重新标定。
   ```

## 无效尝试

- **** — Re-running calibrateCamera with different flags without verifying that the camera matrix is finite and non-zero (35% 失败率)
- **** — Assuming the error is from the image size and resizing the image without recalculating the map (25% 失败率)
- **** — Using a pre-computed map from a different camera or resolution without checking its dimensions (30% 失败率)
