Created
August 8, 2020 13:27
-
-
Save LoLei/b099ee8c449066eb4dcedaa605cf2190 to your computer and use it in GitHub Desktop.
Fix opencv imshow in i3wm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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) |
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
Thank you!