imshow() function displays empty gray image. What do I do?
<p>When I try to use <code>cv2.imshow()</code> it gives a shows the image for a second, then makes the window go gray. I can't seem to find anything about it, except that I should use <code>cv2.waitKey(0)</code>, which I am, and also to use <code>cv2.namedWindow()</code>. My code:</p>

<pre><code>import numpy as np
import cv2
import sys

cv2.namedWindow('img')
img = cv2.imread(sys.argv[1])
cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows
</code></pre>

<p>Again, it shows the image for a second and then grays it out. Thanks in advance.</p>

<ol>
<li>check your sys.argv[1], try to replace with real path (i.e. "images/1.png")</li>
<li>destroyAllWindows() it is the function (use brackets)</li>
<li>parameter of waitKey (0 in your example) it is delay in ms, 0 means "forever", default value of delay is 0.</li>
<li>in fact you don't need namedWindow and destroyAllWindows here</li>
</ol>

<p>try this:</p>

<pre><code>import cv2
import sys

img = cv2.imread(sys.argv[1])
cv2.imshow('img', img)
cv2.waitKey()
</code></pre>

python opencv