寻求一种在RPi上显示图像并继续python执行的简单方法 [英] Seeking a simple way to display an image on an RPi and continue python execution

查看:60
本文介绍了寻求一种在RPi上显示图像并继续python执行的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将应用程序传输到 RPi,我需要一种方法来使用 python (3) 显示全屏图像,同时代码继续执行.我想避免深入研究像 Tkinter 和 Pygame 这样复杂的 GUI 模块.我只希望图像填满屏幕并保持在那里,直到代码替换它们或告诉它们消失.如果 Tkinter 或 Pygame 可以做到这一点,那就没问题了,但在我看来,它们都进入了最终需要键盘输入的循环.我的应用程序涉及监控传感器和外部输入,但不会连接键盘.我尝试了以下方法:

I'm transferring an application to an RPi, and I need a way to display full screen images using python (3) while code continues to execute. I would like to avoid delving into complicated GUI modules like Tkinter and Pygame. I just want images to fill the screen and stay there until the code replaces them or tells them to go away. If Tkinter or Pygame can do this, that would be fine, but it looks to me like they both enter loops that eventually require keyboard input. My application involves montiring sensors and external inputs, but there will be no keyboard attached. I've tried the following:

feh 用 subprocess.call 激活(这会显示图像,但代码停止执行,直到通过按键清除图像.

feh activated with subprocess.call (This displays the image, but the code stops executing until the image is cleared by a keystroke.

wand.display(这有效,但只显示一个小窗口,而不是全屏)

wand.display (this works but only shows a smallish window, not full screen)

fbi(无法让它显示图像)

fbi (couldn't get it to display an image)

xcd-open(工作但在小窗口中的图像查看器"应用程序中打开 - 没有鼠标点击的全屏选项)

xcd-open (works but opens in "Image Viewer" app in small window - no option for full screen without a mouse click)

我还没有尝试过 OpenCV.看起来这可能行得通,但要为这个简单的应用程序引入大量基础设施.

I have not tried OpenCV. Seems like that might work, but that's a lot of infrastructure to bring in for this simple application.

根据记录,我去过谷歌并为此投入了很多时间.此请求是最后的手段.

For the record I've been to google and have put many hours into this. This request is a last resort.

如果你想要一些伪代码:

If you want some pseudocode:

displayImage("/image_folder/image1.jpg" fullscreen = True)
time.sleep(1)
clearImage()
displayImage("/image_folder/image2.jpg" fullscreen = True)

推荐答案

您没有展示如何尝试使用 feh 和子流程,但也许可以尝试启动它在后台,所以它不会阻塞你的主线程:

You don't show how you tried with feh and a subprocess, but maybe try starting it in the background so it doesn't block your main thread:

subprocess.call("feh -F yourImage.jpg &", shell=True)

注意后台进程,即那些以 & 开头的进程,正在使用 shell 的一个特性,所以我设置了 shell=True.

Note that background processes, i.e. those started with &, are using a feature of the shell, so I have set shell=True.

然后,在显示下一个图像之前,杀死前一个实例:

Then, before you display the next image, kill the previous instance:

subprocess.call("pkill feh")

<小时>

或者,如果您事先知道您计划显示的所有图像的名称,您可以在幻灯片模式"中启动feh(通过传入所有启动时的图像名称),然后在每次要推进图像时传递信号 SIGUSR1:


Alternatively, if you know the names of all the images you plan to display in advance, you could start feh in "Slideshow mode" (by passing in all the image names on startup), and then deliver signal SIGUSR1 each time you want to advance the image:

os.kill(os.getpid(...), signal.SIGUSR1)

<小时>

如果上述方法不起作用,请单击原始问题下的 edit 并添加以下命令的输出,以便我们可以沿着帧缓冲区路由:


If the above doesn't work, please click edit under your original question and add in the output from the following commands so we can go down the framebuffer route:

fbset -fb /dev/fb0

tvservice -d edid
edidparser edid

这篇关于寻求一种在RPi上显示图像并继续python执行的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆