Bird
0
0
Raspberry Piprogramming~5 mins

Time-lapse photography in Raspberry Pi

Choose your learning style9 modes available
Introduction

Time-lapse photography lets you capture slow changes by taking pictures at set intervals. When played fast, it shows a long event quickly.

Watching a flower bloom over hours or days.
Recording clouds moving across the sky.
Showing a busy street or crowd over time.
Capturing the sunset or sunrise slowly changing.
Syntax
Raspberry Pi
import time
from picamera import PiCamera

camera = PiCamera()

interval_seconds = 10  # Time between shots
number_of_photos = 5  # How many photos to take

for photo_number in range(number_of_photos):
    camera.capture(f'image_{photo_number}.jpg')
    time.sleep(interval_seconds)

Use PiCamera() to control the Raspberry Pi camera.

time.sleep(seconds) pauses the program between shots.

Examples
If number_of_photos is zero, no pictures are taken.
Raspberry Pi
import time
from picamera import PiCamera

camera = PiCamera()

# Edge case: zero photos
number_of_photos = 0
for photo_number in range(number_of_photos):
    camera.capture(f'image_{photo_number}.jpg')
    time.sleep(5)
With one photo, the loop is not needed; just capture once.
Raspberry Pi
import time
from picamera import PiCamera

camera = PiCamera()

# Edge case: one photo
number_of_photos = 1
camera.capture('single_image.jpg')
Short intervals take photos quickly, useful for fast events.
Raspberry Pi
import time
from picamera import PiCamera

camera = PiCamera()

# Edge case: very short interval
interval_seconds = 0.5
number_of_photos = 3
for photo_number in range(number_of_photos):
    camera.capture(f'image_{photo_number}.jpg')
    time.sleep(interval_seconds)
Sample Program

This program takes 3 photos with 2 seconds between each. It prints messages so you know what is happening.

Raspberry Pi
import time
from picamera import PiCamera

# Create camera object
camera = PiCamera()

# Set interval between photos in seconds
interval_seconds = 2

# Number of photos to take
number_of_photos = 3

print('Starting time-lapse photography...')

# Take photos at intervals
for photo_number in range(number_of_photos):
    filename = f'image_{photo_number}.jpg'
    print(f'Taking photo {photo_number + 1} of {number_of_photos}: {filename}')
    camera.capture(filename)
    if photo_number < number_of_photos - 1:
        print(f'Waiting {interval_seconds} seconds before next photo...')
        time.sleep(interval_seconds)

print('Time-lapse photography complete.')
OutputSuccess
Important Notes

Time complexity: O(n) where n is the number of photos, because it takes each photo one by one.

Space complexity: O(1) for the program itself, but photos use storage space on the SD card.

Common mistake: forgetting to add delay between photos, which causes all photos to be taken instantly and defeats time-lapse purpose.

Use time-lapse photography when you want to see slow changes quickly. For fast events, normal video is better.

Summary

Time-lapse photography captures photos at set intervals to show slow changes quickly.

Use PiCamera and time.sleep() to control timing.

Remember to set a delay between shots to get the time-lapse effect.