Technology

A TP-Link Tapo C320WS1 is used as a webcam. The images are read out on a Raspberry Pi via RTSP and processed with FFMPEG2. After that ImageMagick3 is used for post-processing before the images are uploaded to the server via rsync4.

The decision of the Tapo camera was made because I already use another camera from the manufacturer. The camera can be operated without a cloud service and the RTSP stream makes it possible to use the image material for my own purposes without much effort.

Bash script for processing

Image processing is done directly under Linux with a bash script.

#!/bin/bash

webcam=<WebCamm IP>
user=<WebCam Benutzer>
password=<passwort>
picture=/tmp/webcam$RANDOM.jpg
wc_pfad=/opt/webcam

rsync_user=<rsync Benutzer>
rsync_host=<rsync Host>
rsync_dir=<remote rsync-Pfad>

# aktuelle Stunde ermitteln
hour=$(date +%H)
if [ hour == 00 ];
then
        hour=24
fi

$(whereis bin | ffmpeg -y -i rtsp://$user:$password@$webcam:554/stream1 -vframes 1 -loglevel quiet $picture)

# Bildatei vorhanden
if [ -f $picture ];
then
        # aktuelles Bild
        mv $picture $wc_pfad/images/latest.jpg

        # Archivbild
        if [ ! -f $wc_pfad/images/archiv/$hour.jpg ] || [ $(($(date +%s) - $(date -r $wc_pfad/images/archiv/$hour.jpg +%s))) -gt 3600 ];
        then
                cp $wc_pfad/images/latest.jpg $wc_pfad/images/archiv/$hour.jpg
        fi

        # Sync auf Server
        rsync -avzz --delete $wc_pfad/images/ ${rsync_user}@${rsync_host}:~/${rsync_dir} > /dev/null
fi

The target directory (wc_path) is the directory in which the images are stored and which is synchronised to the webserver. In this directory there is also a directory archive for the 24-hour archive.

I run the script via cron every five minutes. The archive is filled with an image once an hour and the running image every five minutes.

Blur areas

If you still want to pixelate areas (e.g. for data protection reasons), you can use ImageMagick for this. Before moving the current image, one or more command lines of the following type can be inserted:

$(whereis bin | convert $picture \( -clone 0 -fill white -colorize 100 -fill black -draw "polygon x1,y1 x2,y2 x3,y3 x4,y4 x5,x5" -alpha off -write mpr:mask +delete \) -mask mpr:mask -blur 200,100 +mask $picture_neu.jpg)
        mv $picture_neu.jpg $picture

The x,y pairs must be changed here with the corresponding X and Y coordinates in the image.

Camera - Tapo C320WS

The camera is a relatively inexpensive but solid WLAN security camera for outdoor use. It can be used without a cloud (except for configuration) and because it meets the IP66 standard, it is not affected by weather conditions. However, this only applies to the camera. The power supply unit is an indoor PSU and must be operated accordingly! TP-Link should improve this.

The security functions are of no interest to me in this case. I don’t need motion detection etc. However, I assume that they work. I have already had experience with other Tapo cameras that I use. The decision for this camera was also made because it fits into the existing infrastructure.

What is interesting, however, is the access via RTSP and the MPEG4 video format used. This offers a wide range of possibilities for individual further processing.

Roofs visible?

One question that has already come up is why the roofs are visible and not also obscured. The background is simple: roofs are a good indicator of whether there has been ripening or frost. It is therefore a good indication of what the weather is like without having to interfere with privacy.