Project Birds
Last year we had a lovely spring starting in April. I was unlucky to be on furlough during this time and had a lot of free time. One morning, I was sitting in my garden enjoying the weather, morning coffee and birdsong. Unfortunately, this idyllic morning was surrounded by pigeons or as my Dad calls them ‘flying rats’.
Pigeons know they are not welcome in my garden. Whenever they see any movement or hear how I shout at them, they run away. However, if there was another bird, the bird isn’t scared of my movement nor my voice.
I don’t want to sit at the window all day and check when the pigeon enters my garden (even if I have a lot of free time). So in my mind, I decided to create a project called “Project Bird” (codename: I hate pigeons).
The idea was simple: When any pigeon enters the garden — noise is made or lights are shone.
Project Setup
I already had all the tools: Raspberry PI, Camera and Azure Account, to start preparing the basic prototype.
There were four main steps to create this project:
- Get ready with Raspberry PI and get some simple webcam output.
- Save photo to Azure/OneDrive when there is movement in the garden.
- Create Custom Vision API to analyse birds in my garden
- Add some sensor to create voice/movement etc., when there are only pigeons in the garden.
The first step was easy to prepare. I had my Raspberry PI and a USB camera. I installed Windows 10 IoT Core and wrote a simple project (in C#) to have output from the camera.
Next, I wrote the custom code using the OpenCV library to make a photo when movement was detected. I decided to store all of these images in Azure Storage — to send them to Custom Vision and analyse them easily.
Image preparation
Before I could even start to analyse photos, I needed to train my Custom Vision to distinguish which birds are not pigeons.
When it comes to the longest stage — to manually check each photo, tag them to identify the bird, pigeon or other creature (e.g. cat, squirrel or fox). Then train Custom Vision and test the model with photos that were not part of training.
Why Custom Vision?
Azure Cognitive Services offer two Image analysis services — Computer Vision and Custom Vision.
With Computer Vision, I could still analyse the birds probably from the tags, and I was able to obtain information if this was a pigeon. However, Computer Vision was not enough for me, as I needed to have the correct information if the photo was a pigeon. Custom Vision gives me the tools to tag my photos and create a model based on them.
Realtime analysis
When the motion was detected, the camera takes a picture. The picture goes to Azure Storage. When a new item was added to Azure Storage — Microsoft Flow (now known as Power Automate) takes a photo, sends it to Custom Vision Model. Custom Vision analyses the photo and tags it with the bird name. The information is then with the tag and sent back to Raspberry Pi. If this was a pigeon — the light was switched on. After the next movement (when the pigeons go away), the picture is analysed and the light is switched off.
Potential improvements
There are few things that I would improve with this project:
- OS — I used Windows IoT Core, and the problem with OS is that you can have a USB Camera. In this situation, when you have a special camera for Raspberry PI that can detect motion at night, you are unable to use it.
- Programming language — because I would like to change the OS on Raspberry PI to non-Windows, automatically, I’ll write some code in Python (even if you can write in .NET Core, Python has more libraries for Data Science that can be easily used)
- Internet — each image is sent to Azure Storage, then analysed and sent back to Raspberry PI and takes some time. Ideally, in this instance, it is best to have the model on Raspberry PI and run it offline. Synchronisation and removing images from the local storage can be done once per hour.
- Sensor — I will use a voice recording to scare the pigeons, as the lights are not so penetrating during the day.
What did I learn?
This was my first Raspberry PI project. I learnt a lot about setting up the tiny machine and how powerful it is. I tried many libraries for .NET about motion detection, but not all of them work smoothly with Raspberry PI on Windows IoT Core. The Custom Vision and Azure are very powerful and easy to set up and in less than a few hours, I have a model ready with automation via Power Automate.
And finally — my feelings for pigeons have not changed at all!