https://github.com/sensoranalyticsaus/ocd---opencv-motion-detector
OCD - Motion-activated recorder for RTSP and usb cameras
https://github.com/sensoranalyticsaus/ocd---opencv-motion-detector
camera computer-vision motion-detection python3 rtsp security-tools usb
Last synced: 5 months ago
JSON representation
OCD - Motion-activated recorder for RTSP and usb cameras
- Host: GitHub
- URL: https://github.com/sensoranalyticsaus/ocd---opencv-motion-detector
- Owner: SensorAnalyticsAus
- License: apache-2.0
- Created: 2022-11-28T10:14:24.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-11-16T02:10:53.000Z (7 months ago)
- Last Synced: 2025-11-16T03:22:41.950Z (7 months ago)
- Topics: camera, computer-vision, motion-detection, python3, rtsp, security-tools, usb
- Language: Python
- Homepage:
- Size: 269 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OCD Simple Motion Detection NVR
## About
OCD3 is a software network video recorder. Key features:
* low-light motion-detection,
* false-positive motion alert reduction,
* AI summation of daily events (kmeans folder).
It can use any basic computer as a personal cloud for saving and displaying motion-detected images, videos etc. Outputs can also be used in custom image searching programs e.g. making event summary videos, gathering event stats video analytics and much more.
Tested with Tapo, Sricam, PiCam, Hiseeu, and Macbook Pro cameras. The program is quite stable once started - can run for months uninterrupted. Once the program starts up, program parameters e.g. motion sensitivity and disk use can be tailored to meet the site requirements.
${\textsf{\color{red}NB}}$ :
Bash shell scripts in `kmeans/`folder are RaspberryPi OS/Linux specif. Also some files in it may require editing paths at the top. Using these scripts on MacOS bash will need some tweaking. Alternatively `train-km.py` and `predict-km.py` produce `ffnames.txt` containing full paths to images selected by KMeans over the user specified time window (`train-km.py` arg3 and arg4).
### Demo
* OCD2 night vision
## What's New (in reverse chronological order)
* Support for [KM-GEN](https://github.com/SensorAnalyticsAus/KM-GEN) added.
* Support for python virtual environment added.
* `sautils` updated to ver 3.2. A major bug in `kmeans` which restricted the use of image classification to OCD camera filename format has been relaxed. Now any filename which contains timestamp as YYYYMMDD-HHMMSS will generally work.
* Bug fixes.
* Version 3 has an updated motion detection scheme, which is more accurate and works better in low-light conditions.
* A heuristic to minimise excessive frame capture.
* `MD.log` for KMeans clustering.
* `images_cn/` for saving contoured b/w versions of motion-detected images. Handy to know what caused motion-detection and where it occurred.
* Option to increase motion-detection sensitivity after dark.
* Multiple cameras can be motion-detected with suitable mods to *cam??* filenames.
* `crtl3-cam01` can be used to control `driver3-cam01.py` with *start|stop|restart* arguments e.g. `crontab -e` with line, `@reboot /home/saauser/bin/ctrl-cam01 start`).
* A rpi4b with internal SSD ( argon one M2. enclosure) can support three camera streams quite easily.
* Version 1 has even less resource requirements and almost as good (most of my less-critical cameras still use it).
## Getting Started
### Prerequisites
* raspberry pi 4b or a debian linux/mac PC (windows with cygwin may work - not tested)
* python 3.6 or higher
* work-around for accessing a rtsp stream with udp transport only remotely, SensorAnalyticsAu/remote_rtsp
Remember to pip install numpy before installing opencv.
```
python -m pip install -U pip
python -m pip install -U scikit-image
pip install opencv-python
pip install shutils
pip install -U scikit-learn (for kmeans)
pip install matplotlib
sudo apt update
sudo apt upgrade
sudo apt install screen
sudo apt install ffmpeg
```
### Edit Settings
Edit `config3.py` file according to your requirements. If in doubt retain default values where appropriate.
Edit paths in the beginning of
```
ctrl3-cam01.sh
driver3-cam01.py
kmeans/predict-km.py
kmeans/daily-driver
moviefrm-list
moviefrm-list-ni
```
If using [KM-GEN](https://github.com/SensorAnalyticsAus/KM-GEN) for frame analysis (instead of `kmeans/`) then logging and gathering of additional b/w images can be turned off by setting `logg = 0` in `config3.py` as `KM-GEN` generates its own ml data for analysis.
## Running the code
```
./ctrl3-cam01.sh start
```
To stop:
```
./ctrl3-cam01.sh stop
```
To check on program
```
screen -r cam01
ctrl-a-d (to exit)
```
## Troubleshooting
Main reasons for program not working.
* A python dependency is missing.
* Program paths are not correctly specified.
* Incorrect camera url or camera is not working. Suggest testing camera url with VLC.
* Captured image filenames either have no timestamp or their timestamp format does not match YYYYMMDD-HHMMSS format.