Motion detection & video recording software based on OpenCV, built for research on Bumblebees

Overview

BombusCV

GitHub releases GitHub repo size GitHub open issues GitHub open pull requests GitHub sponsors Crates.io downloads Crates.io version Discord GitHub license

Motion detection & video recording software based on OpenCV, built for research on Bumblebees (hence the name).

Index

Use case

This software was built to meet the need of tracking, and/or recording clips of marked Bumblebee individuals in a scientific research project. It has been used with a Raspberry Pi 41 and a Raspberry Pi HQ Camera2 pointed at the entrance of a Bombus terrestris nest, in order to record clips of the entry/exit events, based on motion. This considerably reduced the storage space required for the recordings and completely removed the need of post processing work, since it was only recording clips in which individuals appeared in the video frame.

bombuscv-rs 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.

Examples

Below a brief example of the produced video output:

example.mp4

More examples can be found on YouTube.

Install

For installation on RaspberryPi check Install on RaspberryPi 4.

Requirements

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).

Using Cargo

A package is available at crates.io. In order to install it run cargo install bombuscv-rs in your shell.

Install on RaspberryPi 4

It is strongly recommended to use a RaspberryPi with at least 4GB of RAM. 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/marcoradocchia/bombuscv-rs/master/bombuscv-raspi.sh | sh

Usage

bombuscv-rs 0.2.0
Marco Radocchia 
OpenCV based motion detection/recording software built for research on bumblebees.

USAGE:
    bombuscv [OPTIONS]

OPTIONS:
    -d, --directory       Output video directory
    -f, --framerate       Video framerate
        --format             Output video filename format (see
                                     https://docs.rs/chrono/latest/chrono/format/strftime/index.html
                                     for valid specifiers)
    -h, --help                       Print help information
    -i, --index               /dev/video capture camera index
    -o, --overlay                    Enable Date&Time video overlay
    -q, --quiet                      Mute standard output
    -r, --resolution     Video resolution (standard 16:9 formats) [possible values:
                                     480p, 576p, 720p, 768p, 900p, 1080p, 1440p, 2160p]
    -v, --video 

Note that video option, which runs bombuscv with a pre-recorded video input, is incompatible with framerate, resolution 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 using ffprobe (ffmpeg tool), while the last makes no sense if used with a non-live video feed; same rules apply to CLI arguments.

Configuration

All options (except video) can be set in a optional configuration file stored at $XDG_CONFIG_HOME/bombuscv/config.toml by default or at any location in the filesystem specified by setting BOMBUSCV_CONFIG environment variable. CLI arguments/flags override options defined in the configuration file. Below listed an example configuration file:

# /dev/video camera input
index = 0
# input/output framerate (ignored if used with `video`)
framerate = 60.0
# input/output resolution (ignored if used with `video`)
# possible values (16:9 formats): 480p, 576p, 720p, 768p, 900p, 1080p, 1440p, 2160p
resolution = "720p"
# date&time video overlay (ignored if used with `video`)
overlay = true
# 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"

Changelog

Complete CHANGELOG.

ToDo

  • Provide build & install instructions in README, as well as the instructions to install OpenCV.
  • Make install script for automated installation on RaspberryPi.
  • Passing video or directory options in the configuration file using ~/ 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 using video option.
  • 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 main to newly defined run.

Chat Support

Join Discord server for installation or usage chat support:

Join our Discord server!

License

GPLv3

Footnotes

  1. 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

  2. 12.3 megapixel Sony IMX477 sensor

  3. Based on hardware

  4. RaspberryPi OS 64 bits required in order to install using the script

You might also like...
Gyroflow is an application that can stabilize your video by using motion data from a gyroscope and optionally an accelerometer
Gyroflow is an application that can stabilize your video by using motion data from a gyroscope and optionally an accelerometer

Gyroflow is an application that can stabilize your video by using motion data from a gyroscope and optionally an accelerometer. Modern cameras record that data internally (GoPro, Sony, Insta360 etc), and this application stabilizes the captured footage precisely by using them. It can also use gyro data from an external source (eg. from Betaflight blackbox).

Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

This is a lightweight audio-video player built in Rust using FFmpeg libraries. It demonstrates the usage of FFmpeg with Rust to play back video files.

FFmpeg Rust Video Player This is a lightweight audio-video player built in Rust using FFmpeg libraries. It demonstrates the usage of FFmpeg with Rust

A video player for your terminal that generates a standalone executable that plays your video.

Szmelc Player Szmelc Player is a program that converts any video you give it to a standalone executable that plays the video in the terminal. It uses

CLI for video images. Generates animated video contact sheets fast.

vimg CLI for video images. Generate animated video contact sheets fast. Uses ffmpeg. Note: Support for animated avif isn't everywhere yet, try viewing

A free and open-source DNA Sequencing/Visualization software for bioinformatics research.
A free and open-source DNA Sequencing/Visualization software for bioinformatics research.

DNArchery 🧬 A free and open-source cross-platform DNA Sequencing/Visualization Software for bioinformatics research. A toolkit for instantly performi

A discord.py experimental extension for audio recording

discord-ext-audiorec This project is currently under development. We do not guarantee it works.

Isolates Jibri pods from their Deployment when they start recording or livestreaming, and cleans them up when they finish.

jibri-pod-controller: A tool for managing the scaling of large Jibri deployments in Kubernetes. When managing a large Jibri deployment, you usually wa

High performance wlroots screen recording, featuring hardware encoding

wl-screenrec High performance wlroots based screen recorder. Uses dma-buf transfers to get surface, and uses the GPU to do both the pixel format conve

Rust bindings for OpenCV 3 & 4

Rust OpenCV bindings Experimental Rust bindings for OpenCV 3 and 4. The API is usable, but unstable and not very battle-tested; use at your own risk.

 Slideo: This tool uses OpenCV to automatically synchronize slides with videos that show these slides.
Slideo: This tool uses OpenCV to automatically synchronize slides with videos that show these slides.

This tool matches video frames against PDF pages by using computer vision. It also ships a web app in which you can click on a PDF page to play the video from the first frame showing the page. Its primary use-case is to quickly play a recorded lecture from a given slide.

A simple, efficient spring animation library for smooth, natural motion in Rust
A simple, efficient spring animation library for smooth, natural motion in Rust

Natura A simple, efficient spring animation library for smooth, natural motion in Rust Usage Natura is framework-agnostic and works well in 2D and 3D

OpenCV Sample Projects in Rust

OpenCV Sample Projects in Rust

Rust wrapper for the LeapC Ultraleap (Leap Motion) hand tracking device API.

LeapRS LeapRS is a safe wrapper for LeapC, the Leap Motion C API. It uses the generated binding provided by leap-sys. This is an API for accessing Lea

Just set of functions to utilize YOLO v3, v4, v7 and v8 version with OpenCV's DNN module

Object detection utilities in Rust programming language for YOLO-based neural networks in OpenCV ecosystem This crate provides some basic structures a

JLM: A research compiler based on the RVSDG IR

JLM: A research compiler based on the RVSDG IR Jlm is an experimental compiler/optimizer that consumes and produces LLVM IR. It uses the Regionalized

command line tools for coprolite research (paleontology and archaeology): estimate the producer's body mass based on coprolite diameter by the use of regression models
command line tools for coprolite research (paleontology and archaeology): estimate the producer's body mass based on coprolite diameter by the use of regression models

OVERVIEW OF COPROSIZE coprosize employs power, exponential and cubic regression models allowing to estimate the producer's body mass based on coprolit

An end-to-end encrypted, anonymous IP-hiding, decentralized, audio/video/file sharing/offline messaging multi-device platform built for both communications and application security and performance.

An end-to-end encrypted, anonymous IP-hiding, decentralized, audio/video/file sharing/offline messaging multi-device platform built for both communications and application security and performance.

Lumiere is a proof-of-concept/example video player built with the Slint UI framework and libmpv
Lumiere is a proof-of-concept/example video player built with the Slint UI framework and libmpv

Lumiere is a proof-of-concept/example video player built with the Slint UI framework and libmpv. This was built quickly to try out Slint and it's new OpenGL underlay feature.

Comments
  • Retrieve video metadata when using pre-recorded input

    Retrieve video metadata when using pre-recorded input

    Make bombuscv detect resolution and framerate from video file metadata when using pre-recorded input feed and use them in configuration parsing, ignoring values passed in the configuration file and rejecting values passed as CLI arguments.

    opened by marcoradocchia 2
  • Unable to compile on AArch64

    Unable to compile on AArch64

    Compilation passes on x86_64, but fails on AArch64 with error:

    error[E0308]: mismatched types
      --> /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/bombuscv-rs-0.1.0/src/lib.rs:96:48
       |
    96 |             Codec::MJPG => VideoWriter::fourcc('M' as i8, 'J' as i8, 'P' as i8, 'G' as i8).unwrap(),
       |                                                ^^^^^^^^^ expected `u8`, found `i8`
       |
    help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
       |
    96 |             Codec::MJPG => VideoWriter::fourcc(('M' as i8).try_into().unwrap(), 'J' as i8, 'P' as i8, 'G' as i8).unwrap(),
       |                                                +         +++++++++++++++++++++
    
    error[E0308]: mismatched types
      --> /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/bombuscv-rs-0.1.0/src/lib.rs:96:59
       |
    96 |             Codec::MJPG => VideoWriter::fourcc('M' as i8, 'J' as i8, 'P' as i8, 'G' as i8).unwrap(),
       |                                                           ^^^^^^^^^ expected `u8`, found `i8`
       |
    help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
       |
    96 |             Codec::MJPG => VideoWriter::fourcc('M' as i8, ('J' as i8).try_into().unwrap(), 'P' as i8, 'G' as i8).unwrap(),
       |                                                           +         +++++++++++++++++++++
    
    error[E0308]: mismatched types
      --> /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/bombuscv-rs-0.1.0/src/lib.rs:96:70
       |
    96 |             Codec::MJPG => VideoWriter::fourcc('M' as i8, 'J' as i8, 'P' as i8, 'G' as i8).unwrap(),
       |                                                                      ^^^^^^^^^ expected `u8`, found `i8`
       |
    help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
       |
    96 |             Codec::MJPG => VideoWriter::fourcc('M' as i8, 'J' as i8, ('P' as i8).try_into().unwrap(), 'G' as i8).unwrap(),
       |                                                                      +         +++++++++++++++++++++
    
    error[E0308]: mismatched types
      --> /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/bombuscv-rs-0.1.0/src/lib.rs:96:81
       |
    96 |             Codec::MJPG => VideoWriter::fourcc('M' as i8, 'J' as i8, 'P' as i8, 'G' as i8).unwrap(),
       |                                                                                 ^^^^^^^^^ expected `u8`, found `i8`
       |
    help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
       |
    96 |             Codec::MJPG => VideoWriter::fourcc('M' as i8, 'J' as i8, 'P' as i8, ('G' as i8).try_into().unwrap()).unwrap(),
       |                                                                                 +         +++++++++++++++++++++
    
    error[E0308]: mismatched types
      --> /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/bombuscv-rs-0.1.0/src/lib.rs:97:48
       |
    97 |             Codec::XVID => VideoWriter::fourcc('X' as i8, 'V' as i8, 'I' as i8, 'D' as i8).unwrap(),
       |                                                ^^^^^^^^^ expected `u8`, found `i8`
       |
    help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
       |
    97 |             Codec::XVID => VideoWriter::fourcc(('X' as i8).try_into().unwrap(), 'V' as i8, 'I' as i8, 'D' as i8).unwrap(),
       |                                                +         +++++++++++++++++++++
    
    error[E0308]: mismatched types
      --> /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/bombuscv-rs-0.1.0/src/lib.rs:97:59
       |
    97 |             Codec::XVID => VideoWriter::fourcc('X' as i8, 'V' as i8, 'I' as i8, 'D' as i8).unwrap(),
       |                                                           ^^^^^^^^^ expected `u8`, found `i8`
       |
    help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
       |
    97 |             Codec::XVID => VideoWriter::fourcc('X' as i8, ('V' as i8).try_into().unwrap(), 'I' as i8, 'D' as i8).unwrap(),
       |                                                           +         +++++++++++++++++++++
    
    error[E0308]: mismatched types
      --> /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/bombuscv-rs-0.1.0/src/lib.rs:97:70
       |
    97 |             Codec::XVID => VideoWriter::fourcc('X' as i8, 'V' as i8, 'I' as i8, 'D' as i8).unwrap(),
       |                                                                      ^^^^^^^^^ expected `u8`, found `i8`
       |
    help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
       |
    97 |             Codec::XVID => VideoWriter::fourcc('X' as i8, 'V' as i8, ('I' as i8).try_into().unwrap(), 'D' as i8).unwrap(),
       |                                                                      +         +++++++++++++++++++++
    
    error[E0308]: mismatched types
      --> /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/bombuscv-rs-0.1.0/src/lib.rs:97:81
       |
    97 |             Codec::XVID => VideoWriter::fourcc('X' as i8, 'V' as i8, 'I' as i8, 'D' as i8).unwrap(),
       |                                                                                 ^^^^^^^^^ expected `u8`, found `i8`
       |
    help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
       |
    97 |             Codec::XVID => VideoWriter::fourcc('X' as i8, 'V' as i8, 'I' as i8, ('D' as i8).try_into().unwrap()).unwrap(),
       |                                                                                 +         +++++++++++++++++++++
    
    error[E0308]: mismatched types
      --> /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/bombuscv-rs-0.1.0/src/lib.rs:98:48
       |
    98 |             Codec::MP4V => VideoWriter::fourcc('m' as i8, 'p' as i8, '4' as i8, 'v' as i8).unwrap(),
       |                                                ^^^^^^^^^ expected `u8`, found `i8`
       |
    help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
       |
    98 |             Codec::MP4V => VideoWriter::fourcc(('m' as i8).try_into().unwrap(), 'p' as i8, '4' as i8, 'v' as i8).unwrap(),
       |                                                +         +++++++++++++++++++++
    
    error[E0308]: mismatched types
      --> /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/bombuscv-rs-0.1.0/src/lib.rs:98:59
       |
    98 |             Codec::MP4V => VideoWriter::fourcc('m' as i8, 'p' as i8, '4' as i8, 'v' as i8).unwrap(),
       |                                                           ^^^^^^^^^ expected `u8`, found `i8`
       |
    help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
       |
    98 |             Codec::MP4V => VideoWriter::fourcc('m' as i8, ('p' as i8).try_into().unwrap(), '4' as i8, 'v' as i8).unwrap(),
       |                                                           +         +++++++++++++++++++++
    
    error[E0308]: mismatched types
      --> /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/bombuscv-rs-0.1.0/src/lib.rs:98:70
       |
    98 |             Codec::MP4V => VideoWriter::fourcc('m' as i8, 'p' as i8, '4' as i8, 'v' as i8).unwrap(),
       |                                                                      ^^^^^^^^^ expected `u8`, found `i8`
       |
    help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
       |
    98 |             Codec::MP4V => VideoWriter::fourcc('m' as i8, 'p' as i8, ('4' as i8).try_into().unwrap(), 'v' as i8).unwrap(),
       |                                                                      +         +++++++++++++++++++++
    
    error[E0308]: mismatched types
      --> /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/bombuscv-rs-0.1.0/src/lib.rs:98:81
       |
    98 |             Codec::MP4V => VideoWriter::fourcc('m' as i8, 'p' as i8, '4' as i8, 'v' as i8).unwrap(),
       |                                                                                 ^^^^^^^^^ expected `u8`, found `i8`
       |
    help: you can convert an `i8` to a `u8` and panic if the converted value doesn't fit
       |
    98 |             Codec::MP4V => VideoWriter::fourcc('m' as i8, 'p' as i8, '4' as i8, ('v' as i8).try_into().unwrap()).unwrap(),
       |                                                                                 +         +++++++++++++++++++++
    

    so basically on every call to VideoWriter::fourcc().

    Issue discussed here: twistedfall/opencv-rust#292.

    opened by marcoradocchia 1
Releases(v0.3.0)
  • v0.3.0(Jun 28, 2022)

    Added

    • Colored output with no-color CLI option to disable it.

    Fixed

    • Bug in motion detection preventing it from working as expected.

    Changed

    • Moved resolution option to width & height options in both configuration file and CLI arguments: now custom resolution (and aspect ratio) and framerate can be specified and bobmuscv will adapt those to the closest combination of resolution and framerate the capture device provides.

    Removed

    • Dependency ffprobe: pre-recorded video resolution and framerate, required to construct the VideoWriter, are now obtained using OpenCV's VideoCapture getters methods.
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Jun 14, 2022)

    Changed

    • Updated bombuscv-raspi.sh script to install OpenCV v4.6.0.

    Fixed

    • Issue marcoradocchia/bombuscv-rs#1 which prevented bombuscv to autodetect video framerate and resolution on video CLI option used.

    Removed

    • Option to specify video in the configuration file in favor of passing video file via CLI argument.
    • Dependency validator: moved config file options validation to serde.
    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Jun 11, 2022)

Owner
Marco Radocchia
I'm a physics student with real enthusiasm in computers and free and open source software.
Marco Radocchia
Slideo: This tool uses OpenCV to automatically synchronize slides with videos that show these slides.

This tool matches video frames against PDF pages by using computer vision. It also ships a web app in which you can click on a PDF page to play the video from the first frame showing the page. Its primary use-case is to quickly play a recorded lecture from a given slide.

Henning Dieterichs 78 Oct 7, 2022
OpenCV Sample Projects in Rust

OpenCV Sample Projects in Rust

iwatake 9 Jan 28, 2022
Just set of functions to utilize YOLO v3, v4, v7 and v8 version with OpenCV's DNN module

Object detection utilities in Rust programming language for YOLO-based neural networks in OpenCV ecosystem This crate provides some basic structures a

Dimitrii Lopanov 3 Nov 17, 2023
Face detection library for the Rust programming language

Rustface SeetaFace detection library for the Rust programming language Example of demo program output SEETAFACE C++ – Github repository for the origin

Andrei Tomashpolskiy 323 Dec 27, 2022
😱 Dead fast thumbnail library for browser and NodeJs! Built with Rust 🦀 and WebAssembly 🕸

thumbo-core ?? Dead fast thumbnail library for browser and NodeJs Built with Rust ?? & WebAssembly ?? ?? About thumbo-core is a thubnail library for b

Victor Aremu 12 Dec 2, 2022
🎨 Example-based texture synthesis written in Rust 🦀

?? texture-synthesis A light Rust API for Multiresolution Stochastic Texture Synthesis [1], a non-parametric example-based algorithm for image generat

Embark 1.7k Dec 31, 2022
An SVG toolkit based on resvg

rusty-svg An SVG toolkit based on resvg This module is compiled to WASM and currently only supports Node.js Comparing with the backend ReSVG, this mod

Zimon Dai 9 Mar 21, 2022
Signed distance field font and image command line tool based on OpenCL.

SDFTool Signed distance field font and image command line tool based on OpenCL. Build Windows Run cargo build --release in Visual Studio developer x64

弦语蝶梦 7 Oct 16, 2022
Rust based breadth first search maze image solver

maze_solver Rust based breadth first search maze image solver Works on black and white images with provided start and end points. Usage: maze_solver

null 0 Jan 31, 2022
Motion graphics creation tool in Bevy. (Highly inspired by Motion Canvas and Manim)

Bevy MotionGfx Bevy Motiongfx is a motion graphics creation tool in Bevy. It is highly inspired by Motion Canvas & Manim. Goal The goal of this tool i

Nixon 3 Nov 6, 2023