The Simple Solution: When a Computer Vision Occupancy System Is Beaten by a Simple Reed Switch
Andrew Moses has moved away from AI, even as the industry booms, to provide a University of Wisconsin lab with a simpler occupancy option.
Developer Andrew Moses has been working on upgrading a lab occupancy system that started life as a webcam in the 1990s — and, despite having a computer vision system with person detection to hand, found that sometimes the simplest solutions are the best.
"For almost as long as the Undergraduate Projects Lab at the University of Wisconsin has existed, there’s been a camera of some sort peering at the room," Moses explains. "There’s evidence of a system existing even as far back as the 1990s, with a prehistoric revision of the site mentioning that an old iteration was: '…a $15 video camera attached to the wall with duct tape, connected to a VCR, connected to a video spigot in a Mac IIcx, running Timed Video Grabber (TVG), and FTPd. Dax, an HP workstation ran a script that would try to FTP the latest image every 60 seconds."
Now, nearly 30 years later, there's still a camera pointing at the lab's denizens — only these days it's a lot smarter. Initially developed by Michael Berkey using a Logitech C920 webcam, the new system puts Python and machine learning to work to classify people and provide a live count of the lab's occupancy. After counting the number of people using the YOLOv7 model, the script updates a Discord channel — though sometimes has a problem with telling the difference between a person and an unoccupied chair.
As with its 1990s equivalent, the camera system is more than just a toy: it's designed to help users of the lab know whether it's open or not. There's a problem, though: while sometimes the lab may have occupants, that doesn't always mean it's open — a private meeting would show up as an occupied lab but not provide a visitor with access, much to their dismay.
"It was around this time that I stumbled upon the homepage of MITERS, a makerspace at MIT," Moses explains. "On their website, they broadcast whether the door to the space is open using a reed switch attached to a Raspberry Pi. Reed switches are small, physical components that are able to detect a magnetic field. If you put one on a doorframe, and then attach a tiny magnet to the door itself, you have an effective way of detecting whether a door is open or closed!"
It's a much simpler solution than a computer vision model capable of telling the difference between people and chairs, but it's also much more robust: if the door is open for anything other than a brief period, then the lab is open; if it's closed, then the lab is shut. Using an off-the-shelf Zigbee magnetic door sensor and a compatible radio connected to a Raspberry Pi, Moses was finally able to solve the problem — updating a Home Assistant installation and informing potential users of the lab's status via Discord.
The full project write-up is available on Moses' website.
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.