# cv::error: (-2:Unspecified error) could not find a writer for the specified extension in function 'imwrite_'

- **ID:** `opencv/imgcodecs-imwrite-extension-unsupported`
- **Domain:** opencv
- **Category:** config_error
- **Error Code:** `-2`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The image file extension provided to cv2.imwrite is not supported by the OpenCV build (e.g., .webp, .jp2, .tiff without proper codec support).

## 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. **Convert the image to a supported format before saving: if extension not in ['.png', '.jpg', '.jpeg', '.bmp']: cv2.imwrite('output.png', img); then rename or convert with another tool.** (95% success)
   ```
   Convert the image to a supported format before saving: if extension not in ['.png', '.jpg', '.jpeg', '.bmp']: cv2.imwrite('output.png', img); then rename or convert with another tool.
   ```
2. **Rebuild OpenCV from source with the required image format support: cmake -D WITH_WEBP=ON -D BUILD_JPEG=ON -D BUILD_TIFF=ON ..** (80% success)
   ```
   Rebuild OpenCV from source with the required image format support: cmake -D WITH_WEBP=ON -D BUILD_JPEG=ON -D BUILD_TIFF=ON ..
   ```
3. **Use a different library like PIL to save in unsupported formats: from PIL import Image; Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)).save('output.webp')** (90% success)
   ```
   Use a different library like PIL to save in unsupported formats: from PIL import Image; Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)).save('output.webp')
   ```

## Dead Ends

- **** — The extension determines the codec used; a mismatch between extension and actual format may produce a corrupted file. (70% fail)
- **** — OpenCV must be compiled with support for these libraries; system libraries alone do not enable the codec. (90% fail)
