-
Notifications
You must be signed in to change notification settings - Fork 174
Program Description
What it does, Issues and Features
Speed Camera is a python program that uses opencv computer vision to visually track the largest moving object in the camera designated tracking area and determines the speed and direction. It records and saves an Image and optionally speed data to a CSV (Comma Separated Value) file for later processing.
NOTE: I have release speed-camera version 7.x That implements plugins to make it easier to manage custom settings. Webserver now has a < BACK button link and no longer opens a new browser tab for navigation.
There are lots of factors that can affect a real time computer vision program. Lighting is a critical factor but there are other issues that are not coded into this demo program. I have tried to list some factors below.
- Raspbian is not a real time operating system so occasionally it might be doing something else and thus miss processing some opencv motion tracking data.
- My code only tracks the largest moving object in the camera view. Occasionally two objects or one object that appears to opencv to be two or more may cross over or are very close in size and near each other. This can cause contours to possibly jump to another location and affect results. There is range checking that will try to reduce these anomalies.
- There are timeouts in the configuration that may be delaying camera and object tracking. Timeouts are designed to prevent an incomplete track from holding onto motion processing.
- It takes time to save an image so this will cause a delay in opencv processing.
- If RPI is not a quad core then threading may cause a slow down due to heating, reducing cpu speed or a mismatch in cpu processing versus camera framerate.
- Objects (vehicles) going in different directions on a road will be at different distances. I have thought about adjusting calibration for different directions.
- Tracking at edges of image will be farther away than in the middle of the image. This can affect calculations depending on angles and camera setup.
- The center of the OpenCV contours are used as reference points for motion tracking. This can jump around somewhat due to lighting or other factors causing change in tracking speed. The final speed is an average between start and end of track trigger length.
- Camera video streaming may slow opencv down. Setting the fastest camera FRAMERATE does not always improve performance. There is a balance between camera speed and processor speed. I have tried to accommodate for this in the different configurations (now plugins) but would not know if computer was single core, quad core, overclocked, faster cpu, Etc.
- There are differences between a USB web camera and a pi-camera that are not factored into the code.
- Different pi-camera models will have different capabilities, speed and resolutions, Etc. This also has not been factored into the code. There are similar issues with usb web cameras as well.
- There are differences between different versions of opencv 2 and 3 as well as compile and other opencv settings. This can affect performance and operation of the speed camera.
- There are differences in SD card and/or storage devices so this may slow processing when images are saved.
This demo was written as a learning opportunity for me. If you are interested you can review code and try customizing some settings to see if it improves results. Let me know your results.
- Uses video streaming to track largest moving objects in camera view and records speed based on calibration settings.
- Includes a calibration mode setting to set camera view distance to objects being measured for speed.
- Includes a whiptail menubox.sh Menu system that allows start/stop and managing program features
- Camera and Webserver Settings are managed from a config.py file that is not overwritten by an upgrade
- Can capture a video stream image with a variety of resolutions possible based on type of camera and RPI model.
- Tracks motion in a specified area. This rectangle area is cropped for motion tracking and reduces opencv processing on large image video streams.
- When motion tracking is trigger a video stream image is saved, so fast moving objects will still be in view.
- Motion Tracking Data can be stored in a CSV format file for processing by other applications
- Includes an opencv template match search to find similar objects to a selected image. Search result images can be put in a separate folder for easy review.
- makehtml.py can create html files from CSV data and formats for webserver processing
- Includes a single file webserver.py file that can be used to review images
- Option to create subfolder based on max number of images in folder or age of folder before triggering creation of a new date/time named subfolder.
- Option to manage disk space by specifying free space required before oldest files of specified type are deleted.
- Speed Camera code can run under MS windows and Non RPI Unix Distros using USB Camera and auto detects when picamera not found. Note bash scripts may not be compatible with standard windows OS.
- Includes optional special purpose plugins that overlay variables in config.py.
- Includes two plugins designed for use as simple security application for picam or webcam.
- Includes rclone install and scripts for uploading media to a remote storage name.
- includes sqlite3 database for speed data including sql query reports.
- Include gnuplot data graphing of speed data from sqlite3 database.
Wiki Home
Description, Issues, Features
How to Install or Upgrade
How to Run
How to Calibrate
Change Settings and Plugins
How to Tune Motion Tracking
Setup RTSP Camera
rclone Remote Storage File Transfer
How to View Speed Data
How to Generate Graphs
How to Run speed-search.py
How to Start on Boot
How to use run.sh
watch-app.sh Remote config
How to Manage Sqlite3 Database
How to move speed-camera to ext drive
How to use OPENALPR with speed camera
Github Repo