Reputation: 34
I have the following code that prints the following image. Why don't I have the option to close the window (small Red Cross missing in top left corner)?
import cv2
img = cv2.imread('/Users/natashabustnes/Desktop/geeks14.png')
cv2.imshow('image', img)
cv2.waitKey(0)
Upvotes: 0
Views: 889
Reputation: 1
import numpy as np
import cv2
# Create an orange image
image_opencv = np.zeros((500, 500, 3), np.uint8)
image_opencv[:] = (0, 100, 255) # BGR format
# Display the image
cv2.imshow('Orange Image', image_opencv)
cv2.waitKey(0) # Wait for a key press
cv2.destroyAllWindows() # Close the window
Instructions:
Upvotes: 0
Reputation: 151
Your code displays window and waits for a keypress.
When you pressed a key, waitKey returned and the GUI froze because there's was no more instructions.
Do something like this instead.
import cv2
img = cv2.imread('/Users/natashabustnes/Desktop/geeks14.png')
cv2.imshow('image', img)
while True:
k = cv2.waitKey(1) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
This code waits until you press the 'q' button before closing. OpenCV by default does not support closing windows using the normal close button.
Upvotes: 1