简体   繁体   中英

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. 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? 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. 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) .

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). This could look like:

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

Where root is what you define as your access to Tk() . lambda e: specifies an inline function expression, where e is the event object passed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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