A compact C++ application that captures a live color stream from an Intel RealSense camera, performs simple motion detection, and records video clips when motion is detected.
- Real-time motion detection using frame differencing
- Records video clips on motion and stops after 5 s of no motion
- Splits recordings every 5 min to limit file size
- Automatically manages disk space by deleting oldest files when free space is low
- Optional work-hour exclusion (Mon–Fri, 09:00–17:00)
- Ubuntu or similar Linux distribution
- Intel RealSense SDK 2.0 (librealsense2)
- OpenCV 4.x
Install dependencies:
sudo apt update
sudo apt install build-essential libopencv-dev librealsense2-devgit clone <repo-url>
cd <repo-folder>
# Ensure pkg-config paths include librealsense2 and opencv4
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH
# Compile
g++ -std=c++11 motion_detect_stream.cpp -o motion_detect_stream \
$(pkg-config --cflags opencv4 realsense2) \
$(pkg-config --libs opencv4 realsense2)# Basic mode:
./motion_detect_stream
# Disable recording during work hours (Mon–Fri, 09:00–17:00):
./motion_detect_stream --disable-work-hoursRecorded videos are saved to surveillance_videos/ as motion_YYYYMMDD_HHMMSS.avi.