简体   繁体   English

Raspberry Pi-运行预览时如何做其他事情?

[英]Raspberry Pi - How to do other things while preview is running?

I am currently writing a script that creates a GUI (writing it with Tkinter) that does a bunch of things. 我目前正在编写一个脚本,该脚本创建一个GUI(用Tkinter编写)来完成很多工作。 Among them is the ability to start previewing with the camera, and then being able to move this motor forwards and backwards at will. 其中之一是可以使用相机开始预览,然后可以随意向前和向后移动此马达的功能。 Unfortunately, the preview blocks me from doing anything else with the GUI as it is running, is there any way around it? 不幸的是,预览阻止我在运行GUI时对其进行任何其他操作,是否可以解决? In my ideal world, you can press the GUI buttons to move the motor forward and backward with the preview running in the background and providing you with active feedback. 在我理想的世界中,您可以按GUI按钮在后台运行预览的情况下向前和向后移动电机,并为您提供有效的反馈。 Here is some of my code: 这是我的一些代码:

def motorOut():
    backwards(int(delayf) / 1000.0, int(stepsf))
    setStep(0,0,0,0)

def motorIn():
    forward(int(delayb) / 1000.0, int(stepsb))
    setStep(0,0,0,0)

def cameraPreview():

    camera.start_preview(fullscreen=False, window = (400, 240, 400, 240))
    sleep(20)
    camera.stop_preview()

Thanks for any help! 谢谢你的帮助!

It is likely not the preview that is blocking your program, but using sleep(20) . 可能不是预览阻止了您的程序,而是使用了sleep(20)

Whilst the 'sleep' is occurring, nothing else can process. 当“睡眠”发生时,其他任何事情都无法处理。 This causes the block you are noticing. 这会导致您注意到该阻止。 You could fix this by removing that line, and instead binding the camera.stop_preview() to an event (such as a key press). 您可以通过删除该行,然后将camera.stop_preview()绑定到事件(例如按键)来解决此问题。 This could look like: 可能看起来像:

root.bind("<space>", lambda e: camera.stop_preview())

Where root is what you define as your access to Tk() . root是您定义为对Tk()访问权限。 lambda e: specifies an inline function expression, where e is the event object passed. lambda e:指定一个内联函数表达式,其中e是传递的事件对象。

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

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