D.I.Wyze Person Detection: Part 1

Robert Reed
The Startup
Published in
5 min readDec 12, 2019

--

Building a smart security system with Python, a Wyze cam, and some ingenuity.

Illustration by Emans

Part 1: Taking Control

Over the past year my home has become increasingly intelligent. Smart bulbs illuminate as I enter rooms and darken as I leave. Door sensors gossip to WiFi outlets so my dogs can see at night. Even my Christmas tree bends to my whims, LEDs dancing in quiet obedience.

But for all the fun and countless hours spent making my home smarter — resulting in a cumulative savings of tens of seconds, but who wants to get out of bed to turn off the lights? — one connected device I had yet to purchase was a security camera. I simply couldn’t justify spending $200+ on a device I really didn’t need. That would remain the case to this day if not for a fatefully clogged bathtub drain.

As I wandered the aisles of Home Depot, absorbing the expanse of items while looking for a drain snake, I was suddenly presented with an opportunity. Stacked before me in a delicate tower was a collection of smart devices — bulbs, outlets, sensors, and cameras — for ridiculously low prices. While my fiancée patiently browsed holiday decorations, I frantically Googled this new-to-me manufacturer, Wyze.

To my delight, the cameras seemed revered, and boasted a suite of intelligent features — 1080p HD video, night vision, motion detection, and even person detection. For $25 I was sold (literally) and shortly thereafter I had the camera set up on my front porch. Within minutes my camera began alerting me to every car driving by, every bug flying past, and every tree blowing gently in the wind.

A low resolution GIF of the view of a street from a porch with a bunch of cars driving past.
Yes, most of my plants are dead.

While it was slightly entertaining to see the sheer number and variety of cars that drove down my street, the constant notifications quickly outgrew their novelty. After all, my primary goal with this new camera was to detect package deliveries, not cars. Thankfully, Wyze provides a number of options to limit the onslaught of notifications. You can lower the sensitivity of the motion detector and limit the size of the “Detection Zone”. What’s more, the Wyze Cam even supports on-device person detection, allowing you to filter between people and other types of motion.

However, a problem arises when motion is detected before a person is in the frame. There is a five minute delay between notifications, so it is quite possible to detect motion and miss a person entirely. On top of that, a few days after getting my camera I received an email from Wyze informing me that their partnership with xnor.ai was ending, and that they would be removing person detection from their next firmware update. To their credit, they were extremely apologetic and promised to remedy the situation (from their own wallets if necessary) as quickly as possible.

Although their apology seemed genuine, I now own multiple cameras that can’t immediately serve their intended purpose. So, what do we do when something off the shelf doesn’t quite suit our needs? Take matters into our own hands and build it ourselves!

Enabling RTSP

To build our own person detector, we’ll first need access to the video feed. One of the less obvious features of the Wyze Cam is the ability to enable Real Time Streaming Protocol (RTSP). Doing so allows you to stream live footage directly to devices on your home network. Turning on RTSP is not as simple as flipping a switch, but Wyze has made the process fairly straightforward. They developed an alternative firmware that allows you to enable RTSP, conveniently exposing new options in the app.

The process is well documented, and the only additional hardware requirement is a microSD card. To prep the card, simply download the RTSP firmware (Wyze Cam V2/Wyze Cam Pan), unzip the archive, and save it to the card’s root as “demo.bin”. With the card prepped, insert it into the slot located on the bottom of the camera, hold the setup button while powering on the device, and you should be good to go…

…or so the documentation would lead you to believe. Unfortunately, that wasn’t my experience. After failing to flash the firmware multiple times, I stumbled onto the Wyze blog where folks were murmuring about similar problems. Some alleged that flashing the alternate firmware had been blocked in the latest regular firmware release. This may or may not have been the case (folks have since speculated that it was perhaps an issue with the microSD card and not the firmware), but it inspired me to try downgrading to a previous firmware (I loaded V4.9.4.169 without problem), and then flashing the RTSP firmware, which worked on the first try.

Accessing the Stream

Once the firmware is flashed and the camera reboots, enable RTSP through the app by accessing Settings > Advanced Settings > RTSP. After enabling the stream, generate the url to access it. It should be of the following form:

rtsp://<camera_name>:<some_uuid>@<some_ip>/live

The simplest way to view the stream (IMO) is with VLC Player. You can do so by going to File > Open Network… and pasting the link generated by the Wyze app. You should now be seeing a real-time feed from your camera. You will find that it is a few seconds delayed, but other than that it should work well.

But our goal is to build a person detector, and to do so we need programmatic access to the stream. In this instance, as in many others, Python is our friend.

Viewing the Stream with Python

To access the stream, we will be using OpenCV and a helper library called imutils. Although it’s not required, I would recommend you begin by creating a virtual environment (whichever type you fancy) for the project. With the environment set, install the dependencies:

pip install opencv-python imutils

With the level of abstraction these two libraries provide, remarkably few lines of code are required to view the stream:

rtsp_stream.py
Wyze Cam live stream over RTSP with Python.
Low image quality due to poor GIFing

With access to the raw frames in Python, we can now work towards building a person detection system that better suits our needs. In my next post in this series, I’ll show how we can do that and more. Keep an eye out for it later this month!

By the end of this series, we will have built a robust home security system capable of detecting people, saving videos, sending notifications, and uploading footage to the cloud — all running on a TPU accelerated RaspberryPi 4! Stay tuned!

If you’d like to get a jump-start on implementing the person detection, take a look at this excellent blog post which covers the topic in depth.

--

--

Robert Reed
The Startup

Teacher, software developer, hardware hacker. Interested in learning to do things myself.