I\'m using opencv 2.4.7 on ubuntu 12.04. I\'m programming with python and I have a problem when i run this script:
import cv2
img = cv2.imread(\'34762092361
This will work even if you close the window using the cross button on the window.
import numpy as np
import cv2
img = cv2.imread('arvid.jpg', 0)
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.imshow('image', img)
while True:
k = cv2.waitKey(30) & 0xFF
if k == 27: # wait for ESC key to exit
cv2.destroyAllWindows()
elif k == ord('s'): # wait for 's' key to save and exit
cv2.imwrite('arvid2.jpg', img)
cv2.destroyAllWindows()
if cv2.getWindowProperty("image", 0) == -1:
break
cv2.waitKey(0) means that script is in infinity loop with 0 miliseconds wait after loop .only specified key can stop it.
you did not specified end of app condition.
Try this code: Using other keys for the waitKey() function of opencv
This problem occurs in some earlier version of opencv.
So you just need to update opencv to the latest version. Version 4.0.0.21
worked for me.
Use the command below.
update opencv to version 4.0.0.21.
Well the use cv2.waitKeyEx(0).
It runs in the same way and waits for your response until you revoke it.
I hope it helps. Nithesh varmma
Adding a cv2.waitKey(1) after you destroy the window should work in this case.
cv2.imshow('imgae',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.waitKey(1)
This code works for me from IDLE:
# -*- coding: utf-8 -*-
# Objectif : découvrir le fonctionnement d'opencv-python
# http://opencv-python-tutroals.readthedocs.org/en/latest/index.html
import numpy as np
import cv2
# Load an color image in grayscale
img = cv2.imread('Lena.tiff',0)
WINDOW_NAME = 'Image de Lena'
cv2.namedWindow(WINDOW_NAME, cv2.CV_WINDOW_AUTOSIZE)
cv2.startWindowThread()
# Display an image
cv2.imshow(WINDOW_NAME,img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Hope this helps for future readers.