Time-lapse photography lets you capture slow changes by taking pictures at set intervals. When played fast, it shows a long event quickly.
Time-lapse photography in 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.
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)
import time from picamera import PiCamera camera = PiCamera() # Edge case: one photo number_of_photos = 1 camera.capture('single_image.jpg')
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)
This program takes 3 photos with 2 seconds between each. It prints messages so you know what is happening.
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.')
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.
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.
Practice
Solution
Step 1: Understand time-lapse photography concept
Time-lapse photography captures photos at regular intervals to speed up slow processes.Step 2: Compare options with concept
Only To capture images at set intervals to show slow changes quickly describes capturing images at intervals to show slow changes quickly.Final Answer:
To capture images at set intervals to show slow changes quickly -> Option AQuick Check:
Time-lapse = interval photos showing slow changes fast [OK]
- Confusing time-lapse with video recording
- Thinking it captures only one photo
- Assuming it streams live video
Solution
Step 1: Recall correct syntax for delay in Python
The correct function to pause execution is time.sleep(seconds).Step 2: Check each option
Only time.sleep(5) uses time.sleep(5), which is correct syntax for 5 seconds delay.Final Answer:
time.sleep(5) -> Option DQuick Check:
Delay = time.sleep(seconds) [OK]
- Using time.wait() which does not exist
- Swapping module and function names
- Using undefined delay() function
from picamera import PiCamera
import time
camera = PiCamera()
camera.start_preview()
for i in range(3):
camera.capture(f'image_{i}.jpg')
time.sleep(2)
camera.stop_preview()Solution
Step 1: Analyze the loop and capture calls
The loop runs 3 times (i=0,1,2), capturing images named image_0.jpg, image_1.jpg, image_2.jpg.Step 2: Understand timing between captures
After each capture, the program waits 2 seconds before next capture, so images are spaced by 2 seconds.Final Answer:
Three images named image_0.jpg, image_1.jpg, image_2.jpg saved with 2 seconds delay between each -> Option CQuick Check:
Loop 3 times + capture + sleep(2) = 3 spaced images [OK]
- Thinking only last image is saved
- Confusing preview with capture blocking
- Assuming f-string causes error
from picamera import PiCamera
import time
camera = PiCamera()
for i in range(5):
camera.capture('image_i.jpg')
time.sleep(1)Solution
Step 1: Check filename usage inside loop
The filename is a fixed string 'image_i.jpg', so each capture overwrites the previous image.Step 2: Verify other code parts
start_preview() is optional; time.sleep() works in loops; import order does not matter here.Final Answer:
The filename 'image_i.jpg' does not change, overwriting images -> Option BQuick Check:
Filename must vary to save multiple images [OK]
- Thinking start_preview() is mandatory
- Believing time.sleep() can't be in loops
- Assuming import order causes error
Solution
Step 1: Understand time-lapse capture timing
Photos must be taken every 3 seconds, so time.sleep(3) in a loop is correct.Step 2: Combine images into video
ffmpeg is a common tool to combine sequential images into a video file.Final Answer:
Capture images with time.sleep(3) in a loop, then use ffmpeg to combine images into a video -> Option AQuick Check:
Interval capture + ffmpeg video creation = correct workflow [OK]
- Skipping delay causing fast captures
- Using photo viewer instead of video tool
- Uploading images without video creation
Ready to prove it?
Pass the test and this pattern moves unknown
