IntruderDet —An Intruder Detection Bot for my Appartment

Detected Intruder surrounded by a bounding box — drawn by Hannah Schieber

I recently bought a new camera OAK-D Lite. OAK-D Lite is a small RGB-D camera. It includes neural models and everything else, which let the computer vision enthusiast heart grow. So as I have this thing, what should I do with it?

Why not build a telegram bot which sends me an image if a person is in my appartment? To implement this, a script combines MobileNet-SSD with a telegram bot. The network output is filtered for the class person. With this filter, our script only notifies the owner of the appartment if a person is detected.

Telegram Chat Bot

For the creation of a telegram, many blog posts exist. Therefore I recommend reading the one below and installing the telegram-bot according to this instruction:

The python-telegram-bot is distributed under a LGPLv3 license. Chose a nice name for your bot and maybe do a basic method like echo to test the bot. However, we will not interact with the bot, we just want to be notified in case an intruder is in our appartment. First, get familiar with the chatbot, this example is copied from python-telegram-bot. From the context variable, you can access the chat_id which is necessary for the next steps.

python-telegram-bot Hello World

With the python-telegram-bot you will receive your API token, denoted as TOKEN in the script below. Paste your token and the individual chat id into the script.

Initalize libaries and IDs

To initially notify the user that the script is running the user is notified via text message. The send_message(text) is for this purpose. However, other messages can be sent as text is just a variable that can be called with any string.

Even more important than this init method is the send_photo() method. This method sends the photo of the intruder to your telegram chat.

Bot Part

Intruder Detection

The initial part of our IntroderDet is working. Next, we will figure out how to get an image of an intruder. So now the OAK-D Lite SDK is used as well as the camera. OAK-D Lite already comes with great documentation and two repositories:

Due to that, I will not explain the code in detail. For GUI support I recommend using depthai repository instead of depthai-python (they both provide python code). If you first want to play around then depthai is useful due to the GUI. We will stick to depthai-python, as we only need the script part and it’s easier for python people without a GUI ;).

Install depthai-python and add it to your imports on top. Next, we mostly reuse the mobilenet-ssd implementation of depthai-python.

import of depthai

depthai-python provides an output via open-cv frames. We will get rid of this code and also remove the sync part otherwise we will never get an RGB image we could send.

We replace:

original source code

The sync part with:

adapted source code, removed sync part

Then we mainly replace the part where the camera output is evaluated to send an image to our chatbot. To not get constantly spamed, the threshold for sending a new image is set to one minute. This threshold can be adapted to whatever interval suits you.

our “magic”, sends the captured image with a person to the chatbot user

Ok so that’s all, let’s run it! I provide an example image, as I do not want to have a picture from me as an intruder on the internet :). Normally, the script above sends the currently captured image via the telegram-bot.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store