I'm pretty new to Python and raspberry Pi, having mostly a background in shell scripting.
My goal is to have have a Pi set up, with the preview continuously running, waiting for a user to press 'Space Bar' at which point it takes a photo, shows it (overlay) and returns to the preview.
So far I have got the preview up, the image capture (Still working out how to avoid the stutter), and then I am overlaying the result for a bit.
But I'm stuck on how to capture a users keypress, take the photo, and continue on with the preview. Nothing I have seen online gives a very clear example of how to capture user input. I have gotten the sys.stidn code up and running in a separate script, but I can't seem to get the looping to work the way I want it to; Take photo, return back to preview state.
I feel like this should be easier, but somehow I just can't seem to get it. Any help would be great.
import picamera import Image from time import sleep import datetime as dt import itertools import tty, sys with picamera.PiCamera() as camera: camera.framerate = 15 camera.vflip = True camera.hflip = True #camera.brightness = 70 #camera.sharpness = 10 #camera.saturation = 100 camera.resolution = (1296, 972) #print ( Time_String ) #sleep(5) camera.start_preview() camera.annotate_text = 'Cheese Dude!' tty.setraw(sys.stdin.fileno()) while 1: ch = sys.stdin.read(1) if ch == ' ': capture() elif ch == 'q': exitCam() def capture(): Time_String = dt.datetime.now().strftime('%Y_%m_%d_%H_%M_%S') ImageName = './photos/image' + Time_String + '.jpg' camera.capture(ImageName) #camera.start_preview() #will now try and overlay the captured image on the preview for a short period, to show how it looked # Create an image padded to the required size with # mode 'RGB' img = Image.open(ImageName) pad = Image.new('RGB', ( ((img.size + 31) // 32) * 32, ((img.size + 15) // 16) * 16, )) # Paste the original image into the padded one pad.paste(img, (0, 0)) o = camera.add_overlay(pad.tostring(), size=img.size) o.alpha = 255 o.layer = 3 sleep(5) def exitCam(): camera.stop_preview() camera.close()