Motion detection & video recording software based on OpenCV. This project was created as an extension of the BombusCV project authored by Marco Radocchia in attempt to create a more generic motion detection software and for educational purpose.
The following changes were made to the original project:
- Added support for video streaming
- Added support for Slack alerting
- OpenCV version updated to 4.9.0
More advanced alerting and support for other popular messengers will be added in the future.
As a separate note want to thank the original author of the project Marco Radocchia. This thing works great, and I really enjoyed the code he wrote! Hope to give the project some love.
I decided to add video streaming and alerting to the original project to be able to use it as a general purpose motion detector. And of course to learn Rust and have fun!. It has been used with a Raspberry Pi 41 and a Raspberry Pi HQ Camera2
rustymode offers realtime motion detection & video recording3 using
camera input and can be directly used on fieldwork. However, using the video
option, live camera input can be replaced with a pre-recorded video file: this
is useful to remove dead moments from videos and reduce/remove the need of
manual video trimming. Video stream can be viewed using a web browser.
Slack alerting can be configured to receive notifications when motion is
detected.
For installation on RaspberryPi check Install on RaspberryPi 4.
This program requires a working installation of OpenCV (>=4.5.5).
Building OpenCV from source is recommended (if you're going to build OpenCV
from source make sure to also install OpenCV dependencies), although it should
work with precompiled packages in your distro's repositories (it has been
tested with success on ArchLinux with the extra/opencv package).
It is strongly recommended to use a RaspberryPi 4 with at least 4GB of RAM.
Also, before trying to install, please enable Legacy Camera support under
Interface options running raspi-config and reboot. Since installation on a
RaspberryPi may be a little bit tricky, an installation script is
provided4. It takes care of updating & preparing the system, compiling
OpenCV and installing Rustup and finally BombusCV. You can run the
instllation script using curl:
curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/s0b01ev/rustymode/master/rustymode-raspi.sh | shrustymode 0.3.0
Dmitry Sobolev <sobolev@gmail.com>, originally by Marco Radocchia <marco.radocchia@outlook.com>
Fork of BombusCV: OpenCV-based motion detection/recording software for insect research.
USAGE:
rustymode [OPTIONS]
OPTIONS:
-d, --directory <DIRECTORY> Output video directory
-f, --framerate <FRAMERATE> Video capture framerate
--format <FORMAT> Output video filename format (see
<https://docs.rs/chrono/latest/chrono/format/strftime/index.html>
for valid specifiers)
-h, --help Print help information
-H, --height <HEIGHT> Video capture frame height
-i, --index <INDEX> /dev/video<INDEX> capture camera index
--no-color Disable colored output
-o, --overlay Date&Time video overlay
-q, --quiet Mute standard output
-v, --video <VIDEO> Video file as input
-V, --version Print version information
-W, --width <WIDTH> Video capture frame width
Specifying width, height & framerate will make bombuscv probe the
capture device for the closest combination of values it can provide and select
them. In other words: if you required valid options, they will be used,
otherwhise rustymode will adapt those to the closest available combination5.
Note that video option, which runs rustymode with a pre-recorded video
input, is incompatible with framerate, width, height and overlay. Also,
if these options are specified in the configuration file, they are going to be
ignored. This because the first two are auto-detected from the input file while
the last makes no sense if used with a non-live video feed; same rules apply to
CLI arguments.
All CLI options (except video and no-color) can be set in a optional configuration file
stored at $XDG_CONFIG_HOME/rustymode/config.toml by default or at any other
location in the filesystem specified by setting RUSTYMODE_CONFIG environment
variable. CLI options/arguments/flags override those defined in the
configuration file. Below listed an example configuration file:
# be quiet (mute stdout)
quiet = false
# output video directory
directory = "~/output_directory/"
# output video filename format (see
# https://docs.rs/chrono/latest/chrono/format/strftime/index.html for valid specifiers)
format = "%Y-%m-%dT%H:%M:%S"
# The following options are ignored if bombuscv is run with `--video` option
# /dev/video<index> camera input
index = 0
# video capture frame width
width = 640
# video capture frame height
height = 480
# video capture framerate
framerate = 30
# date&time video overlay
overlay = true
# date&time video overlay border
overlay_border = 2
# Slack web hook URL
slack_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
# Slack channel
slack_channel = "#cam"
# Slack user
slack_user = "detector"
# Streamer listener
streamer_listener = "0.0.0.0:8740"
# Streamer encoder image type
streamer_image_encode = ".jpg"Complete CHANGELOG.
- Provide build & install instructions in README, as well as the instructions to install OpenCV.
- Make install script for automated installation on RaspberryPi.
- Passing
videoordirectoryoptions in the configuration file using~/<path>results in an error: in the Deserialize expanding~to absolute path is required. - Using
video, date&time overlay generated on frame grabbed makes no sense: disable video overlay while usingvideooption. - Add option to specify custom config path using env variables.
- Add option to specify (in config file or via CLI argument) a custom output video filename formatter (must be chrono DateTime syntax).
- Add thread signalling to interrupt grabber thread and gracefully terminate the execution.
- Move logic from
mainto newly definedrun.
Footnotes
-
4GB of RAM memory, powered by a 30000mAh battery power supply, which means this setup can be also reproduced in locations where no AC is available ↩
-
12.3 megapixel Sony IMX477 sensor ↩
-
Based on hardware (RasberryPi 4 at the moment of writing can handle 640x480 resolution at 60fps) ↩
-
RaspberryPi OS 64 bits required in order to install using the script ↩
-
Same rules apply to configuration file ↩