Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python opencv cv2.waitkey error

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?

like image 666
juanca Avatar asked Feb 05 '14 04:02

juanca


People also ask

How do I stop waitKey?

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 waitKey 1?

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.

What does cv2 waitKey 1 & 0xFF do?

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.


3 Answers

AttributeError: 'module' object has no attribute 'waitkey'

Try cv2.waitKey in place of cv2.waitkey. Capitalization counts.

like image 129
John1024 Avatar answered Oct 02 '22 03:10

John1024


cv2.waitKey()

This syntax works. In the open parentheses add time.

like image 40
Rishabh Avatar answered Oct 05 '22 03:10

Rishabh


Try waitKey() instead of waitkey(),It worls fine.

like image 38
Himanshu_Kardam Avatar answered Oct 02 '22 03:10

Himanshu_Kardam