How to refresh the image content in a window?
cv2.namedWindow("image",0)
img=cv2.imread("autojump.png")
while 1:
img=cv2.imread("autojump.png")
cv2.imshow("image",img)
k=cv2.waitKey(0) & 0XFF
if k== 27 :
break
cv2.destroyAllWindows()
The image file autojump.png
's content will change along with time(rewrited by with open("autojump.png","w" as f : f.write(some_other_image_bytes_stream)
), so I reload it during the while
loop, but it seems that the window never refresh.Just always the same image. What's wrong?
press a key or change
cv2.waitKey(0) -> cv2.waitKey(10)
you should destory img first,then read a new "autojump.png"