• Stars
    star
    935
  • Rank 48,878 (Top 1.0 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Unix, Windows, Raspberry Pi Object Speed Camera using python, opencv, video streaming, motion tracking. Includes a Standalone Web Server Interface, Image Search using opencv template match and a whiptail Admin Menu Interface Includes picam and webcam Plugins for motion track security camera configuration including rclone sync script. watch-app allows remotely controller camera configuration from a remote storage service name. Uses sqlite3 and gnuplot for reporting. Recently added openalpr license plate reader support.

SPEED CAMERA - Object Motion Tracker Mentioned in Awesome <INSERT LIST NAME>

RPI, Unix and Windows Speed Camera Using python, openCV, RPI camera module, USB Cam or IP Cam

For Details See Program Features, Wiki Instructions and YouTube Videos.

Note re Bullseye:

Speed-cam.py ver 11.26 will now run under the latest Raspberry Pi OS Bullseye with a pi camera module as well as webcam and IP cameras. For picamera support Run sudo raspi-config, Interface Options, then enable Legacy Camera option and reboot.

RPI Quick curl Install or Upgrade

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.

Step 1 With mouse left button highlight curl command in code box below. Right click mouse in highlighted area and Copy.
Step 2 On RPI putty SSH or terminal session right click, select paste then Enter to download and run script.

curl -L https://raw.github.com/pageauc/speed-camera/master/speed-install.sh | bash

This will download and run the speed-install.sh script. If running under python3 you will need opencv3 installed. See my Github menu driven compile opencv3 from source project

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.

Mac or Windows Systems

See Windows 10/11 or Apple Mac Docker Install Quick Start
or Windows or Unix Distro Installs without Docker

Program Description

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 y_upper, y_lower, x_left, x_right variables (road or area of interest). Auto calculated but can be overridden in config.py by uncommenting desired variable settings. Motion Tracking is controlled by the track_counter 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_obj_px and cal_obj_mm 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 imageSubDirMaxFiles = 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

Admin, Reports, Graphs and Utilities scripts

  • menubox.sh script is a whiptail menu system to allow easier management of program settings and operation.
  • webserver.py Allows viewing images and/or data from a web browser (see config.py for webserver settings) To implement webserver3.py copy webserver3.py to webserver.py Note and update will undo this change.
  • rclone Manage settings and setup for optional remote file sync to a remote storage service like google drive, DropBox and many others.
  • watch-app.sh for administration of settings from a remote storage service. Plus application monitoring.
  • sql-make-graph-count-totals.py Query sqlite database and Generate one or more matplotlib graph images and save to media/graphs folder. Graphs display counts by hour, day or month for specfied previous days and speed over. Multiple reports can be managed from the config.py GRAPH_RUN_LIST variable under matplotlib image settings section.
  • sql-make-graph-speed-ave.py Query sqlite database and Generate one or more matplotlib graph images and save to media/graphs folder. Graphs display Average Speed by hour, day or month for specfied previous days and speed over. Multiple reports can be managed from the config.py GRAPH_RUN_LIST variable under matplotlib image settings section.
  • sql-speed_gt.py Query sqlite database and Generate html formatted report with links to images and save to media/reports folder. Can accept parameters or will prompt user if run from console with no parameters
  • makehtml.py Creates html files that combine csv and image data for easier viewing from a web browser and saved to media/html folder.
  • speed-search.py allows searching for similar target object images using opencv template matching. Results save to media/search folder.
  • alpr-speed.py This is a demo that processes existing speed camera images with a front or back view of vehicle using OPENALPR License plate reader. Output is saved to media/alpr folder. For installation, Settings and Run details see ALPR Wiki Documentaion

Reference Links

Requirements

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

Windows or Non RPI Unix Installs

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.

Docker Install Quick Start

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.

  1. Download and install Docker Desktop for your System
  2. Clone the GitHub Speed Camera repository using green Clone button (top right)
  3. Run docker-compose up from the directory you cloned the repo into.
  4. The Docker container will likely exit because it is using a default config.
  5. Edit the configuration file @ config/config.py
  6. Run docker-compose up per documentation
  7. Run docker build command locally to get a fresh image.

Raspberry pi Manual Install or Upgrade

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.

Run to view verbose logging

cd ~/speed-camera    
./speed-cam.py

See How to Run speed-cam.py wiki section

IMPORTANT Speed Camera will start in calibrate = 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_obj_px and cal_obj_mm 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.

Run menubox.sh

cd ~/speed-camera
./menubox.sh

Admin speed-cam Easier using menubox.sh (Once calibrated and/or testing complete)
menubox main menu

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.

Speed Camera GRAPHS Folder Web Page
Speed Camera REPORTS Folder Web Page
Speed Camera HTML Folder Web Page

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 refesh button to update display Speed Camera RECENT Folder Web Page
Speed Camera IMAGES Folder Web Page

Credits

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

More Repositories

1

pi-timolo

Raspberry PI-TIMOLO ( PI-TImelapse, MOtion, LOwLight ) uses RPI picamera and OpenCV for Remote Headless Security Monitoring using Motion Tracking, Rclone Auto Sync files with remote storage services. Auto Twilight Transitions and Low Light Camera Settings. Panoramic images using PanTiltHat and More. This project is featured on GitHub Awesome software.
Python
547
star
2

motion-track

Windows, Unix, Raspberry Pi Motion Tracking Demo. Tracks movement in camera view and returns X, Y Position of Largest Moving Contour in Camera View - See Moved GitHub Project Links
Python
149
star
3

rclone4pi

rclone4pi - Easy Install of rclone to Raspberry Pi Computer with automated folder sync demo
Shell
96
star
4

picamera-motion

Raspberry Pi python PiCamera Lightweight Motion Detection. Includes easy curl script install/upgrade, whiptail admin menu system, single file web server and Rclone for uploading to a variety of web storage services.
Python
89
star
5

opencv3-setup

Raspberry Pi whiptail Menu driven Easy Install and Compile of opencv3 python from source files.
Shell
51
star
6

pi-motion-lite

Raspberry Pi python motion detection using picamera python module
Python
45
star
7

face-track-demo

Raspberry Pi python PiCamera, OpenCV Face and Motion Tracking using pan/tilt assembly via servo controller or gpiozero pwm
Python
38
star
8

cam-track

Windows, Unix, Raspberry Pi Computer python program to Track Camera X, Y Movements and Convert to Camera Pointing Position. Useful for Stabilization or Robotics Course Correction
Python
38
star
9

sonic-track

Uses a raspberry pi camera or web cam and python opencv to track motion in camera view. Sends motion contour data to sonic-pi via osc interface to produce and control notes/sample. Includes ability to use onscreen menu areas to change synthesizer, octaves Etc.
Python
30
star
10

pi-motion

Raspberry Pi and Camera Module raspistill Python Motion Capture
Shell
23
star
11

FileBrowser

This is a bash whiptail file selection menu sample code
Shell
15
star
12

track-inout

Windows, Unix, Raspberry Pi program uses opencv and python to track moving objects that enter and leave camera view and cross a vert or horz trigger center line. Can be configured to take an image and log data to a csv file. Includes a standalone web server for viewing image files. At this point it is a demo since it would need more work but the basic operation is functional.
Python
12
star
13

webserver

A Raspberry Pi Simple python Stand Alone Local Network Web Server. Automatically reads folder and file entries into a right pane selection list. Selected folder opens a new browser tab and Selected file displays content in browser left pane iframe. Right pane list can be ordered by date/time or alphabetic ascending or descending via settings.py file. A menubox.sh makes it easier to operate and change the webserver settings.
Python
12
star
14

pi-motion-orig

Raspberry Pi camera python motion detect and grive sync images to google drive
Python
10
star
15

panopi

Create pano timelapse images from multiple RPI computers using picamera modules.
Python
9
star
16

pifan

Control Raspberry Pi case fan on/off using CPU temperature
Python
7
star
17

waveshare.pantilthat

Waveshare PanTiltHat python2 and 3 Driver and demo. Uses curl install scripts. One for Demo and Driver and one just for driver. Demo's scripts support Pimoroni.
Python
6
star
18

enviro-pi

Use RPI with Sensehat to monitor humidity, temperature, barometric pressure. View data and graphs on a web browser. Optionally Upload data to Weather Underground Personal Weather Station
Python
6
star
19

pokeme

A Motion Tracking Demo with Motion Activated Menus and Image Clips
Python
3
star
20

MoTrack-Picam2-Demo

Test of Picamera2 python library
Python
3
star
21

hotspot-game

A Windows, Unix or Raspberry Pi Computer Motion Tracking Game using a Web Cam or RPI Camera Video Streaming. Uses Body Motion for Menus and Game Play for One or Two Players.. Get High Score by getting most motion hits in moving boxes that get smaller..
Python
3
star
22

rpi-shutdown

Safely shutdown a raspberry pi using a momentary switch
Python
2
star
23

webcam-video

A Bash script to take short video sequences using avconv and upload (sync) to google drive. Runs on Raspberry Pi or other Unix Distros
Shell
1
star