i'm trying to test the following code of the getting started page:
import numpy as np
import cv2
img = cv2.imread('test.jpg', 0)
cv2.imshow('image', img)
cv2.waitkey(0)&0xFF
cv2.destroyAllWindows()
But i got this error:
init done
opengl support available
Traceback (most recent call last):
File "showimg.py", line 5, in <module>
cv2.waitkey(0)&0xFF
AttributeError: 'module' object has no attribute 'waitkey'
Violación de segmento
I executed the examples that comes with the opencv installation, and they run correctly. Also, the last example that use the Matplotlib works fine.
¿Any idea of the error?, ¿any suggestion?
waitKey(0) until the 0 key is pressed properly whilst the window is in focus. Pressing the 0 key whilst the window is in focus is the right way to close the window and make sure that, once the window is destroyed in line cv2. destroyAllWindows() and the program ends, the user can get back the control of the terminal.
How do I stop my CV2 wait key? So, when you will press “ESC” in your computer it will go to the 4th line and the window will get closed. if you have k as 97 you can exit using 'a' key on your keyboard.
Answer #1: 0xFF is a hexadecimal constant which is 11111111 in binary. By using bitwise AND ( & ) with this constant, it leaves only the last 8 bits of the original (in this case, whatever cv2. waitKey(0) is). Answered By: Kevin W.
AttributeError: 'module' object has no attribute 'waitkey'
Try cv2.waitKey
in place of cv2.waitkey
. Capitalization counts.
cv2.waitKey()
This syntax works. In the open parentheses add time.
Try waitKey() instead of waitkey(),It worls fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With