rebecca2525 (rebecca2525) wrote,

Birds + Coding = ♥

In March I installed a bird bath on the landing of our fire escape.

The wooden frame isn’t a pretty sight, and I totally messed up the part about right angles and equal sides, but no-one’s going to see it and it’s hard to make the fire escape any uglier than it already is. ;-) The frame is tied to the grid to prevent the dish from sliding off the landing – it took us surprisingly long to come up with this simple solution to secure the dish.

I wasn't sure how much traffic the bath was going to get since we live in the middle of the city. We can hear a variety of different species through the windows, but most of them don't come to our (quite barren) backyard, except for the swifts (who need larger bodies of water to drink from since they drink during flight), the pair of black restarts who were breeding here the last couple of years, and blackbirds.

So of course I was curious, but since I am out of house most of the time I'm probably missing a lot, especially back in March when it was already getting dark when I was getting home from work.

So I thought: technology to the rescue! First I put up my digital camera and programmed it to take timed photos every couple of seconds. The camera runs off a battery though and isn't really made for running non-stop. It only lasted for a good three hours. Still, it left me with a couple hundred photos to sort through in the evening. I wrote a little program to check for differences in two subsequent photos — images are just a sequence of numbers, so you can easily calculate their Euclidean distance — and it seemed to work quite well, though I didn't catch any birds.

What to do? Enter the Raspberry PI! It's a tiny little computer, very cheap with a very low energy footprint — ideal for running it 24/7. I've been considering buying one for a while since having a small Linux server running all the time can be quite handy for a couple of things, but so far I haven't gotten around to it. I learned that there's even a special Webcam for the Raspberry PI though, with everything about it programmable, so it was ideal to become my BirdCam. Having a real computer at your disposal means you can analyse the photos before you save them, thus saving a lot of space. This is what my setup looks like (note the 'professional' camera mount):

The code I wrote for my digital camera didn't work well with the webcam. The webcam's quality isn't bad for a webcam, but it does a couple of seemingly random lighting changes when the actual lighting doesn't really change, leading to big differences in susequent photos even though nothing was happening. However, the camera records motion data, which you can analyse in your code. To test it, I built a little bird dummy, which is a sock on a string tied to a broomstick:

Attack of the flying sock (with hard lighting conditions):

And this morning, my BirdCam caught the first bird! A female common blackbird coming to have a look. Carefully approaching:

Contemplating the water:

Looking around:

She might have drunk, too, but I'm currently snapping photos only every 7 seconds or so as to not spam my SD card. Once I have a feeling for the correct values and am not saving too many boring photos anymore, I can take photos more frequently, or maybe even save videos. But right now it's not looking like I will be able to reliably tell birds from other false positives, and I guess once the swifts are back and circling the backyard, it will only get worse. I have an infrared sensor that I could use as well, maybe combine its readings with the motion values from the camera? Only problem is that the IR sensor needs to be installed outside since it doesn't work through glass, which means I have to weatherproof it.

We'll see. I'm already happy with how far I've come in a very short time. The code is smart enough to only snap pictures when the sun is up, so I can let it run unsupervised for a while and just check up on the pictures via a webserver.

Anyway, bird! \o/

This entry was originally posted at Please comment there using OpenID.
Tags: birds, coding
  • Post a new comment


    default userpic

    Your reply will be screened

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.