Using ZoneMinder to determine vehicle speed
Posted: Thu Sep 17, 2009 8:15 pm
I've got two kids on a street that is often used as a cut-through. Most people drive nicely, but some people fly through here 10mph+ over 25mph and are on their cell phone. All it takes is for my kid just once to go into the street when they come through and boom -- my kid is dead or in the hospital and the driver goes to jail.
I've got ZoneMinder watching my front yard which includes the street. I used it to help get a traffic study done in our neighborhood by the local DOT. Viewing one day of footage from ZM I was able to run through 24 hours of events in about 20 minutes and counted 1200 cars passing down the street, with the peak between 4-7pm of about 100-120 cars per hour. I'd like to do more, capturing proof of speeders, and show that marked police cars are ineffective at gauging actual speed because people slam on the brakes at the first sign of a Crown Vic, marked or unmarked. Our county won't do anything unless the average speed is 30+ or the 85th percentile are doing 35+. Mostly I want to figure out if I'm being an overprotective dad or if there is a real problem with speeding in our neighborhood.
Since I've been able to do some math, measuring and calculating, and at 15 frames per second, with a distance between driveways of 35 feet and adjusted for the camera's view the distance at the center of the road is 29 feet, I can calculate the rough speed of any vehicle using ZoneMinder.
I can even set up zones for this very purpose! The biggest problem is that I haven't yet figured out how to automate it.
The camera faces east, so right-to-left is north, left-to-right is south.
| Z3 | Z2 | Z1 |
For a northbound vehicle, it would enter the frame (Zone 1) and start alarming. The right-most edge of Zone 2 is the line for which I want to start counting. The right-most edge of Zone 3 is the line for which I want to stop counting.
For a southbound vehicle, it would enter the frame (Zone 3) and start alarming. The left-most edge of Zone 2 is the line for which I want to start counting. The left-most edge of Zone 1 is the line for which I want to stop counting.
Using the northbound vehicle as an example, and assuming our zone sensitivity is the same for all zones, if the time delta 1.10 when Zone 2 starts alarming, and the time delta when Zone 3 first alarms is 1.75:
29 feet per 0.65 seconds (1.75-1.10)
We want to solve for x, where we know 29 feet per 0.65 seconds should equal x miles per hour.
29 feet / 5280 feet per mile = 0.0054924 miles
0.65 seconds / 3600 seconds per hour = 0.0001806 hours
0.0054924 miles / 0.0001806 hours == 30.41 miles per hour.
I can do this manually, but what a pain.
I can boil this down to pseudocode:
I haven't rustled the code or DB schema yet, so maybe this will be easy to write a cron job to parse all the events. The biggest issue will be setting the sensitivity just right on each of the zones to make sure all three zones alert at the same rate.
Would love to start some discussion here about it. If it is feasible, I may just write the code for it and offer to integrate it into ZM.
I've got ZoneMinder watching my front yard which includes the street. I used it to help get a traffic study done in our neighborhood by the local DOT. Viewing one day of footage from ZM I was able to run through 24 hours of events in about 20 minutes and counted 1200 cars passing down the street, with the peak between 4-7pm of about 100-120 cars per hour. I'd like to do more, capturing proof of speeders, and show that marked police cars are ineffective at gauging actual speed because people slam on the brakes at the first sign of a Crown Vic, marked or unmarked. Our county won't do anything unless the average speed is 30+ or the 85th percentile are doing 35+. Mostly I want to figure out if I'm being an overprotective dad or if there is a real problem with speeding in our neighborhood.
Since I've been able to do some math, measuring and calculating, and at 15 frames per second, with a distance between driveways of 35 feet and adjusted for the camera's view the distance at the center of the road is 29 feet, I can calculate the rough speed of any vehicle using ZoneMinder.
I can even set up zones for this very purpose! The biggest problem is that I haven't yet figured out how to automate it.
The camera faces east, so right-to-left is north, left-to-right is south.
| Z3 | Z2 | Z1 |
For a northbound vehicle, it would enter the frame (Zone 1) and start alarming. The right-most edge of Zone 2 is the line for which I want to start counting. The right-most edge of Zone 3 is the line for which I want to stop counting.
For a southbound vehicle, it would enter the frame (Zone 3) and start alarming. The left-most edge of Zone 2 is the line for which I want to start counting. The left-most edge of Zone 1 is the line for which I want to stop counting.
Using the northbound vehicle as an example, and assuming our zone sensitivity is the same for all zones, if the time delta 1.10 when Zone 2 starts alarming, and the time delta when Zone 3 first alarms is 1.75:
29 feet per 0.65 seconds (1.75-1.10)
We want to solve for x, where we know 29 feet per 0.65 seconds should equal x miles per hour.
29 feet / 5280 feet per mile = 0.0054924 miles
0.65 seconds / 3600 seconds per hour = 0.0001806 hours
0.0054924 miles / 0.0001806 hours == 30.41 miles per hour.
I can do this manually, but what a pain.
I can boil this down to pseudocode:
Code: Select all
$distanceInFeet = 29;
if (Zone 1 alarms before Zone 2) {
$time = $TDz3 - $TDz2;
} elseif (Zone 3 alarms before Zone 2) {
$time = $TDz1 - $TDz2;
} else {
// not a valid event for speed calc
}
if (!empty($time)) {
$speed = round(($distanceInFeet/5280)/($time/3600),2);
}
Would love to start some discussion here about it. If it is feasible, I may just write the code for it and offer to integrate it into ZM.