PROJECTS Raspberry Pi Speed Camera
• Next, the changing angle of view of the camera
causes the dx/dt values to be slightly larger at
the center of the view than at either end where
the view of the moving object is slightly angled.
• On top of these regular variations in dx/dt there
is less regular variation caused by changes
in lighting and background color variation,
changes in the actual speed of the object, and
partial blocking of the image from tree trunks,
vegetation, etc.
We cut through all this complexity by fitting
the dx/dt versus x values to a best-fit line and
interpolating the observed values to compute
dx/dt at the center of the frame image. Most of
the calculations for the best-fit line are done
incrementally as each frame is analyzed, so the
overhead of speed estimation does not impede
real-time video capture.
If the tracked object motion is fairly steady, the
dx/dt value calculated for the center of the frame
is a decent estimate of the object speed at the
center of the frame. The dx/dt value is converted
to mph by multiplying it by a factor found by
calibration runs. In my case, the street is about
90 feet away from the garage window, and slightly
angled so that the left side is farther away. Driving
by at 19.5mph resulted in a dx/dt value of 150.5,
so my conversion factor for the garage camera is
0.130 mph/(dx/dt).
THE HARDWARE
Our app is somewhat resource intensive and uses
the CPU heavily so a Raspberry Pi 4B with 8GB
memory and some provision for heat dissipation
is recommended. I’ve replaced the top cover of
the HighPi case purchased from pishop.us with
a 3D-printed cover that’s perforated to provide
venting. I also suggest adding inexpensive stick-
on aluminum heatsinks from the same source
(Figure
B
).
Video files captured with the Pi Version 2
Camera Module can range in size from 100MB
to 3GB on a windy day. The app has logic to open
new output files every midnight and to limit
the number of files to a configurable number
of days. A 32GB MicroSD card is adequate for
several days’ storage, and my practice is to move
video files off the Pi to a different workstation
for review. To save weeks of video on the Pi, get
yourself a 64GB card or larger.
For a dedicated setup there is no monitor and
keyboard connected to the Pi and all access is
through the home network. By logging in with
ssh -X, we enable X-Windows and see a
decorated camera view plus another view of
the computed blobs. The app uses console
commands to optionally show or dismiss the two
windows; unless they’re being viewed, they’re
dismissed to reduce lost frames, CPU usage, and
network load.
A good network connection is important
to avoid lock-ups. The Pi’s built-in Wi-Fi had
difficulty keeping a good connection with my
mesh routers, so I tried a USB Wi-Fi adapter that
had a larger antenna. I soon replaced that with an
additional router with a wired connection to the
Pi. Once the Pi is using the wired LAN, the built-
in Wi-Fi and Bluetooth can be disabled using
raspi-cong.
TOO MUCH SUN
If the sun shines directly on the camera lens,
the images get washed out. So I designed and
G
B C
Hooded camera case on window blind.Hardware for the window mounted speed cam.
78 makezine.com
M83_076-83_PiCamSpeedTrap_F1.indd 78M83_076-83_PiCamSpeedTrap_F1.indd 78 10/10/22 4:16 PM10/10/22 4:16 PM