# cv::error: (-215:Assertion failed) map1.size().area() > 0 in function 'cv::undistort'

- **ID:** `opencv/undistort-empty-map`
- **Domain:** opencv
- **Category:** assertion_error
- **Error Code:** `-215`
- **Verification:** ai_generated
- **Fix Rate:** 89%

## Root Cause

undistort received an empty or uninitialized map (map1) because initUndistortRectifyMap was not called or produced an empty output due to invalid camera matrix parameters.

## Version Compatibility

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

## Workarounds

1. **Always call initUndistortRectifyMap before undistort. Example: 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). Check mapx.size > 0.** (95% success)
   ```
   Always call initUndistortRectifyMap before undistort. Example: 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). Check mapx.size > 0.
   ```
2. **If using cv2.undistort directly, ensure the camera matrix and distortion coefficients are not None and have correct shape: mtx must be 3x3 float64, dist must be 1xN or Nx1.** (90% success)
   ```
   If using cv2.undistort directly, ensure the camera matrix and distortion coefficients are not None and have correct shape: mtx must be 3x3 float64, dist must be 1xN or Nx1.
   ```
3. **Verify camera matrix validity: if np.any(np.isnan(mtx)) or np.any(np.isinf(mtx)): raise ValueError('Invalid camera matrix'). Recalibrate if needed.** (85% success)
   ```
   Verify camera matrix validity: if np.any(np.isnan(mtx)) or np.any(np.isinf(mtx)): raise ValueError('Invalid camera matrix'). Recalibrate if needed.
   ```

## Dead Ends

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