Skip to content

Instantly share code, notes, and snippets.

@dnnsmnstrr
Created March 13, 2021 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnnsmnstrr/6197a9e2b78106b0500de5eefe3c294a to your computer and use it in GitHub Desktop.
Save dnnsmnstrr/6197a9e2b78106b0500de5eefe3c294a to your computer and use it in GitHub Desktop.
Takes a picture using the raspberry pi camera and saves the resulting image with datetime filename
from picamera import PiCamera
import time
import os
camera = PiCamera()
camera.start_preview()
time.sleep(3)
currentTime = time.strftime("%Y-%m-%d-%T")
#print(currentTime)
if not os.path.exists('/home/pi/Desktop/camera/'):
os.makedirs('/home/pi/Desktop/camera/')
path = '/home/pi/Desktop/camera/' + currentTime + '.jpg'
camera.capture(path)
camera.stop_preview()
os.system('xdg-open ' + path)
print(path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment