简体   繁体   English

自动刷新Ubuntu树莓派中的图像

[英]Automatically refresh an image in ubuntu raspberry pi

I am streaming and writing an image to a particular location in a raspberry pi. 我正在流式传输图像并将其写入树莓派中的特定位置。 Every time a new image comes it overwrites the previous one. 每次出现新图像时,它都会覆盖前一个图像。 Now if i keep that image file open, it does not get automatically updated.I have to close and reopen it for the update to happen.Is there anyway i can automatically refresh it. 现在如果我保持打开该图像文件,它不会自动更新。我必须关闭并重新打开它才能进行更新。无论如何,我可以在那里自动刷新它。

I tried implementing a python code to continuously read and show the image. 我尝试实现一个python代码来连续读取和显示图像。 But still i have to refresh the window for the image to get updated. 但是我仍然必须刷新窗口以更新图像。 Below is the code that i used. 下面是我使用的代码。

img = cv2.imread("Filename",1)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Please suggest any alternatives. 请提出其他选择。 I just need to preview the stream. 我只需要预览流。

You could use a simple loop as you can call imshow repeatedly without destroying it. 您可以使用一个简单的循环,因为您可以重复调用imshow而不会破坏它。

while True: #Find something to get out of here
    img = cv2.imread("Filename",1)
    cv2.imshow('image', img)
    cv2.waitKey(1)
cv2.destroyAllWindows()

due to opencv documenation: 由于opencv文档:

For example, waitKey(0) will display the window infinitely until any keypress (it is suitable for image display). 例如,waitKey(0)将无限期显示窗口,直到任何按键为止(适用于图像显示)。 waitKey(25) will display a frame for 25 ms, after which display will be automatically closed. waitKey(25)将显示25毫秒的帧,此后将自动关闭显示。

So you have to set time in milliseconds instead of 0. 因此,您必须将时间设置为毫秒而不是0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM