{
  "id": "opencv/imwrite-format-unsupported",
  "signature": "cv2.error: OpenCV(4.8.0) /modules/imgcodecs/src/loadsave.cpp:734: error: (-2:Unspecified error) could not find a writer for the specified extension in function 'cv::imwrite_'",
  "signature_zh": "cv2.error: OpenCV(4.8.0) /modules/imgcodecs/src/loadsave.cpp:734: error: (-2:未指定的错误) 找不到指定扩展名的写入器 在函数'cv::imwrite_'中",
  "regex": "error: \\(-2:Unspecified error\\) could not find a writer for the specified extension",
  "domain": "opencv",
  "category": "encoding_error",
  "subcategory": null,
  "root_cause": "The file extension in the output path is not recognized or supported by OpenCV's image writing codecs (e.g., .bmp, .jpg, .png are supported, but .webp or .tiff may be missing).",
  "root_cause_type": "generic",
  "root_cause_zh": "输出路径中的文件扩展名不被OpenCV的图像写入编解码器识别或支持（例如，支持.bmp、.jpg、.png，但可能缺少.webp或.tiff）。",
  "versions": [
    {
      "version": "4.5.0",
      "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.8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Installing libwebp-dev via apt but not rebuilding OpenCV with WEBP support.",
      "why_fails": "Installing additional image libraries without rebuilding OpenCV does not add codec support.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Converting the image to float32 before saving.",
      "why_fails": "Changing the image data type does not affect codec availability.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Converting the image to grayscale before saving.",
      "why_fails": "Using a different color space does not enable unsupported formats.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use a supported extension like '.png' or '.jpg': `cv2.imwrite('output.jpg', img)`",
      "success_rate": 0.95,
      "how": "Use a supported extension like '.png' or '.jpg': `cv2.imwrite('output.jpg', img)`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Rebuild OpenCV with the desired format support, e.g., for WEBP: `cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -DBUILD_WEBP=ON ..`",
      "success_rate": 0.8,
      "how": "Rebuild OpenCV with the desired format support, e.g., for WEBP: `cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -DBUILD_WEBP=ON ..`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use an external library like Pillow to convert the image to a supported format before saving with OpenCV.",
      "success_rate": 0.85,
      "how": "Use an external library like Pillow to convert the image to a supported format before saving with OpenCV.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use a supported extension like '.png' or '.jpg': `cv2.imwrite('output.jpg', img)`",
    "Rebuild OpenCV with the desired format support, e.g., for WEBP: `cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -DBUILD_WEBP=ON ..`",
    "Use an external library like Pillow to convert the image to a supported format before saving with OpenCV."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.opencv.org/4.8.0/d4/d5e/group__imgcodecs.html",
  "official_doc_section": null,
  "error_code": "-2",
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.93,
  "resolvable": "true",
  "first_seen": "2023-02-28",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}