Time Collapsing* Photos With OpenCV

Adam Derewecki
2 min readJul 10, 2019

Time Collapse of San Francisco

A few years ago, I had a camera looking out over San Francisco. It was hooked up to a Raspberry Pi that snapped a photo every minute and posted it. When there was a good sunset, I went back and made a time lapse video from the photos:

After a while of collecting photos, I started thinking about what else I could do. Inspired by photo projects that show the same scene throughout different seasons of the year, I decided to create a single photo from 24 hours of photos using OpenCV and Python:

import numpy as np
import cv2

filenames = ["file1.jpg", ... ]
columns = []

for i, filename in enumerate(filenames):
img: np.array = cv2.imread(f"p/{filename}")
height: int = len(img)
width: int = len(img[0])
column_start = 2 * i
column_end = 2 * i + 2
print(f"filename: {filename}, height: {height}, width: {width}, {column_start}-{column_end}")
column = img[0:height, column_start:column_end]
columns.append(column)

matrix = [[] for _ in range(height)]

for row_idx in range(height):
row = []
for col_idx in range(len(columns)):
pixels = columns[col_idx][row_idx]
matrix[row_idx] += list(pixels)

new_img = np.array([np.array(list(row)) for row in matrix])
cv2.imwrite('output.jpg', new_img)

I wouldn’t call the resulting image pretty, but I do think it’s interesting.

*It’s not clear if time collapsing is the proper term for this technique, but it makes sense to me

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Adam Derewecki
Adam Derewecki

Written by Adam Derewecki

Hi! I’m Adam. I live in San Francisco, write code, take pictures, and practice yoga.

No responses yet

Write a response