Speed-cam.py ver 11.26 and greater will now run under Raspberry Pi OS Bullseye or later with a pi camera module as well as usbcam and IP/RTSP cameras. For picamera support Run sudo raspi-config, Interface Options, then enable/disable Legacy Camera option and reboot.
IMPORTANT - A raspbian sudo apt-get update and sudo apt-get upgrade will NOT be performed as part of
speed-install.sh so it is highly recommended you run these prior to install
to ensure your system is up-to-date.
Press GitHub copy icon on right side of code box below.
or With mouse left button highlight curl command in code box below. Right click mouse in highlighted area and select Copy.
curl -L https://raw.github.com/pageauc/speed-camera/master/speed-install.sh | bash
On RPI putty SSH or terminal session right click, select paste then Enter to download and run script.
This will download and run the speed-install.sh script. If running under python3 you will need opencv3 installed if not installed. If you need to compile openCV see my Github Repo at menu driven compile opencv3 from source project
Version 13.05 is a major speed camera revision. Camera thread code is now handled by a strmcam.py module.
config.py variable names have changed so you will need to backup and cp config.py.new config.py (see below for details)
IMPORTANT : All settings are in config.py. You can delete configcam.py if it exists, once you upgrade to ver 13.05 or greater.
plugins now work. You can customize plugin files to suit you needs or create your own. If you are upgrading you should delete, move
old plugins so new ones will be downloaded during UPGRADE. Please post GitHub issue if you find a bug or problem. Claude
IMPORTANT speed-cam.py ver 8.x or greater Requires Updated config.py and plugins.
cd ~/speed-camera
cp config.py config.py.bak
cp config.py.new config.py
To replace plugins rename (or delete) plugins folder per below
cd ~/speed-camera
mv plugins pluginsold # renames plugins folder
rm -r plugins # deletes plugins folder
Then run menubox.sh UPGRADE menu pick.
See Windows 10/11 or Apple Mac Docker Install Quick Start
or Windows or Unix Distro Installs without Docker
This is a raspberry pi, Windows, Unix Distro computer openCV object speed camera demo program. It is written in python and uses openCV to detect and track the x,y coordinates of the largest moving object in the camera view above a minimum pixel area.
User variables are stored in the config.py file. Motion detection is restricted between MO_CROP_Y_UPPER, MO_CROP_Y_LOWER, MO_CROP_X_LEFT, MO_CROP_X_RIGHT variables (road or area of interest). MO_CROP_AUTO_ON = True overrides manual settings and will Auto calculate a rough crop area based on image size. Motion Tracking is controlled by the MO_TRACK_EVENT_COUNT variable in config.py. This sets the number of track events and the track length in pixels. This may need to be tuned for camera view, cpu speed, etc. Speed is calculated based on CAL_OBJPX and CAL_OBJMM variables for L2R and R2L motion direction. A video stream frame image will be captured and saved in media/images dated subfolders (optional) per variable IM_SUBDIR_MAX_FILES = 2000 For variable settings details see config.py file.
If LOG_DATA_TO_CSV = True then a speed-cam.csv file will be created/updated with event data stored in CSV (Comma Separated Values) format. This can be imported into a spreadsheet, database, Etc program for further processing. Release 8.9 adds a sqlite3 database to store speed data. Default is data/speed_cam.db with data in the speed table. Database setting can be managed from config.py. Database is automatically created from config.py settings. For more details see How to Manage Sqlite3 Database
Raspberry Pi computer and a RPI camera module installed
or USB Camera plugged in. Make sure hardware is tested and works. Most RPI models will work OK.
A quad core RPI will greatly improve performance due to threading. A recent version of
Raspbian operating system is Recommended.
or
MS Windows or Unix distro computer with a USB Web Camera plugged in and a
recent version of python installed
For Details See Wiki details.
It is recommended you upgrade to OpenCV version 3.x.x For Easy compile of opencv 3.4.2 from source See https://github.com/pageauc/opencv3-setup
For Windows or Unix computer platforms (non RPI or Debian) ensure you have the most up-to-date python version. For Download and Install python and Opencv
The latest python versions includes numpy and recent opencv version that is required to run this code. You will also need a USB web cam installed and working. To install this program access the GitHub project page at https://github.com/pageauc/speed-camera Select the green Clone or download button. The files will be cloned or zipped to a speed-camera folder. You can run the code from python IDLE application (recommended), GUI desktop or command prompt terminal window. Note bash .sh shell scripts will not work with windows unless special support for bash is installed for windows Eg http://win-bash.sourceforge.net/ http://www.cygwin.com/ Note: I have Not tested these.
speed camera supports a docker installation on
Apple Macintosh per System requirements and Instructions
and
Microsoft Windows 10/11 64 bit with BIOS Virtualization enabled
and Microsoft Windows Subsystem for Linux WSL 2
per System requirements and Instructions.
config/config.py
From logged in RPI SSH session or console terminal perform the following. Allows you to review install code before running
cd ~
wget https://raw.github.com/pageauc/speed-camera/master/speed-install.sh
more speed-install.sh # You can review code if you wish
chmod +x speed-install.sh
./speed-install.sh # runs install script.
cd ~/speed-camera
./speed-cam.py
See How to Run speed-cam.py wiki section
IMPORTANT Speed Camera will start in CALIBRATE_ON = True Mode.
Review settings in config.py file and edit variables with nano as required.
You will need to perform a calibration to set the correct value for config.py CAL_OBJPX and CAL_OBJMM for
L2R and R2L directions. The variables are based on the distance from camera to objects being measured for speed.
See Calibration Procedure for more details.
The config.py motion tracking variable called track_counter = can be adjusted for your system and opencv version. Default is 5 but a quad core RPI3 and latest opencv version eg 3.4.2 can be 10-15 or possibly greater. This will require monitoring the verbose log messages in order to fine tune.
cd ~/speed-camera
./menubox.sh
Admin speed-cam Easier using menubox.sh (Once calibrated and/or testing complete)
View speed-cam data and trends from web browser per sample screen shots. These can be generated from Menubox.sh menu pick or by running scripts from console or via crontab schedule.
You can view recent or historical images directly from the speed web browser page. These are dynamically created
and show up-to-date images. Press the web page refresh button to update display
Some of this code is based on a YouTube tutorial by Kyle Hounslow using C here https://www.youtube.com/watch?v=X6rPdRZzgjg
Thanks to Adrian Rosebrock jrosebr1 at http://www.pyimagesearch.com for the PiVideoStream Class code available on github at https://github.com/jrosebr1/imutils/blob/master/imutils/video/pivideostream.py
Have Fun
Claude Pageau
YouTube Channel https://www.youtube.com/user/pageaucp
GitHub Repo https://github.com/pageauc