# cv::error: (-215:Assertion failed) !winname.empty() && namedWindow(winname, flags) == 0 in function 'imshow'

- **ID:** `opencv/highgui-window-name-duplicate`
- **Domain:** opencv
- **Category:** assertion_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

imshow() is called with an empty window name or a window name that conflicts with an existing named window due to duplicate creation without proper flags.

## Version Compatibility

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

## Workarounds

1. **Always provide a non-empty, unique window name: cv::imshow("Display Window", img); or use cv::namedWindow("MyWindow", cv::WINDOW_AUTOSIZE); cv::imshow("MyWindow", img);** (95% success)
   ```
   Always provide a non-empty, unique window name: cv::imshow("Display Window", img); or use cv::namedWindow("MyWindow", cv::WINDOW_AUTOSIZE); cv::imshow("MyWindow", img);
   ```
2. **Check if window exists before creating: if (cv::getWindowProperty("MyWindow", cv::WND_PROP_VISIBLE) < 0) { cv::namedWindow("MyWindow", cv::WINDOW_AUTOSIZE); }** (85% success)
   ```
   Check if window exists before creating: if (cv::getWindowProperty("MyWindow", cv::WND_PROP_VISIBLE) < 0) { cv::namedWindow("MyWindow", cv::WINDOW_AUTOSIZE); }
   ```

## Dead Ends

- **Calling namedWindow with a different flag like WINDOW_NORMAL every time** — If the window name already exists, namedWindow returns non-zero but doesn't fail; imshow still sees the conflict. (70% fail)
- **Using imshow without namedWindow at all** — imshow internally calls namedWindow, so the same assertion can trigger if the name is empty. (80% fail)
- **Destroying window with destroyWindow before each imshow** — If the window name is empty, destroyWindow does nothing and imshow still fails. (85% fail)
