A Simple Security Camera with Motion Detection implemented with Python3, Termux:API, OpenCV and rsync
- Takes photoes using the phone's built-in (rear or front) camera and LED flash light.
- Detects if there's any difference between two picture frames and save them selectively.
- Upload the photoes to any device capable of running SSH and SFTP server (and with enough storage space).
- Add timestamp mark to the photoes. (Now timestamp is in the filename only.)
- Support timing with RTC (For example, remove the photoes from remote computer monthly.)
- ... ...
-
Android 12 or 13 tends to kill this script because of too many phantom processes, here is the fix: https://termux.xyz/how-to-fix-termux-error-process-completed-signal-9-press-enter/
-
An Android Phone (better with root privilege)
-
Install Termux and Termux:API from F-Droid or GitHub (optional: Termux:Boot, SmartPack Kernel Manager)
-
In Termux run:
pkg install openssh python3 opencv-python rsync libjpeg-turbo libtiff termux-api
-
Generate an SSH key of your phone(with
ssh-keygen
) then upload the pubkey to remote server (file:~/.ssh/authorized_keys
) -
ssh
connect your phone to the desired remote server once (forknown_hosts yes
) -
(Optional) Set the CPU governor to "performance" (in "SmartPack Kernel Manager" or other similar Apps), add this script to Termux:Boot
-
Upload this script to Termux home directory (using
ssh
or anything else you like) -
Make this script executable:
chmod +x motioncam.py
It is pretty much self-explained.
./motioncam.py [-l --light] [-r --rsync] [-m --motion] [-c --count=x]
--light
: Enable Camera LED Flash Light.--rsync
: Enable Incremental Sync (rsync).--motion
: Enable Motion Detection.--count=x
: Auto Sync Frequency (Upload Per (x) Valid Shots)