Eastern Ave speed limit 25 mph

Eastern Ave Speed Camera

Detects passing vehicles and computes their speed by the distance traveled between two consecutive image frames


Refresh browser for updates
Albemarle county police speed sign on Eastern

Set-up

  1. Runs on a Raspberry Pi 4 computer with 5 megapixel camera module

  2. Code is written in Python using Picamera and OpenCV libraries

  3. View the code on Github: https://github.com/ryanraba/pimotion/blob/master/monitor.py


Set-up in window

Algorithm

  1. An image frame is recorded every ~0.75 seconds

  2. The frame is convolved with a gaussian (kernel size 31) to blur small details

  3. The blurred frame is subtracted from the previous to produce a difference

  4. The absolute value of the difference image is thresholded to produce a binary (black/white) image of changes over/under threshold

  5. A dilation function expands the area of the pixels over threshold

  6. A contour function finds the outline of pixel groups over threshold

  7. The area of each contour is computed and the largest saved

  8. A bounding rectangle is placed over the original image at the location of the saved contour

  9. Center position of the bounding rectangle and time of image recording are saved

  10. If the subsequent frame also produces a large bounding rectangle, the position delta is divided by the time delta of the two images and converted to units of mph

Limitations

  1. The real-world distance corresponding to position delta of the bounding rectangles is a wild estimate, this needs to be calibrated, and until then the speed calculation is also a wild estimate

  2. A filter is used to throw out small contours and slow moving deltas, this is meant to avoid picking up people walking, but may end up missing some vehicles

  3. The image frames are heavily cropped to avoid people's yards

  4. The algorithm does not account for 3-D projection on to a 2-D surface, so it is limited to perpendicular movement with a fixed offset for depth between right and left lanes of the road