Catflap with raspberry pi plus camera and image recognition to keep the cat from bringing prey inside
This project is maintained by maxkostka
The catflap for detecting prey in the cats snout. Based on a raspberry pi 2 with the raspicam and the catflap sureflap. The raspberry runs ubuntu with ros indigo, python 2.x opencv. The system has 4 sensors, two ir sensors to detect the presence of a cat in the catflap tunnel, a sensor to check, whether the status of the flap and a camera to take pictures of the cats profile.
I further think that the original idea was not created by the three youngsters or at least they were not the only ones. I was further inspired by joakim soderberg and the catcierge https://joakimsoderberg.github.io/catcierge/ (Nice work Joakim!) and the flow control project which can no longer be found on the web (origial url: http://www.quantumpicture.com/Flo_Control/flo_control.htm) but we can find some remaints of its impact on others http://www.openscience.org/blog/?p=109.
Some time after the flo control project, three germans participated in a contest called 'jugend forscht' http://www.neumarktonline.de/art.php?newsid=59507) with a simpler concept only using light barriers. The price was patent application http://www.freepatentsonline.com/DE202009002677.html which is currently owned by the Feldberglicht GmbH. They are still developing a commercial application or at least the say they are developing- check it out http://www.mouse-lock.de/. But don't expect a working catflap before a working fusion reactor ;)
usage so far
roslaunch catflap_training.launch
to start the ros nodes to aquire images, when a cat passes the flapi added the startup.sh via
sudo crontab -e
just add a line like
@reboot /home/max/projects/catflap/ros_catkin_ws/src/startup.sh >>/home/max/projects/catflap/log_launch 2>&1
to start it at when the raspi boots up.
What it looks like:
My work is based on a SureFlap catflap that I bought three years ago. It has the feature to learn the signature of certain RFID devices which are used to tag cats, and release the catflap lock only for known RFID signatures.
I bought the catflap as it has a convenient locking mechanism included. We had two cats at that time. They embraced their freedom to come and leave as they wanted and - as any decent cat would do - brought back prey from time to time as a present - as a proof of their love. I planned on stopping the - to me sometimes very disgusting - presents with a raspberry pi I had at home. The idea was to pictures of the cat before it enters the flap, and with some image recognition, release the lock only when there is no prey in the cats snout. I build a housing to mount it in front of my catflap, which contained the raspberry pi together with the raspi cam, two ir sensors mounted at the entrance of the housing an a IR LED spotlight behind the camera, lighting the cat that enters.
After a while I switched to a setup using backlight and modified my housing accordingly, as my plans were to work on black and white images of the cats contours. I want to show you two images with very nice presents:)
Unfortunately, my cat Luigi was hit by a cat and died, and the other cat Socke lived with us for some more months. At some day she just didn't return home. We never found out what happened to her, hopefully she just found a new home. So this was the end of the catflap plans - prototype one.
A little down the road we decided to get two new cats. Since Socke and Luigi had a lot of bad luck, we did not want to let them go outdoors. Bad luck did not end here, one of the two, called Kitty died soon after we got her (FIP) So we were a one cat household with an indoor cat.
But a little further down the road our household got a new fellow lodger, the cutest baby in the world :) And things got worse with our cat Charlie. She simply has a loooooot of energy that she could not for her life shake off during her day or her night. So after some artistic high speed stunts involving rayor sharp claws very close to our baby we decided that Charlie should indeed be an outdoor cat again. This time the catflap would lead her to the garden, and not he front door, minimizing the need to cross the street there and the according risks of getting hit by a cat or something.
In her first night out our cat must have been replaced by someone or at least brainwashed. The standoffish cat left and a snuggly cat returned home. But it's ok for us, she still looks the same:)
Considering the energy Charlie displayed so far I expected her to bring home a small deer or one of the neighbours dogs at least on one of her next next nightly tours. we were lucky so far, she only brought in small insects.
In the meantime a raspberry pi 2 was bought, a new housing was constructed and I heard about ros and wanted to try it out. And here we are with the catflap. Right now it can aquire images, when a cat enters the door and does not take pictures when the door is already open, or when a cat is leaving the house.
Two IR sensors detect when Charlie enters the housing. A door sensor detects, if the door is closed or open. When a the IR sensors are active and the door is closed and an internal timeout has elapsed, the backlight is turned on and an image is recorded, saved, and the backlight is turned off. A timeout is set to a certain short period then (under a second). If the IR sensors are still active, the door is still closed when the timeout has elapsed, the light is turned on again, image recorded ... timeout is set again ... and so on until the door is opened.
As long as the door is open no image will be recorded. When the door closes, a timeout is set to a certain long period to get a certain dead time (about 5 seconds).
The next steps are: