PROJECTS Raspberry Pi Speed Camera
Here we are using a directory pycode for the app
file and its output.
When reviewing or editing Python code, it
helps to use an IDE that highlights the language
keywords and can prompt you to fix syntax errors.
Microsoft’s Visual Studio Code is available from
the default software sources and can be installed
with: sudo apt install code
Let’s hit some highlights of what a casual
user may want to customize in the program
code. The program is ready to run as-is on the
different hardware platforms. There are different
camera classes defined depending on the value
of platform.machine(). There’s a lot more
detail in the code than I can present in this limited
article, but you don’t need to understand it all to
configure and use it.
CLIPPING LIMITS & NOISE SOURCES
We make the Pi’s job easier with clipping limits
that tell the motion detection logic to ignore
image areas at the top of the view, such as
moving tree branches, and at the bottom of
the view, such as moving shadows. The Pi
camera frame is 640px wide by 480px high.
The y coordinate is 0 at the top of the frame, so
setting yTopClip to 220 ignores blobs whose y
centers are from y=0 to y=220. The lower limit is
configured similarly.
Within the image area of interest, what if
there’s a flashing light, or a waving tree branch?
The motion detection logic knows to ignore these
noise sources after several frames because they
do not move away from their initial locations.
However, their presence distracts the limited set
of tracker instances. A list of noise_tuples
can be configured to define rectangular areas
where smaller blobs will be ignored.
We’ve mentioned blurring and expanding the
areas of blobs done by Open CV method calls;
these act uniformly across the view. Additional
logic tries harder to combine blobs that are seen
at street level. For example, this can cause a
man walking a dog on a leash to be seen as one
moving object instead of two. So in addition to
the clip limits, there are configurable bounds to
define a street level, and there is a gap size value
to influence the extent of merging.
THE INVENTION OF BLOCKERS
Next, there is some algorithmic voodoo with the
idea of blockers: As a walking person disappears
behind a tree, the detected blob is reduced and
then disappears for a few frames. Without some
kind of software correction, a large tree trunk can
cause an object that has disappeared to be seen
as a new object when it reappears, or split what
should be one big blob into two. A blocker may
also cause the apparent speed to be reduced as
the leading edge is hidden, and then to jump as it
suddenly reappears.
A list of blockers can be configured as
rectangular areas that block the view of the
moving objects. When the motion of a tracked
object is predicted to intersect a blocker, the
software creates fake blobs for the predicted area
of intersection, and these fake blobs are merged
with the observed blobs. The net effect can be
seen in video clips — a blue rectangle indicating
a tracked car or person moves smoothly through
the large tree trunk (Figure
G
), like the camera
has X-ray eyes.
INTERACTIVE CONTROL
The app has keyboard commands to display or
hide the configured clipping limits, noise sources,
and blockers. This feature helps with checking
the configuration or with re-aiming a camera to
a previously configured position. Commands can
always be entered at the console window using
the Enter key. If X-Windows are displayed, single
keystroke commands can be directed at a window
without using Enter. Entering h (as in help)
displays the available commands.
Big block: The speed trap uses predictive software to
see through” view blockers like large trees.
G
80 makezine.com
M83_076-83_PiCamSpeedTrap_F1.indd 80M83_076-83_PiCamSpeedTrap_F1.indd 80 10/10/22 4:16 PM10/10/22 4:16 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.228.40