Thursday, August 22, 2013
4:20 AM

Hey Raspberry PI, where is my cat?

Introduction

Last week my family went on a summer holiday to Menorca leaving me at home with just the cats for company.

Half way through the week I realised that 5 cats had become 4 and that I hadn't seen one for a good couple of days.

Realising that my wife would kill me if one of the cats went missing on my watch, I set about searching for the cat around the local village.

The cat in question is a young female cat called "Pippin" and her defining feature is that she is known as a Calico cat. What all this means is that she is white, with patches of black and orange and she is a little bit unhinged.

Pippin has gone missing before and commonly shows up at the house at the end of the farmers field near our house and has been known to live on a diet of potatoes?!? 

Needless to say on this occasion I searched the village and Pippin was not to be seen.

It occurred to me however that Pippin may well be coming into the house at night when I am asleep in my bed. To see if this was the case I set up "CatCam".

CatCam Version 1 

My first idea was to connect a webcam to the Raspberry PI and use image capturing software to take photos of the cat flap at various intervals to see if the camera would spot Pippin coming into or out of the house during the night.

To do this I loaded a piece of software onto the Raspberry PI called "Camorama". 


The first thing I would like to say is that the webcam used cost just £2 from Tesco and the quality of the webcam looks like something that would pop out of those "good" Christmas crackers. 

You know the Christmas crackers that I am on about don't you? They are the sort of cracker that my mum would say "Ooh aren't these are good crackers" after finding a small metal salt pot that holds just enough salt to pour onto one person's dinner for one night.

So what else might you find in the crackers? Well there would be a yo-yo that doesn't yo-yo, a retractable USB mouse, a tie pin, cuff links and a small set of screwdrivers (which is the only really useful item in the whole box). These are "good" crackers because the "not so good" crackers only have plastic spinning tops, black moustaches that as a kid I thought were bats, plastic rings and a magic trick.

The idea though wasn't to take high quality images. The idea was to find Pippin, so as long as the camera could take photos of cat shaped items I should have been able to make out whether one of those images contained Pippin.

If you select "Edit -> preferences" within Camorama the following screen appears:


The preferences screen lets you change a number of settings but what I wanted to do was set up the camera to point at a cat flap and take an image every so many minutes.

Now rather stupidly I set the capture interval to 5 minutes but I will come back to this later. 



On the "Local Capture" tab you can define where the images are stored and set up the file format and the file name structure to be used.

I set up the Raspberry PI in the utility room where the cat flap is and I then used VNC to connect to the Raspberry PI (using a similar technique as shown in my article "Connecting via VNC to Raspberry PI from Google Nexus 7"). 

I then ran the Camorama software and let it run all night taking pictures every 5 minutes and I stored them on the SD card. I could have stored the images remotely and there is an FTP option under the "Remote Capture" tab but it didn't seem necessary.

So why is taking a photo every 5 minutes incredibly stupid? Well cats are quite quick. They can get through a cat flap in a second and I would have to be incredibly lucky to actually manage to capture a shot of the missing Pippin.


Meet Pippin everyone. Yes although my plan was very dumb I also happen to be a fairly lucky individual and as luck would have it just after midnight my feline friend appeared on the mat just inside the cat flap.

How lucky is that? I can tell you that the cat slept there until 5.45 am when she left the house and wasn't seen again until the weekend.

Pippin isn't a particularly friendly cat. She is a little bit bitey, very scratchy and much prefers my wife to me. 

This is really where this article should end because having found the cat there really was no need for me to come up with CatCam 2 but I just couldn't do it. I couldn't leave this project in such a sorry state.

CatCam Version 2 

I realised that what I really should have done was find some software that can handle motion detection.

A quick search online and I found an application called "Motion".

"Motion" acts like CCTV software and you can access the live view of the camera via an internal webpage.

To install "Motion" all I had to do was type "sudo apt-get install motion". The software was installed and the service was started.

Motion is controlled using the motion.conf settings file and I had to edit this file to get Motion to do what I wanted.


The main problem I had however was that my camera is rubbish. Therefore I had to add these two lines at the beginning of /etc/init.d/motion file:

LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libv4l/v4l1compat.so
export LD_PRELOAD

Now when I log on to my browser from any computer within my house I can type in the path to the Raspberry PI with the port 8081 at the end and see the cam.





















On the Raspberry PI itself the folder containing images /tmp/motion is filling up quite quickly but because the file size is relatively small it will last a while on a decent sized SD Card.

To resolve this I could set up motion to send the images remotely. In this solution you can transfer images caught from Motion to Dropbox

I have found the cat now though so I no longer need to monitor the cat flap so it is time to switch it off.

Summary

Generally I use my Raspberry PI for retrogaming. I have written a number of articles about the Raspberry PI on the imaginatively title "Raspberry PI" page.

I had never intended to write an article about finding a cat using the Raspberry PI but having used the Raspberry PI for just that purpose I thought I may as well write about it.

Thankyou for reading.

0 comments:

Post a Comment