{
  "id": "opencv/highgui-window-could-not-be-created",
  "signature": "cv::error: (-2:Unspecified error) Could not create window in function 'cv::namedWindow'",
  "signature_zh": "cv::error: (-2:未指定错误) 无法创建窗口 在函数 'cv::namedWindow' 中",
  "regex": "cv::error: \\(-2:Unspecified error\\) Could not create window in function 'cv::namedWindow'",
  "domain": "opencv",
  "category": "system_error",
  "subcategory": null,
  "root_cause": "The display server (X11, Wayland, or macOS Quartz) is not available, or the window manager is not running.",
  "root_cause_type": "generic",
  "root_cause_zh": "显示服务器（X11、Wayland 或 macOS Quartz）不可用，或窗口管理器未运行。",
  "versions": [
    {
      "version": "4.5.5",
      "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": "Qt backend also requires a display server; if no display is available, it will still fail.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If no X server is running, setting DISPLAY won't create one; the variable only works if X is already active.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Root privileges do not enable a display server; the error is about display availability, not permissions.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "import os\nos.environ['OPENCV_IO_ENABLE_OPENCL'] = '0'\n# Or simply avoid namedWindow calls; save images to disk instead:\ncv2.imwrite('output.jpg', img)\n# For debugging, print image shape instead of displaying.",
      "success_rate": 0.95,
      "how": "import os\nos.environ['OPENCV_IO_ENABLE_OPENCL'] = '0'\n# Or simply avoid namedWindow calls; save images to disk instead:\ncv2.imwrite('output.jpg', img)\n# For debugging, print image shape instead of displaying.",
      "condition": "",
      "sources": []
    },
    {
      "action": "sudo apt-get install xvfb\nXvfb :99 -screen 0 1024x768x24 &\nexport DISPLAY=:99\n# Then run your OpenCV script",
      "success_rate": 0.9,
      "how": "sudo apt-get install xvfb\nXvfb :99 -screen 0 1024x768x24 &\nexport DISPLAY=:99\n# Then run your OpenCV script",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "import os\nos.environ['OPENCV_IO_ENABLE_OPENCL'] = '0'\n# Or simply avoid namedWindow calls; save images to disk instead:\ncv2.imwrite('output.jpg', img)\n# For debugging, print image shape instead of displaying.",
    "sudo apt-get install xvfb\nXvfb :99 -screen 0 1024x768x24 &\nexport DISPLAY=:99\n# Then run your OpenCV script"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.opencv.org/4.x/d7/dfc/group__highgui.html#ga5afdf8410934fd099df085bd3b1c0d6a",
  "official_doc_section": null,
  "error_code": "-2",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "partial",
  "first_seen": "2024-09-18",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}