Skip to content

Instantly share code, notes, and snippets.

@LoLei
Created August 8, 2020 13:27
Show Gist options
  • Save LoLei/b099ee8c449066eb4dcedaa605cf2190 to your computer and use it in GitHub Desktop.
Save LoLei/b099ee8c449066eb4dcedaa605cf2190 to your computer and use it in GitHub Desktop.
Fix opencv imshow in i3wm
"""
Fix opencv imshow in i3wm
- Use namedWindow with WINDOW_NORMAL
- Only close when Esc (==27) is pressed
(For some reason it triggers on Alt/i3 mod as well otherwise)
- 50% chance the window is opened in tiled mode or floating mode
Just change mode to liking after the fact with keybind
"""
import cv2
def i3imshow(wname, img):
cv2.namedWindow("preview", cv2.WINDOW_NORMAL)
while True:
cv2.imshow(wname, img)
k = cv2.waitKey(33)
# Esc key to stop
if k == 27:
cv2.destroyAllWindows()
return
# Test
img = cv2.imread("image.png")
i3imshow("preview", img)
@nfedyashev
Copy link

Thank you!

@LoLei
Copy link
Author

LoLei commented Jan 11, 2024

Wow, glad this 4 year old script could help someone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment