{"id":13586221,"url":"https://github.com/pageauc/speed-camera","last_synced_at":"2025-05-14T20:07:36.339Z","repository":{"id":37493460,"uuid":"70590335","full_name":"pageauc/speed-camera","owner":"pageauc","description":"A Unix, Windows, Raspberry Pi Object Speed Camera using python3, opencv, video streaming, motion tracking.  Includes a Standalone Web Server , 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 scripts. ","archived":false,"fork":false,"pushed_at":"2025-04-26T01:07:46.000Z","size":4914,"stargazers_count":1019,"open_issues_count":13,"forks_count":175,"subscribers_count":47,"default_branch":"master","last_synced_at":"2025-04-26T02:35:57.577Z","etag":null,"topics":["matplotlib-pyplot","motion-tracking","moving","openalpr","opencv","picamera2","python","raspberry-pi-computer","road","rpi-camera","speed-cam","sqlite3","traffic","unix","vehicle","video-streaming","webcam-capture","webserver","whiptail-menu","windows"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pageauc.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.MD","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-10-11T12:20:12.000Z","updated_at":"2025-04-26T01:07:50.000Z","dependencies_parsed_at":"2024-03-02T21:24:33.832Z","dependency_job_id":"98e3fe6f-d840-491e-9c98-526b056e9fb2","html_url":"https://github.com/pageauc/speed-camera","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pageauc%2Fspeed-camera","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pageauc%2Fspeed-camera/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pageauc%2Fspeed-camera/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pageauc%2Fspeed-camera/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pageauc","download_url":"https://codeload.github.com/pageauc/speed-camera/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254219373,"owners_count":22034397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["matplotlib-pyplot","motion-tracking","moving","openalpr","opencv","picamera2","python","raspberry-pi-computer","road","rpi-camera","speed-cam","sqlite3","traffic","unix","vehicle","video-streaming","webcam-capture","webserver","whiptail-menu","windows"],"created_at":"2024-08-01T15:05:24.540Z","updated_at":"2025-05-14T20:07:36.293Z","avatar_url":"https://github.com/pageauc.png","language":"Python","readme":"## SPEED CAMERA - Object Motion Tracker [![Mentioned in Awesome \u003cINSERT LIST NAME\u003e](https://awesome.re/mentioned-badge.svg)](https://github.com/thibmaek/awesome-raspberry-pi)\n#### Raspberry Pi, Unix Disto's and Windows Speed Camera Using python3, openCV, RPI camera module, USB Cam or IP/RTSP Cam\n#### For Details See [Program Features](https://github.com/pageauc/speed-camera/wiki/Program-Description#program-features), [Wiki Instructions](https://github.com/pageauc/speed-camera/wiki) and [YouTube Videos](https://github.com/pageauc/speed-camera#reference-links).\n\n***Note re Bullseye***     \nspeed-cam.py will run using pi camera with libcamera, picamera2 under Raspberry Pi OS Bullseye, Bookworm,and later. Usbcam and IP/RTSP cameras\n are also supported. For picamera library support (on Bullseye only) Run ***sudo raspi-config***, Interface Options, then enable Legacy Camera option and Reboot.\n\n### RPI Quick Install or Upgrade   \n***IMPORTANT*** - A raspbian **sudo apt-get update** and **sudo apt-get upgrade** will **NOT** be performed as part of   \n**speed-install.sh** so it is highly recommended you run these prior to install\nto ensure your system is up-to-date.     \n\n#### Step 1\nPress GitHub copy icon on right side of code box below.  Copied! will be displayed.   \n\n    curl -L https://raw.github.com/pageauc/speed-camera/master/source/speed-install.sh | bash\n\n#### Step 2\nOn RPI putty SSH or terminal session right click, select paste then Enter to Download and Run **speed-install.sh** script.  \n\nTo get started, see Instructions at the end of the install script. Initial default config.py setting is CALIBRATE_ON=True.\nYou may also need to Align Camera using config.py ALIGN_CAM_ON=True setting.  Once calibration is complete set CALIBRATE_ON=False\n\n### Mac or Windows Systems\nSee [Windows 10/11 or Apple Mac Docker Install Quick Start](https://github.com/pageauc/speed-camera#docker-install-quick-start)    \nor [Windows or Unix Distro Installs without Docker](https://github.com/pageauc/speed-camera#windows-or-non-rpi-unix-installs)\n\n### Program Description   \nThis project can run on a Raspberry Pi, Windows, Unix Distro computer.\nIt is written in python3 and uses openCV to detect and track the x,y coordinates of the \nlargest moving object in the camera view above a minimum pixel area and calculates speed based on calibration settings.\n\nUser variables are stored in the [***config.py***](https://github.com/pageauc/speed-camera/blob/master/source/config.py) file.\nMotion 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).\n***MO_CROP_AUTO_ON*** = ***True*** overrides manual settings and will Auto calculate a rough crop area based on image size.\nMotion Tracking is controlled by the ***MO_TRACK_EVENT_COUNT*** variable in config.py.  This sets the number of track events and \nthe track length in pixels.  This may need to be tuned for camera view, cpu speed, etc. \nSpeed 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\ncaptured and saved in ***media/images*** dated subfolders (optional) per variable ***IM_SUBDIR_MAX_FILES*** = ***2000*** \nFor variable settings details see [config.py file](https://github.com/pageauc/speed-camera/blob/master/source/config.py). \n\nIf ***LOG_DATA_TO_CSV*** = ***True*** then a ***speed-cam.csv*** file will be created/updated with event data stored in\nCSV (Comma Separated Values) format. This can be imported into a spreadsheet, database, Etc program for further processing.\nRelease 8.9 adds a **sqlite3** database to store speed data. Default is ***data/speed_cam.db*** with data in the ***speed*** table.\nDatabase setting can be managed from config.py.  Database is automatically created from config.py settings. For more\ndetails see [How to Manage Sqlite3 Database](https://github.com/pageauc/speed-camera/wiki/How-to-Manage-Sqlite3-Database)\n\n### Admin, Reports, Graphs and Utilities scripts\n  \n* [***menubox.sh***](https://github.com/pageauc/speed-camera/wiki/Admin-and-Settings#manage-settings-using-menuboxsh)\nscript is a whiptail menu system to allow easier management of program settings and operation.    \n* [***speed-cam.py***](https://github.com/pageauc/speed-camera/wiki/How-to-Run)\nView operation and log messages in real time in terminal session. Can be used to monitor, troubleshoot and tune speed camera (see config.py for speed-cam.py settings)   \n* [***speed-cam.sh***](https://github.com/pageauc/speed-camera/tree/master/source/supervisor)\nThis bash script uses supervisorctl to manage start, stop, status, Etc of speed-cam.py Configured to autostart eg due to interruption of RTSP stream. \nSee conf files in supervisor folder for details. Note: you must run ***./speed-cam.sh*** ***install*** to initialize symbolic links to /etc/supervisor/conf.d folder. \nStop running any speed-cam and/or websever processes before running ***./speed-cam.sh*** ***start*** \n* [***speed-web.py***](https://github.com/pageauc/speed-camera/wiki/How-to-View-Data#how-to-view-images-and-or-data-from-a-web-browser)\nAllows viewing images, video and/or data from a web browser. This will display web server messages. (see config.py for speed-web.py settings)   \n* [***speed-web.sh***](https://github.com/pageauc/speed-camera/tree/master/source/supervisor)\nThis bash script uses supervisorctl to manage start, stop, status, Etc of speed-web.py. Configured to restart eg due to interruption \nSee conf files in supervisor folder for details. Note: you must run ***./speed-web.sh*** ***install*** to initialize symbolic links to /etc/supervisor/conf.d folder. \nStop running any speed-cam and/or websever processes before running ***./speed-web.sh*** ***start*** \n* [***rclone***](https://github.com/pageauc/speed-camera/wiki/Manage-rclone-Remote-Storage-File-Transfer)\nManage settings and setup for optional remote file sync to a remote storage service like google drive, DropBox and many others.   \n* [***sql-make-graph-count-totals.py***](https://github.com/pageauc/speed-camera/wiki/How-to-Generate-Speed-Camera-Graphs#sql-make-graph-count-totalspy) Query sqlite database and Generate one or more matplotlib graph images and save to media/graphs folder.\nGraphs display counts by hour, day or month for specfied previous days and speed over. Multiple reports can be managed from\nthe config.py ***GRAPH_RUN_LIST*** variable under matplotlib image settings section.       \n* [***sql-make-graph-speed-ave.py***](https://github.com/pageauc/speed-camera/wiki/How-to-Generate-Speed-Camera-Graphs#sql-make-graph-speed-avepy) Query sqlite database and Generate one or more matplotlib graph images and save to media/graphs folder.\nGraphs display Average Speed by hour, day or month for specfied previous days and speed over. Multiple reports can be managed from\nthe config.py ***GRAPH_RUN_LIST*** variable under matplotlib image settings section.    \n* [***sql-speed_gt.py***](https://github.com/pageauc/speed-camera/wiki/How-to-Generate-Speed-Camera-Graphs#sql-speed_gtpy) Query sqlite database and Generate html formatted report with links to images and save to media/reports folder.\nCan accept parameters or will prompt user if run from console with no parameters\n* [***makehtml.py***](https://github.com/pageauc/speed-camera/wiki/How-to-View-Data#view-combined-imagedata-html-pages-on-a-web-browser)\nCreates html files that combine csv and image data for easier viewing from a web browser and saved to media/html folder.    \n* [***speed-search.py***](https://github.com/pageauc/rpi-speed-camera/wiki/How-to-Run-speed-search.py)\nallows searching for similar target object images using opencv template matching.  Results save to media/search folder.    \n* [***alpr-speed.py***](https://github.com/pageauc/speed-camera/wiki/alpr-speed.py---Process-speed-images-with-OPENALPR-Automatic-License-Plate-Reader)\nThis is a demo that processes existing speed camera images with a front or back view of vehicle using [OPENALPR](https://github.com/openalpr/openalpr)\nLicense plate reader. Output is saved to media/alpr folder. For installation, Settings and Run details see\n[ALPR Wiki Documentaion](https://github.com/pageauc/speed-camera/wiki/alpr-speed.py---Process-speed-images-with-OPENALPR-Automatic-License-Plate-Reader)       \n\n### Reference Links\n* YouTube Tutorial Video https://www.youtube.com/watch?v=n2WT3Qb0SIU\n* YouTube Speed Lapse Video https://youtu.be/-xdB_x_CbC8\n* YouTube Speed Camera Video https://youtu.be/eRi50BbJUro\n* YouTube motion-track video https://youtu.be/09JS7twPBsQ  \n* [How to Build a Cheap Homemade Speed Camera](https://mass.streetsblog.org/2021/02/26/how-to-build-a-homemade-speed-camera/)  \n* Speed Camera RPI Forum post https://www.raspberrypi.org/forums/viewtopic.php?p=1004150#p1004150\n* YouTube Channel https://www.youtube.com/user/pageaucp \n* Speed Camera GitHub Repo https://github.com/pageauc/speed-camera      \n\n### Requirements\n[***Raspberry Pi computer***](https://www.raspberrypi.org/documentation/setup/) and a [***RPI camera module installed***](https://www.raspberrypi.org/documentation/usage/camera/)\nor USB Camera plugged in. Make sure hardware is tested and works. Most [RPI models](https://www.raspberrypi.org/products/) will work OK. \nA quad core RPI will greatly improve performance due to threading. A recent version of \n[Raspbian operating system](https://www.raspberrypi.org/downloads/raspbian/) is Recommended.   \nor  \n***MS Windows or Unix distro*** computer with a USB Web Camera plugged in and a\n[recent version of python installed](https://www.python.org/downloads/)\nFor Details See [***Wiki details***](https://github.com/pageauc/speed-camera/wiki/Prerequisites-and-Install#windows-or-non-rpi-unix-installs).\n\nIt is recommended you upgrade to OpenCV version 3.x.x  For Easy compile of opencv 3.4.2 from source \nSee https://github.com/pageauc/opencv3-setup\n\n### Windows or Non RPI Unix Installs\nFor Windows or Unix computer platforms (non RPI or Debian) ensure you have the most\nup-to-date python version. For Download and Install [python](https://www.python.org/downloads) and [Opencv](https://docs.opencv.org/4.x/d5/de5/tutorial_py_setup_in_windows.html)    \n\nThe latest python3 versions includes numpy and recent opencv version that is required to run this code. \nYou will also need a USB web cam installed and working. \nTo install this program access the GitHub project page at https://github.com/pageauc/speed-camera\nSelect the ***green Clone or download*** button. The files will be cloned or zipped\nto a speed-camera folder. You can run the code from python IDLE application (recommended), GUI desktop\nor command prompt terminal window. Note bash .sh shell scripts will not work with windows unless \nspecial support for bash is installed for windows Eg http://win-bash.sourceforge.net/  http://www.cygwin.com/\n***Note:*** I have Not tested these.   \n\n### Docker Install Quick Start\nspeed camera supports a docker installation on    \nApple Macintosh per [System requirements and Instructions](https://docs.docker.com/desktop/mac/install/)    \nand      \nMicrosoft Windows 10/11 64 bit with BIOS Virtualization enabled\nand [Microsoft Windows Subsystem for Linux WSL 2](https://docs.microsoft.com/en-us/windows/wsl/install) \nper [System requirements and Instructions](https://docs.docker.com/desktop/windows/install/).   \n\n1. Download and install [Docker Desktop](https://www.docker.com/get-started) for your System\n1. Clone the GitHub [Speed Camera repository](https://github.com/pageauc/speed-camera) using green Clone button (top right)\n1. Run [docker-compose up](https://docs.docker.com/compose/reference/up/) from the directory you cloned the repo into.\n1. The Docker container will likely exit because it is using a default config.\n1. Edit the configuration file @ `config/config.py`\n1. Run [docker-compose up](https://docs.docker.com/compose/reference/up/) per documentation\n1. Run [docker build](https://docs.docker.com/engine/reference/commandline/build/) command locally to get a fresh image.\n \n### Raspberry pi Manual Install or Upgrade   \nFrom logged in RPI SSH session or console terminal perform the following. Allows you to review install code before running\n\n    cd ~\n    wget https://raw.github.com/pageauc/speed-camera/master/source/speed-install.sh\n    more speed-install.sh       # You can review code if you wish\n    chmod +x speed-install.sh\n    ./speed-install.sh  # runs install script.\n    \n### Run to view verbose logging \n\n    cd ~/speed-camera    \n    ./speed-cam.py\n    \nSee [***How to Run***](https://github.com/pageauc/speed-camera/wiki/How-to-Run) speed-cam.py wiki section\n\n***IMPORTANT*** Speed Camera will start in ***CALIBRATE_ON*** = ***True*** Mode.    \nReview settings in ***config.py*** file and edit variables with nano as required.\nYou will need to perform a calibration to set the correct value for config.py ***CAL_OBJ_PX_*** and ***CAL_OBJ_MM_*** for\nL2R and R2L directions. The variables are based on the distance from camera to objects being measured for speed.\nSee [***Calibration Procedure***](https://github.com/pageauc/speed-camera/wiki/Calibrate-Camera-for-Distance) for more details.     \n\nThe config.py motion tracking variable called ***track_counter*** = can be adjusted for your system and opencv version.\nDefault is 5 but a quad core RPI3 and latest opencv version eg 3.4.2 can be 10-15 or possibly greater.  This will\nrequire monitoring the verbose log messages in order to fine tune.\n    \n### Run menubox.sh \n\n    cd ~/speed-camera\n    ./menubox.sh\n\nAdmin speed-camera Easier using menubox.sh (Once calibrated and/or testing complete) \n \n![menubox main menu](https://github.com/pageauc/speed-camera/blob/master/assets/menubox.png)     \n\nView speed-cam data and trends from web browser per sample screen shots. These can be generated \nfrom Menubox.sh menu pick or by running scripts from console or via crontab schedule.\n\n![Speed Camera GRAPHS Folder Web Page](https://github.com/pageauc/speed-camera/blob/master/assets/speed_web_graphs.png)  \n![Speed Camera REPORTS Folder Web Page](https://github.com/pageauc/speed-camera/blob/master/assets/speed_web_reports.png)   \n![Speed Camera HTML Folder Web Page](https://github.com/pageauc/speed-camera/blob/master/assets/speed_web_html.png)    \n\nYou can view recent or historical images directly from the speed web browser page.  These are dynamically created\nand show up-to-date images.  Press the web page refresh button to update display \n![Speed Camera RECENT Folder Web Page](https://github.com/pageauc/speed-camera/blob/master/assets/speed_web_recent.png)   \n![Speed Camera IMAGES Folder Web Page](https://github.com/pageauc/speed-camera/blob/master/assets/speed_web_images.png)   \n\n### Credits  \nSome of this code is based on a YouTube tutorial by\nKyle Hounslow using C here https://www.youtube.com/watch?v=X6rPdRZzgjg\n\nThanks to Adrian Rosebrock jrosebr1 at http://www.pyimagesearch.com \nfor the PiVideoStream Class code available on github at\nhttps://github.com/jrosebr1/imutils/blob/master/imutils/video/pivideostream.py\n  \nHave Fun   \nClaude Pageau    \nYouTube Channel https://www.youtube.com/user/pageaucp   \nGitHub Repo https://github.com/pageauc\n","funding_links":[],"categories":["Python","By Industry","By Language","Projects"],"sub_categories":["Web Development","Python"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpageauc%2Fspeed-camera","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpageauc%2Fspeed-camera","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpageauc%2Fspeed-camera/lists"}