Birdcam, or: the unexpected virtue of dumb ideas

Posted in Articles, Development, Raspberry Pi

I don’t have the patience to learn new skills for their own sake. Most of what I know about computers, including everything I do at my day job, was something I learned because I needed it to do something cool. In 2001 I needed to learn PHP to make a web site, and in 2005 I needed to learn JavaScript to make a Dashboard widget. (Man, I miss Dashboard widgets.)

That’s one reason why I’m thankful for Raspberry Pis — they allow me to scratch certain technical itches with skills I mostly already have. Arduinos? Feh — I’m out of my element. I’d rather throw some overqualified hardware at the task.

To illustrate: my first Raspberry Pi project was a white/brown noise machine for drowning out snoring. That’s right — an entire Linux system was dedicated to the task of making a fuzzy sound all night, largely when Barbara and I wouldn’t be awake to hear it. All it did was run this script for a certain number of minutes. How did I control it? Glad you asked — instead of messing with GPIO and physical buttons, I just wrote a Sinatra app so that I could control the thing from a web page.

I’m not suggesting that laziness is a virtue. But there was no way I was going to learn about GPIO just to make a white noise machine when I wasn’t even sure if we’d use it for more than a couple of weeks. (We didn’t.)

But this post isn’t about a white noise machine. In general, this post is about how Raspberry Pis allow me to scratch mild itches. Specifically, this post is about a birdcam.

The silly idea

A few weeks ago, Barbara bought a bird feeder for our backyard. She wanted to look at birds more often. I don’t give a damn about birds either way, so this was fine with me. Our back porch has a beam that overhangs into an ideal spot — sunny and right outside our kitchen window.

Window
The window.

After a couple days, she mentioned how she hadn’t seen any birds yet. I told her she hadn’t seen any birds yet because she wasn’t willing to stare out our kitchen window all day. She reminded me that she has a full‐time job.

Hence it occurred to me: couldn’t we make a machine be our bird scout? I wasn’t willing to drop $200 on a Dropcam for the sake of birds, but I could get a $30 webcam and hook it up to one of our extra Raspberry Pis.

The short version

I’ve got a detailed writeup of what I did, but I’ll save it for another post. Here’s the short version:

Put together correctly, this hardware becomes a nest of wires — but an intelligent one that can stare at something for a long time and yell if anything moves.

To do that, we install Motion. Motion is the typical open‐source project: it does about 85% of what I’d want ideally, but it’s way easier than writing my own thing. It was pretty easy (by Linux standards) to figure out how to use it well enough to do what I needed to do, which made it suitable for this particular dumb idea.

How it works

We’ve now got a nest of wires in our kitchen window, plus a webcam pointing straight at a bird feeder. Through a convoluted process, here’s roughly what happens:

  • Motion starts up on boot and observes the webcam image three times every second.
  • When there’s enough movement to exceed its (configurable) movement threshold, it starts recording.
  • When the movement stops and doesn’t start up again for at least 60 seconds, it stops recording, and dumps the video file into the /tmp/motion directory.
  • Luckily, Motion lets me run a script whenever a video is done recording. I wrote a Ruby script that uploads the file to a folder in my Dropbox (via Dropbox Uploader) and then deletes it from the RPi once it’s uploaded.
  • I’ve shared that folder with Barbara so that she can look at bird videos whenever she wants.
Birdcam
The equipment.

On top of that, Motion will stream a webcam image on port 8081, so when she’s working from her home office Barbara can just open a browser tab to http://birdcam.local:8081 and get a live view of our bird feeder.

Using Dropbox allows us to check on urgent birdcam activity even when we happen to be out of the house. But no aspect of the RPi itself (nor its webcam stream) is accessible from outside of our home network because we’d like to steer clear of that creepy Twitter account that just posts screenshots from unsecured webcams.

Wait, it doesn’t work

One of my concerns was that the motion detection would be too sensitive. You can tell Motion how sensitive it should be, but I didn’t know whether there existed a sensitivity threshold that would reliably distinguish the movement of a bird from, say, the movement caused by a strong gust of wind.

Now I know for sure: for our circumstances, I’m correct. There is no such threshold. We started running birdcam on Saturday morning and got a whole bunch of movie files in the early afternoon that were bird‐free. That’s no fun. I know what the rustling of trees looks like; I don’t need periodic video reminders on my phone. The more false positives there are, the more tedious it will be to sift through the video files, and the less useful birdcam will be.

How do I filter out the non‐bird videos? I don’t have my own research team. I’m not about to dive into machine learning and train my birdcam by dividing up 10,000 images into bird/not‐bird buckets. This is a dumb project and it needs a dumb solution.

Motion lets you specify a greyscale image file of the same dimensions as your webcam and have it act as a sensitivity mask. With such a mask, I could tell Motion to ignore an entire region of the image, or to look for motion only in the precise part of the image where the bird feeder is. That would probably reduce the number of false positives. But it’s not dumb enough. If the webcam changed position or angle, whether accidentally or on purpose, I’d have to make a whole new mask image.

Thinking I was stuck, I started idly flipping through Saturday’s birdcam videos. Many of the videos were just a few frames long — which, at three frames per second, makes for some boring movies, I’ve got to say. Even if a video has a bird in it, it’s not worth watching if it’s only a second long. Then, on a hunch, I dropped all the videos into a VLC playlist and sorted the playlist by duration descending. Starting with the longest video, I got through about twenty videos of birds before I ran into even one false positive. Aha!

OK, it works again

I modified my movie‐handling script to enforce a minimum file size. If the video exceeds that file size, it goes onto Dropbox, then gets deleted from the RPi. If it’s too small, it just gets deleted. A size threshold of around 700 kilobytes seemed to give me the best compromise between false positives and false negatives.

This is a dumber solution than the image mask, but it’s exactly the right amount of dumb. If we want to repurpose birdcam for another task later on, like keeping an eye on our dog when we’re out of the house in case she starts eating drink coasters, the file size threshold will probably end up being useful even if we have to play around with the exact number.

The point

Having read this far, you might be disappointed to learn that there are only about four different kinds of birds that visit our feeder, and that it does not make for captivating television. You’re welcome to judge for yourself. If nothing else it’s confirmed for us that the feeder is squirrel‐proof.

So why did I do any of this? I assure you: it’s not because I like birds. It makes Barbara happy, but I probably could’ve made her similarly happy doing some other good deed that would’ve taken less time. And I’m pretty sure even Barbara won’t care about birdcam in a month’s time. Maybe we’ll leave it running and just check in occasionally.

This is the third RPi I’ve devoted to a weird task around the house. None of them are all that useful in their own right, but each has helped me get better at the weird task of talking to a tiny headless computer. I may not even have attempted birdcam if I hadn’t first proved I could make a white noise machine. Dumb ideas warrant dumb solutions because finishing is the important part. Finishing breeds confidence, confidence extends your comfort zone, and a large comfort zone leads to better and more ambitious ideas.

Birdcam was the good kind of dumb idea: it amused me just enough to motivate me to try to build it. Judge your ideas not just for their usefulness but for their worth as mind exercises.

quotation

Mr. Duncan did not strike me as a fool and individual acts seldom define people, but the red binder he offered to the officers and the “affidavit of truth” he offered to me in court were regrettable descents into foolishness and Mr. Duncan would be well‐advised to be more discriminating on what parts of the internet he models himself upon in the future.

Justice Fergus O’Donnell
quotation

Just use your brain. I’m not sure our industry says this often enough. You’re smart, you make the internet, and you can make good decisions. Pay attention to your craft, weigh the good against the bad, and check your assumptions as you go.

Dave Rupert
quotation

In the playoffs, every story line is ex post facto, with the process graded after the fact by whatever the outcome was. You know the stories. A team with a first‐round bye is refreshed and full of energy if they blow out their opponents (often as big favorites at home), but rusty and lost their timing if they lose to their opponents, who don’t have anybody believing in them but themselves. It’s one of the laziest bits of analysis you’ll see about sports.

Bill Barnwell

Hypermedia APIs, Part Two

Posted in Articles, Development, Ruby, Web

Last time, I treated you guys to some Solomonesque baby‐splitting between Steve Klabnik and DHH, and then spent two dozen paragraphs talking about how Gowalla’s API was pretty groundbreaking and how Scott Raymond was like the Lou Reed of hypermedia APIs. To balance out all this ridiculous self‐praise, I’ll talk

Read more →
review
1
Mass Effect 3

Mass Effect 3

Verdict: 89/100 (Minimum score is 0; maximum is 100.)

I think so many things about the Mass Effect series, far too many to corral into a focused thought. I know because I’ve tried to write this review several times already and I have nothing to show for it except thirty paragraphs of ramblings.

My brain lies to me sometimes. Because I’d loved Mass Effect, and because Mass Effect 2 changed several of the things I’d loved about the first game, I convinced myself that the sequel wasn’t quite as good. It had been a year and a half since I’d touched either game, so after I finished Mass Effect 3 I decided to go back to the very beginning and do a marathon playthrough with a fresh character. Not only would it be a plot refresher, but it’d let me undo all of the dumb mistakes I made in games one and two that I ended up having to pay for in game three.

Read more →
review
Infamous 2

Infamous 2

Verdict: 67/100 (Minimum score is 0; maximum is 100.)

I’m a tough man to write video games for. Any triple‐A title released for a major console is the result of so much craftsmanship from so many talented people, such that you can find genuinely good things to say about even the mediocre ones.

Why do I want a game to have long‐lasting impact? Why does it have to be profound to me after I’m done with it? I played the original Infamous for at least fifteen hours — doesn’t that say more about its quality than whatever I feel about it eighteen months later?

Read more →
quotation

The Act does not compel physicians to apprise women of the risks inherent in abortion, inform the women of available alternatives, and facilitate access to additional information if the women wish to review it before making their decisions; existing Texas law already compels such speech by physicians… Instead, the Act compels physicians to advance an ideological agenda with which they may not agree, regardless of any medical necessity, and irrespective of whether the pregnant women wish to listen.

Judge Sam Sparks
quotation

Many readers were enraged that I could support taxation in any form. It was as if I had proposed this mad scheme of confiscation for the first time in history. Several cited my framing of the question — “how much wealth can one person be allowed to keep?” — as especially sinister, as though I had asked, “how many of his internal organs can one person be allowed to keep?”

Sam Harris