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.

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.
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.


Leave a comment

What's allowed? Markdown syntax, with these caveats…
GitHub-Flavored Markdown

A couple aspects of GFM are supported:

  • Three backticks (```) above and below a section of code mark a code block. Begin a JavaScript block with ```js, Ruby with ```ruby, Python with ```python, or HTML with ```html.
  • Underscores in the middle of words (cool_method_name) will not be interpreted as emphasis.
HTML tags/attributes allowed

Whether you're writing HTML or Markdown, the resulting markup will be sanitized to remove anything not on this list.

<a href="" title="" class=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class=""> <del datetime=""> <em> <i> <li> <ol> <pre> <q cite=""> <s> <strike> <strong> <ul>

Now what? Subscribe to this entry's comment feed to follow the discussion.