We have three cats. One of our cats occasionally poops outside the litter box. We had our suspicions, but we couldn't pin down who or why. Territorial issues? Finickiness about box hygiene? Sickness? Fear or surprise? What could we do to reduce the frequency of incidents?
We decided that a litter box webcam was an excellent first project for the Raspberry Pi computer that W- just bought. The Pi is a tiny, quiet, inexpensive Linux server. My webcam worked without hassles, and Motion was easy to set up for motion detection. We set it up to capture videos when the computer detected motion. I watched the videos and encoded the data, tracking which cat and which litter box. I figured that exploring this would be a good excuse to work with the Pi and learn a little more about computer vision.
2014-03-24 Litter Box Cam with Raspberry Pi #raspberry #cats
You might think that watching litter box videos would be boring and somewhat icky. It was surprisingly informative. I had no idea that Luke sniffed so many litter boxes before settling on one. Leia usually checked out one or two boxes before doing her thing, but if all the other boxes were used (even if one of them was used only by her), she sniffed everything and then circled around in indecision before finally pooping in the middle of the basement floor. (Watching her try everything made me feel somewhat better.) The two cats cover, but Neko never does. (Territorial dominance marker by the smallest cat?)
We collected a week of baseline data, which showed that box 1 was twice as popular as box 4 and 5. W- hypothesized that it was because box 4 and box 5 were near the furnace, and the strange noises from the furnace might startle the cats occasionally. Leia pooped outside the box twice, both times sniffing all the boxes before going in the middle.
We took to calling Leia our little data-generator.
2014-03-29 Litterbox analysis #quantified
Since the cats often left a little bit of extra food in their bowls and the vet had suggested they needed less food or more exercise, we decided to try reducing the amount of food we gave them. That change seems to be going well.
We also moved box 5 closer to box 1. That led to box 5 being much more popular than it used to be, which was a pleasant surprise. If Leia likes box 5 a lot more now that it's away from the furnace, maybe it'll be easier for her to find a clean box to poop in.
Preliminary cat litter box results
We set the camera up to capture 2 frames per second in order to save space. Watching it in real-time eventually lost its novelty, so I looked up how to speed up the AVIs.
for FILE in video-*.avi; do
if [ ! -f "fast-$FILE" ]; then
ffmpeg -i $FILE -vf "setpts=0.10*PTS" -r 30 fast-$FILE
fi
done
I also started looking into how to use SimpleCV for computer vision and image processing. I had a hard time getting SimpleCV set up in my Ubuntu virtual machine, but the Windows version worked fine after a lengthy install process on my computer. After much learning, I figured out how to identify changed areas, get the largest share over a certain area threshold, find the centroid of that shape, and plot it back on the image. The real challenge is figuring out some kind of visual output that makes sense to me when I look at it. The image below is a step in the right direction, but it's still not quite what I need.
The Raspberry Pi camera module arrived, so we swapped that in and eventually got everything working again after some SD/power-related grumbling.
It would be great if I could get Python to automatically figure out which cat is in the video, distinguishing between multiple cats and flagging it for manual review if the motion detection got confused. Even better if it can track the path that the cats take!
On the other hand, the speeded-up AVIs are now fast enough that the bottleneck isn't waiting for the video to play, it's me typing in the description of the path (since I track not only the litter box they use, but any other litter boxes they check along the way). Maybe this is fine.
While watching me encode data, W- said, “Isn't this something you can have your assistants do?” It's data entry, sure, but I feel embarrassed about assigning people to watch our cats poop. <laugh> Besides, I'm learning a lot from the encoding process. We'll probably treat it as a time-limited experiment.
Pretty cool! =) Next steps: Collect more data, try more experimental changes, learn more about image processing…
Anticipated questions/responses:
- That's so geeky. You're weird. Yup.
- You have too much time on your hands. I like spending my time learning things, and getting better at computer vision and data analysis will come in handy. =) Better than watching TV or reading forgettable things. (See also: Too much time on her hands)
- Just get a self-cleaning litter box. We got a Litter Robot because that was the best-reviewed of the self-cleaning litter boxes, but only Neko likes using it. We're not into fancy litter boxes that require cartridges or special litter. It's hard to tell if Leia will take to a new automated litter box, and returns/refunds for used litter boxes would be a bit weird. We can probably figure out something that works with our current setup, or maybe with an additional regular litter box. We still need to clean daily anyway, so it makes sense to try low-cost approaches first.
- How about tracking both input and output? Too much work at the moment, and not enough interest in the data. (Weigh the food bowls? Weigh the boxes? Distinguish between cats?)
- What about rigging up an automated water sprayer / Nerf gun to fire when cats poo outside the litter box? That will just make them poop outside the furnace room. It's much easier to clean the furnace room than the carpet, so if they're going to poop outside the litter box, that's as good a place as any. We don't want them to get any negative associations.