{
  "id": "opencv/imgcodecs-imwrite-extension-unsupported",
  "signature": "cv::error: (-2:Unspecified error) could not find a writer for the specified extension in function 'imwrite_'",
  "signature_zh": "cv::error: (-2:未指定错误) 在函数 'imwrite_' 中找不到指定扩展名的写入器",
  "regex": "could not find a writer for the specified extension",
  "domain": "opencv",
  "category": "config_error",
  "subcategory": null,
  "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).",
  "root_cause_type": "generic",
  "root_cause_zh": "提供给 cv2.imwrite 的图像文件扩展名不受当前 OpenCV 构建支持（例如 .webp、.jp2、.tiff 缺少相应的编解码器支持）。",
  "versions": [
    {
      "version": "4.5.5",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The extension determines the codec used; a mismatch between extension and actual format may produce a corrupted file.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "OpenCV must be compiled with support for these libraries; system libraries alone do not enable the codec.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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.",
      "success_rate": 0.95,
      "how": "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.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Rebuild OpenCV from source with the required image format support: cmake -D WITH_WEBP=ON -D BUILD_JPEG=ON -D BUILD_TIFF=ON ..",
      "success_rate": 0.8,
      "how": "Rebuild OpenCV from source with the required image format support: cmake -D WITH_WEBP=ON -D BUILD_JPEG=ON -D BUILD_TIFF=ON ..",
      "condition": "",
      "sources": []
    },
    {
      "action": "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')",
      "success_rate": 0.9,
      "how": "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')",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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.",
    "Rebuild OpenCV from source with the required image format support: cmake -D WITH_WEBP=ON -D BUILD_JPEG=ON -D BUILD_TIFF=ON ..",
    "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')"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.opencv.org/4.x/d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce",
  "official_doc_section": null,
  "error_code": "-2",
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.85,
  "resolvable": "partial",
  "first_seen": "2023-06-18",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}