The following code is not rendering:
import cv2
import numpy as np
from time import sleep
hz = 30
bitmap = np.zeros((512,512,3),np.uint8)
for i in range(512):
sleep(1/hz)
bitmap[i,i,:] = 128
cv2.imshow("Color Image", bitmap)
cv2.waitKey(0)
cv2.destroyAllWindows()
What am I missing?
waitKey, it needs to run each iteration, or you won't see anything (as explained in the documentation). The parameter ofwaitKeyalso needs to be non-zero. | Also, thesleepexpects the rest of the loop body to happen in 0 time, which won't be the case, so your loop will run slower than you want.cv2.imshowdoesn't block. But it needs a call towaitKeyto run the message loop, so that the window gets rendered.