Take multiple pictures on demand using Raspberry Pi python code

The python code below takes as many pictures you want as long as you keep pressing enter and saves images in a specified folder (in this case "images") with image names "image1.jpg" , "image2.jpg", etc.,

from picamera import PiCamera
from time import sleep

camera = PiCamera()
camera.rotation = 270
i = 0
while not raw_input("Press enter for a photo"):
   i = i + 1
   camera.start_preview(alpha=200)
   sleep(1)
   image_path = "./images/image"+str(i)+".jpg"
   camera.capture(image_path)
   camera.stop_preview()
   print("image successfully saved in the path: "+image_path)


Important things to remember


  1. You could also use input() instead of raw_input() function based on the python version.
  2. make sure the folder exists already. This code might not create a new folder.
  3. Do while in python doesn't exist.

Comments

Popular posts from this blog

Raspberry - Record a video for x minutes / x hours using command line option

Raspberry camera [raspistill] image options