BigJinge
Posts: 31
Joined: Sat Jul 09, 2016 12:23 pm

The Integrated Cat Flap : Pi Zero

Fri Jan 20, 2017 1:33 am

Hello,

I've been working on a project over the last year (time permitting) and would love some feedback.

We have a cat who is a very avid hunter and wanted to stop her from bringing her "wares" into the kitchen and beyond. I've seen other cat flap projects but they all seem to rely on sending data outside of the cat flap or building special boxes for cats to pass through.

I wanted to make something that was self contained, hence The Integrated Cat Flap.

The system is based around a stock Petsafe Staywell Deluxe Magnetic cat flap with a Pi Zero using Open CV 3.1.

A Pi Camera NoIR 2.1 points underneath the cats mouth alongside a dawn / dusk IR LED. When enough motion is detected, OpenCV takes a picture and if prey is detected in the cats mouth, a servo will lock the flap mechanism and fluffy can't come in.

I've had the flap in operation since September last year and now have over 500 photos of cat with prey.

The plan is to create an Open CV Haar Cascade from these images which Open CV will use to lock the flap.

Question is, is using a Haar Cascade the best option for recognition? Would LBP or HOG be better?

Thanks

BigJinge

Image
Image
Image
Image
Image

User avatar
Paul Webster
Posts: 812
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK
Contact: Twitter

Re: The Integrated Cat Flap : Pi Zero

Fri Jan 20, 2017 6:48 am

That is impressive - both your solution and the cat.
Presumably many of the 500 photos are of the cat with the same animal in its mouth as it makes repeated attempts to come in.
How long has it taken for the cat to realise what is going on and trying less frequently with same prey?

mattmiller
Posts: 2137
Joined: Thu Feb 05, 2015 11:25 pm

Re: The Integrated Cat Flap : Pi Zero

Fri Jan 20, 2017 7:39 am

Great idea but are all those pictures of cat with or without prey as they all look like no prey to me

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: The Integrated Cat Flap : Pi Zero

Fri Jan 20, 2017 8:40 am

Have you breached article 8 of the European Convention on Feline Rights?

Kitteh is allowed to bring presents home for the boss cat, that's what kittehs do. Can we have a daylight picture of the poor victim of your horrid torture?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

boyoh
Posts: 1352
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: The Integrated Cat Flap : Pi Zero

Fri Jan 20, 2017 10:14 am

What A CAT--RASTOPHEY.

Would you like a door sensor, stopping you bringing in a Mc Donalds Diet Coke & a Double Cheese Burger
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

BigJinge
Posts: 31
Joined: Sat Jul 09, 2016 12:23 pm

Re: The Integrated Cat Flap : Pi Zero

Fri Jan 20, 2017 2:07 pm

Paul Webster wrote:That is impressive - both your solution and the cat.
Presumably many of the 500 photos are of the cat with the same animal in its mouth as it makes repeated attempts to come in.
How long has it taken for the cat to realise what is going on and trying less frequently with same prey?
Thanks Paul.

We've had 14 mice (if memory serves, without checking the timestamps) since September, so about 35 photos of each different prey animal from different angles as she approaches, stands at the cat flap then comes in.

The flap is currently in observe and record mode at the moment. The library of prey pictures will be used to build an Open CV cascade which will allow it to detect future prey in an image and lock the flap.

How she'll react? She's not stupid, I'll think she'll catch on.

BigJinge
Posts: 31
Joined: Sat Jul 09, 2016 12:23 pm

Re: The Integrated Cat Flap : Pi Zero

Fri Jan 20, 2017 2:13 pm

mattmiller wrote:Great idea but are all those pictures of cat with or without prey as they all look like no prey to me
Those are pictures without prey just to show what the camera sees. I haven't posted any prey pictures because nature is rough and given this is an all age forum, don't want to disturb people with bulging mouse heads, multiple mouse legs etc.

I've found it interesting that the mouse leg and foot does have a similar profile so will be easier to identify than a block of back fur.

BigJinge
Posts: 31
Joined: Sat Jul 09, 2016 12:23 pm

Re: The Integrated Cat Flap : Pi Zero

Fri Jan 20, 2017 2:19 pm

DougieLawson wrote:Have you breached article 8 of the European Convention on Feline Rights?

Kitteh is allowed to bring presents home for the boss cat, that's what kittehs do. Can we have a daylight picture of the poor victim of your horrid torture?
Fluffy has a LOT of instinct to bring back presents for us bosses. We do though draw the line at butchery on the kitchen floor at 3am making even Hannibal Lecter blush...

BigJinge
Posts: 31
Joined: Sat Jul 09, 2016 12:23 pm

Re: The Integrated Cat Flap : Pi Zero

Fri Jan 20, 2017 2:22 pm

boyoh wrote:What A CAT--RASTOPHEY.

Would you like a door sensor, stopping you bringing in a Mc Donalds Diet Coke & a Double Cheese Burger
To be fair though, I'm not bringing in half eaten Burger King, dropping it in front of her and staring at her until she has to deal with it...

Toreoe
Posts: 1
Joined: Tue Aug 15, 2017 10:32 am

Re: The Integrated Cat Flap : Pi Zero

Tue Sep 05, 2017 1:08 pm

Nice project!

How is the cat flap prey detection coming along? Any results to share? I'd love to hear more about your experiences, as I am about to do more or less exactly the same myself.

I have a NoIR Raspberry camera mounted in a "tunnel extender" for a Sureflap cat door, but have been delayed because of our neighbour's cat regularly spraying the door. I fear that fluid would be unhealthy for the camera... (This problem seems to have been taken care of now by means of a surveillance camera, a Haar cascade trained on images of spraying cats and a cat flap that sprays back... http://orpetveit.no/filmer/catflapspray.mp4 ).

Plan is to mount the "tunnel extender" with camera this weekend and start collecting negatives and positives (mostly negatives, I hope...)

-Tore

Dimple
Posts: 1
Joined: Tue Mar 20, 2018 1:34 am

Re: The Integrated Cat Flap : Pi Zero

Tue Mar 20, 2018 1:36 am

Hi do you mind sharing your code for how you achieved the motion detection with your pi zero? Specifically how you got the pictures to be taken with a given amount of motion

BigJinge
Posts: 31
Joined: Sat Jul 09, 2016 12:23 pm

Re: The Integrated Cat Flap : Pi Zero

Thu Mar 22, 2018 4:07 am

Hi,

I've had to put the cat flap project on hold for the time being due to life commitments.

I have been collecting more mouse image grabs to increase the quality of the Open CV cascade. Hopefully the cascade trainer file will be useful for all people as an infrared mouse looks the same regardless of what type / breed of cats they have holding it.

There is an excellent Open CV cascade maker called Cascade Trainer GUI which really takes the slog out of training a cascade.

http://amin-ahmadi.com/cascade-trainer-gui/

Amin is very open to any suggestions that people might find.

My next goal is to rebuild the cascade file as above with more pictures and then to try it out live on the cat flap but if it is activated to note in a log rather than close the flap so I can check the photo it activated on to make sure it wasn't a false positive.

My ultimate goal is to upload all the build photos and code to a website so people can build one of their own.

The project is very much alive... just on hold. :)

User avatar
Paul Webster
Posts: 812
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK
Contact: Twitter

Re: The Integrated Cat Flap : Pi Zero

Fri Mar 23, 2018 8:03 am

Looking forward to seeing the photos from a few days after it starts enforcing the block showing the cat reversing in through the cat flap.

BigJinge
Posts: 31
Joined: Sat Jul 09, 2016 12:23 pm

Re: The Integrated Cat Flap : Pi Zero

Fri Mar 23, 2018 2:54 pm

I've never see her back in from the outside so this is a use case I didn't need to bake in...

Bakayoko14
Posts: 1
Joined: Fri Mar 30, 2018 5:13 pm

Re: The Integrated Cat Flap : Pi Zero

Fri Mar 30, 2018 5:24 pm

Hi,

I think this idea is amazing. The technology is beyond me to try something like this but good on you for it!

I had a thought yesterday for something like this hence the google search and finding this. What about a chip sensor cat flap that the cat would have to bite to open. The cat would ofcourse be unable to get through with prey in it's mouth?

Perhaps a biting part that has sensors on top and bottom for the top and bottom teeth.

The cat would need training initially but i wonder if mine is intelligent enough to remember he has to bite the part to get in?

What do you think?

BigJinge
Posts: 31
Joined: Sat Jul 09, 2016 12:23 pm

Re: The Integrated Cat Flap : Pi Zero

Sat Mar 31, 2018 4:17 pm

Hi,

I didn’t think about the biting sensor as the camera choice was moving forward. As I want to keep everything integrated I wouldn’t want to have a bite sensor sticking out from the door, plus the cat is older and it would be hard to teach now.

Saying that, there is nothing stopping a bite sensor being added should someone else want to do that. There are plenty of GPIO pins left.

CatDogHousehold
Posts: 1
Joined: Mon Jun 24, 2019 11:46 pm

Re: The Integrated Cat Flap : Pi Zero

Tue Jun 25, 2019 12:03 am

How's this coming along? I have a cat that consistently brings home "presents" then lets them loose in my house, still alive, meaning my Jack Russell then goes running around until he catches it - and eats it. I already have a pet door that reads chips, so only my dog and two cats can come in, but I would be more than happy to back someone who is actively trying to make a door that stays locked when a present is presented.....

BigJinge
Posts: 31
Joined: Sat Jul 09, 2016 12:23 pm

Re: The Integrated Cat Flap : Pi Zero

Tue Jun 25, 2019 7:56 pm

Well, the project has mostly been on hiatus due to other commitments.

There has been some progress. I was looking how to create the AI model given that the OpenCV cascade idea wasn't that accurate and didn't work out. I could have worked through Machine Learning with different engines such as Keras but given time is a luxury, I got an account with Google AutoML Vision. Much easier, nice GUI, just upload the images and label plus Google's comparison library is huge.

The AI model I've trained has taken images of just the cat, the cat with a mouse and the cat with a bird.

I've got just over 13k images of just the cat with nothing in it's mouth, 1200 of it with a mouse and 13 with a bird. Given 98% of the time, the cat brings in a mouse, not too worried about the small number of bird images.
AutoML.PNG
AutoML.PNG (222.81 KiB) Viewed 3061 times
The model is 100% accurate 95% of the time. That's good enough for me.

I've exported the model in Edge Tensorflow format from Google AutoML Vision and have tried to convert it over to the Movidius Neural Compute Stick format which will speed up the detection considerably.

The problem now is the Movidus compiler gives an error when trying to compile the graph file so I've raised it with the Movidius forum.

Once I've got the compiled graph file, the Python code to use it shouldn't take too long to do (hopes) and then the testing begins.

First of I won't activate the lock but will write a log file and image if prey is brought in and detected. If we're happy it's not false positiving, I'll activate the lock.

NickCats
Posts: 1
Joined: Thu Jun 27, 2019 11:53 am

Re: The Integrated Cat Flap : Pi Zero

Thu Jun 27, 2019 2:14 pm

Staywell Petsafe Electromagnetic cat door.jpg
Staywell Petsafe Electromagnetic cat door.jpg (150.81 KiB) Viewed 2969 times
Help! There is no magnetic or microchip reader cat door on the market that has a big enough door flap for my cat to fit through. (the small dog flaps have magnetic fobs are too big to hang on my cats collar.) So I am modifying a Staywell Pet Safe magnetic cat door #932 with a bigger custom made door. She is 19 years old and needs access to a quiet room and her prescription food. Can you tell me what's wrong with my Staywell (Petsafe) 932 Magnetic Cat Flap? After opening it up, I observed when the magnet is engaged, it pushes the latch down but the latch is not catching the lock mechanism. Am I missing a part that broke off that I am not noticing? Thanks for any desperately needed help.

BigJinge
Posts: 31
Joined: Sat Jul 09, 2016 12:23 pm

Re: The Integrated Cat Flap : Pi Zero

Fri Jun 28, 2019 12:15 am

Hi Nickcats,

It might be that a cat magnetic collar attachment can trigger the dog magnetic flap. They aren't coded. It's just a magnet. However as you've got the cat flap, I'll go from there.

Short answer

The flap looks fine but the locking mechanism works in reverse. The reason it won't lock when it's apart is the locking bar (1) isn't there to stop the latch mechanism (3) moving out of the way. Put the flap back together, the flap will lock. Use the magnet attachment and it will open.

Longer answer.

It's been a while since I first got the original cat flap and that I removed the magnetic pivot mechanism, but this is what I remember.

In the picture you've shown, the pivot is up inside the flap, down under the cat. The flap would be locked if it was together.

When the cat wearing the magnetic collar puts its head over the pivot mechanism, the pivot goes up under the cat and naturally down inside the cat flap. On the pivot is a bar (1) that with no cat present, sits between the latch mechanism in hole (2). The pivot being down means (1) moves down so it's not in hole (2) allowing the latch mechanism to move out of the way (3) when the cat opens the cat flap.

With the Integrated Cat Flap. I have removed the magnetic pivot mechanism and if the cat flap needs to be locked, a servo pushes a rod to stop the latch mechanism from moving out of the way.

If I've misunderstood something, forgive me and please describe further.

BSG
Pivot.PNG
Pivot.PNG (140.77 KiB) Viewed 2951 times

KevinSwansea
Posts: 17
Joined: Fri Jan 05, 2018 10:24 pm

Re: The Integrated Cat Flap : Pi Zero

Mon Jul 01, 2019 3:44 pm

It looks like something similar has been done by an Amazon engineer, just published on the BBC news site "Cat flap uses AI to punish pet's killer instincts".

According to the BBC they are happy linking to their stories so the link is: https://www.bbc.co.uk/news/technology-48825761

BigJinge
Posts: 31
Joined: Sat Jul 09, 2016 12:23 pm

Re: The Integrated Cat Flap : Pi Zero

Mon Jul 01, 2019 4:28 pm

Yes, I've just seen the Amazon engineers story.

I'm glad this has gotten publicity that you can use ML / AI to block out prey but his design is still with the lock on the outside of the cat flap where mine is designed from the get go to be an easy swap out with an existing cat flap as it has all the components inside it and doesn't annoy the missus having a load of kit next to it.

With regards to The Integrated Cat Flap, time has been the issue and I've been able to get a Google Coral USB Accelerator that will take my Google AutoML Vision trained model (which as the Google stats say it's 100% accurate, 95% of the time).

So the goal this week was to put the Accelerator into the cat flap and activate it.

I plan to make the design and code publicly available.

BigJinge
Posts: 31
Joined: Sat Jul 09, 2016 12:23 pm

Re: The Integrated Cat Flap : Pi Zero

Mon Jul 01, 2019 5:38 pm

One of the goals of the project is to make it easier so you don't have do deal with ML engines and models at a programming level.

You'll find that each location where the cat flap is positioned and cat are different. A ML model someone creates that recognises their cat(s) for say cat A with a white underside of the face and a dark nose may not work as accurately for a cat B with a white and dark patches under their face and a light nose.

So, each person who built The Integrated Cat Flap, if they have a cat with the same features as ours would likely get a similar recognition rate, if the cat is different a new model for that cat would need to be trained.

Hence I waited until Google, Microsoft and others came along with a GUI solution.

So you could either use my existing cat/prey model or create your own, I recommend Google AutoML Vision.

The flap has two modes.

1. Monitor - This looks for movement inside the flap and takes many images of the cat passing through the flap, regardless of what is in its mouth. You can then put the images with just the cat and the cat with different types of prey in different folders. Each folder is then uploaded to Google AutoML Vision where you label "this folder" to be images are cat, these are prey etc. You don't need to specifically draw a rectangle around each piece of prey. Once you generate the Edge model from the images, you download it onto the Rasp Pi and onto stage 2.

2. Protect - A piece of code constantly checks to see if there is movement in the cat flap. If there is, the ML prey model is checked to see if the cat is "alone" or has prey in it's mouth. If it does have prey the flap is locked before the cat can bring it in plus a speaker (still inside the flap) plays back a sample of a word that the cat knows to take the prey away.

I have no doubt that PetSafe or the like will team up with Google / Movidius (for the Myriad VPU ML processor) and create their own retail version ML catflap with built in cameras eventually.

BigJinge
Posts: 31
Joined: Sat Jul 09, 2016 12:23 pm

Re: The Integrated Cat Flap : Pi Zero

Tue Jul 02, 2019 5:12 pm

Coral USB Accelerator came today and have been running the exported cat flap Google AutoML Vision Edge TPU model on it.
Coral.PNG
Coral.PNG (67.59 KiB) Viewed 2589 times
Works fine.

Mouse in cat's mouth detection peaks around 96% , Cat by itself around 95%
MouseProb.PNG
MouseProb.PNG (1.28 KiB) Viewed 2589 times
Will add the Edge TPU Python code / libraries into the existing locking Python code and see how we get on...

Markii666
Posts: 1
Joined: Wed Jul 31, 2019 11:27 pm

Re: The Integrated Cat Flap : Pi Zero

Wed Jul 31, 2019 11:30 pm

I live in the UK and in 4 weeks cat has brought in 20 mice so far, alive are the worst as we have 20 min process locating and trapping them for removal.

Would be happy to pay for this system,

Mark

Return to “Automation, sensing and robotics”