# i attached a camera to my window

source: https://samliu.dev/writing/camera-on-window
posted: 21 nov, 2026 · 10 min read

> [!info] this page is best viewed with hdr!
> standard screens will look okay (i tried my best), but if you have a phone that supports it, i'd recommend viewing this with that.

yes, i have a camera attached to my window! the view out my window as of {{live:capture-time}}:

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the live view out my window](https://now.samliu.dev/cam.jpg)

*this is live! (takes ~10 min to process and update)*

it's captured by this little thing!

![the camera mounted on my window](/writing/camera-on-window/01.webp)

## what's the point

i currently live at the university of waterloo's "rev" residence, and compared to the other rooms here, i actually have a pretty good view! it's especially pretty in the morning when the sun rises.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the view from the camera on nov 1 at 8:10 am, processed and color graded automatically](https://samliu.dev/writing/camera-on-window/figures/01.webp)

*from the camera and processed. nov 1, 8:10 am*

as the seasons change, it would be so cool to be able to have a timelapse! something like this, but for an entire month... 

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

a timelapse of the sunrise on nov 21

the camera takes 5 exposures every 200 seconds, archives the raw digital negative, then automatically color grades them! footage at night isn't saved due to storage costs, each group of 5 exposures is 70 mb!

(unfortunately, i have to move out mid-december, so it won't catch the snowfall)
## the hardware!

the camera is an [arducam IMX519 (with autofocus)](https://www.arducam.com/imx519-autofocus-camera-module-for-raspberry-pi-arducam-b0371.html). at $25 usd, it's probably the best camera with an impressive 16MP resolution and pretty good color accuracy. it's not best for video purposes, but for still shots it's awesome at the price. using a csi camera allows me to get the raw sensor data, which allows me to adjust my processing pipeline in the future.

![image from amazon|389](/writing/camera-on-window/02.webp)

image from [amazon](https://www.amazon.ca/dp/B0B3XBQM9Z)

to keep it compact, the camera is hooked up to a raspberry pi zero 2w, which transmits the raw footage off to be processed.

### camera mount

the mount was designed in onshape. i wasn't super sure about the dimensions, so i split it into 3 parts to reduce re-printing. it was printed in pla, but petg would be better to avoid heat deformation from sunlight.

![the camera mount in onshape](/writing/camera-on-window/03.webp)

all 3 sections are connected via a singular m3 screw and a self-aligning pocket. i didn't have threaded inserts, and the entire thing doesn't need to be super strong, so this was more than sufficient.

![the self-aligning pocket that joins the sections](/writing/camera-on-window/04.webp)

i didn't want to pay $15 for a camera housing, so i designed my own with a snap-on cover. tolerances took a few test prints to get right.

![the camera housing with its snap-on cover](/writing/camera-on-window/05.webp)

for secure attachment. my dorm didn't allow drilling holes into my wall... but luckily, my window has this end stop that was pretty useless, and it had 2 mounting holes. so i replaced it...

![the mount screwed into the window end stop](/writing/camera-on-window/06.webp)
## the software
the hardware was pretty straightforward! building the software took me down many rabbit holes. much was learned about image processing.
### capturing and storing the images
we capture 5 frames raw every 200 seconds with fixed focus, auto exposure (with 5 brackets, thus the 5 frames).

the end goal is to render a smooth timelapse, so the pipeline needs to never, ever lose or miss a capture. the entire pipeline is designed around this and to auto recover.

there are 4 devices that make this work:

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

the rpi zero 2w hashes each capture and uploads it to the rpi 5, which sends back a verification, compresses it and makes a preview; the rpi 5 uploads archives to the storage box and the preview and heartbeat to the vps; the zero also sends a heartbeat; the vps verifies the archives, serves the preview and sends alerts through a slack webhook

- **rpi zero 2w**: compact enough to sit next to the camera
- **rpi 5**: powerful enough and local to do compression and render low res previews
- **hetzner vps (cpx11)**: most reliable. used for monitoring, and serving data publicly
- **hetzner storage box**: 1tb long term archive for raw footage

both pis send heartbeats to the vps. the two hetzner services cost $11 usd a month.

a slack webhook is used as the monitoring service, since i check slack often and it's super reliable compared to an email or text. a test message is sent every week just to confirm it's still working.

upon capture, we hash the footage using sha-256. when footage is transferred, we always verify the hash on the recipient before deleting the original. when there's enough storage, we retain the original for a while just in case.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

where copies of one capture exist over its first day; each is deleted only after a later copy has been proven

the rpi zero 2w is the most important device since it does the capturing. checks are in place for captures, memory, network, and a hardware watchdog will reboot in case of a total freeze. the rpi 5 is the gateway to the storage box, so it also has checks to make sure everything runs.

raw footage is a lot of data even after compression, and there's only 1tb to store it. since the night is pretty boring, we only save captures from nautical dawn to nautical dusk. at around 15gb a day post-compression, 1tb stores around 2 months.

### image processing
i originally thought this was going to be super easy. i want the footage to look as close to real life as i can. i don't really process photos from my phone and they look pretty good already... this can't be that hard.

here's a comparison. left is straight out of the camera with defaults, and right is my processing pipeline.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

the nov 21 sunrise straight out of the camera beside the same footage through my pipeline

*nov 21, 6:16 am → 10:56 am*

the camera's honestly pretty good already for $25, but there was a vignette, the colors were dull, the color balance was too blue and flickered, it was super dark at night, overexposed at dawn, amongst other issues.

here's a closer look with one frame

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![one frame straight out of the camera compared with the same frame through my pipeline](https://samliu.dev/writing/camera-on-window/figures/08.jpg)

*nov 21, 7:50 am*

#### 1. dynamic range

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the processing steps so far, up to merged](https://samliu.dev/writing/camera-on-window/figures/10.jpg)

the camera struggles with high contrast scenes. at times of the day we lose detail as the sensor blows out super bright highlights and crushes dark shadows. the data is lost so there's no way to recover the detail. 

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![a single exposure with its blown out sky in red and crushed shadows in blue](https://samliu.dev/writing/camera-on-window/figures/19.jpg)

*nov 1, 6:40 am*

a common solution is to take many frames at varying levels of exposure.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the five exposures of one capture, from -4 ev to +4 ev](https://samliu.dev/writing/camera-on-window/figures/20.jpg)

*nov 21, 7:20 am*

after combining them the image might feel flatter or darker, but you'll be able to see more detail. we need to further color grade to bring back the contrast and color that we want.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![one exposure compared with all five exposures combined](https://samliu.dev/writing/camera-on-window/figures/25.jpg)

*nov 1, 6:40 am*

we merge these 5 exposures by giving each pixel a trust value. a pixel is more trusted when the pixel isn't too dark or blown out. we then combine pixels weighted by their trust.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![how much each of the five exposures counts in the final picture, white where it carries the pixel](https://samliu.dev/writing/camera-on-window/figures/27.jpg)

*pixels used in the final picture. nov 21, 7:20 am*

you can see that for the sky, more of the darker exposures are used since they aren't blown out there, and for the dark shadows, we use the brighter exposure more. 

using exposure bracketing also gives us enough range for our final result to be HDR, we'll touch on this later.
#### 2. vignette

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the processing steps so far, up to vignette](https://samliu.dev/writing/camera-on-window/figures/10.jpg)

without correction, edges of an image look darker since less light physically hits the sensor there. a quick fix is to point the camera at a uniform, white sheet of paper, and try to undo the vignette by brightening up the edges.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the frame before and after vignette correction](https://samliu.dev/writing/camera-on-window/figures/32.jpg)

*nov 21, 7:50 am*



<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![a clear sky before and after vignette correction, darker in the top corners before](https://samliu.dev/writing/camera-on-window/figures/34.jpg)

*look at the top-right corner. nov 1, 11:07 am*

on the before, if you look at the sky, you can see it's slightly darker towards the right corner. we can actually visualize how much correction we're applying. here's the green channel

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the green channel vignette correction, 1x in the middle rising to 4x in the corners](https://samliu.dev/writing/camera-on-window/figures/36.jpg)

*green channel correction*

we see a slightly redder-shift in the image's color. the vignette correction is applied differently for different color channels. we'll correct this later.
#### 3. color speckle

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the processing steps so far, up to speckle](https://samliu.dev/writing/camera-on-window/figures/10.jpg)

the sensor's built in color filter introduces some artifacts, especially around bright edges. a chroma noise reduction throws out outlier colors and fixes it.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![color speckle on branches and on a distant lamp, before and after chroma noise reduction](https://samliu.dev/writing/camera-on-window/figures/37.png)

do note that this isn't chromatic aberration!
#### 4. white balance

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the processing steps so far, up to white balance](https://samliu.dev/writing/camera-on-window/figures/10.jpg)

the camera's built-in white balance is okay, but it still gets it wrong pretty often. we can apply a technique known as grey-pixel, which finds places where the texture is color-neutral and tries to balance them.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the pixels grey-pixel picked as neutral, marked in red](https://samliu.dev/writing/camera-on-window/figures/41.jpg)

*nov 1, 9:00 am*

compared to the camera's guess, which we've used so far, it's more true to eye.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the camera's white balance compared with grey-pixel on three different frames](https://samliu.dev/writing/camera-on-window/figures/42.jpg)

built-in white balance also doesn't care how the scene changes, so it will jump around. we apply some smoothing along the use of grey-pixel correction to help compensate.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

the camera's white balance jumping between frames beside smoothed grey-pixel, on the basketball court

*zoomed on the court. nov 21, 9:13 am → 9:50 am*

here's what we get after white balance correction! notice the redder-shift from the vignette step is gone.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the frame with the camera's white balance and with grey-pixel](https://samliu.dev/writing/camera-on-window/figures/50.jpg)

*nov 21, 7:50 am*

#### 5. exposure

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the processing steps so far, up to exposure](https://samliu.dev/writing/camera-on-window/figures/10.jpg)

auto exposure makes every frame the same brightness, in the evening the image would feel bright and it's hard to tell the time of day. in a timelapse the relative darkness is also messed up and we lose the sense of the sky getting darker.

measuring how bright noon is allows us to anchor all frames, but it's a bit too extreme and makes the nights too dark, so we combine both techniques.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

a morning timelapse with auto exposure beside our exposure method

*nov 21, 6:16 am → 10:56 am*



<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![five times of the morning with auto exposure and with our exposure method](https://samliu.dev/writing/camera-on-window/figures/54.jpg)

our image becomes darker, since it's in the early morning.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the frame with auto exposure and with our exposure method](https://samliu.dev/writing/camera-on-window/figures/51.jpg)

*nov 21, 7:50 am*

#### 6. color grading

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the processing steps so far, up to hdr grade](https://samliu.dev/writing/camera-on-window/figures/10.jpg)

right now our image looks flat and washed out, since we've prioritized preserving detail while getting the basics right. color grading brings the contrast and coloring back, and to take advantage of the extra brightness in hdr.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the frame before and after color grading](https://samliu.dev/writing/camera-on-window/figures/64.jpg)

*nov 21, 7:50 am*

flat dusk is naturally pretty dull and low in contrast, so i added a shadow floor which deepens shadows in flatter frames

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the frame with the shadow floor off and on](https://samliu.dev/writing/camera-on-window/figures/66.jpg)

*nov 21, 7:50 am*

this step took hours to get right, and it was so painfully slow since i needed to make sure it looked good at varying times of the day and lighting conditions.

if you have an hdr display, you'll see a difference, otherwise, it'll just be the same image.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the same frame in hdr and sdr](https://samliu.dev/writing/camera-on-window/figures/68.avif)

*nov 21, 7:50 am*

#### 7. hdr to sdr

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the processing steps so far, up to sdr grade](https://samliu.dev/writing/camera-on-window/figures/10.jpg)

so far we've been working with hdr images, but most displays are sdr and by default, it looks pretty inconsistent across displays since by default each one does conversion differently.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![the hdr frame through a standard sdr conversion and through my tuning](https://samliu.dev/writing/camera-on-window/figures/70.jpg)

*nov 21, 7:50 am*

youtube's default also looks pretty bad...

here's my lut compared to youtube's, it's quite different.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![youtube's sdr conversion compared with my lut, at dusk and at night](https://samliu.dev/writing/camera-on-window/figures/72.jpg)

*oct 31, 5:43 pm and 7:06 pm*

### fun bugs along the way...

#### magenta lamps
areas overexposed even in the lowest exposure ended up to be magenta. no frames were trustworthy, so the merger just guessed.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![a blown out lamp core turning magenta before the fix and white after it](https://samliu.dev/writing/camera-on-window/figures/76.jpg)

*3× zoom. nov 21, 6:40 am*

#### pale sky
when a sky is too bright, we only dimmed the bright channel instead of all, causing blue to be lost in the sky.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![a bright sky that lost its blue before the fix and keeps it after](https://samliu.dev/writing/camera-on-window/figures/78.jpg)

*nov 21, 8:26 am*

#### leaves messing with white balance
in certain lighting conditions the grey-pixel treated yellow leaves as neutral grays. they're now ignored when it doesn't make sense.

<!-- The following is an interactive figure, not part of standard Markdown. The Markdown format of this page may not have rendered properly. -->

![white balance thrown off by sunlit leaves before the fix and correct after it](https://samliu.dev/writing/camera-on-window/figures/80.jpg)

*nov 1, 4:10 pm*
