Is there a way to calculate speed of cars on camera

darrenph1

Getting comfortable
Joined
Feb 10, 2017
Messages
108
Reaction score
42
If I spray painted a couple of marks (x?) feet apart on the street, is there a way to calculate the speed of the car?
 

J Sigmo

Known around here
Joined
Feb 5, 2018
Messages
997
Reaction score
1,333
Look up VASCAR.

What you want to do is use the frame rate of your camera to calculate the time required for the car to pass between two points a known distance apart.

VASCAR - Wikipedia

The beauty of the video obtained by a security camera is that you have a visual record of the car's motion as well as the "landmarks" being used to mark off a known distance.

By stepping through the video frames, and knowing the frame rate of the camera, you can know how long it took the car to pass through the measured distance.

You would need to also take into account any parallax error if the car does not pass directly over the marks. And you would need to be sure of the exact frame rate for the camera.
 
Last edited:

tangent

IPCT Contributor
Joined
May 12, 2016
Messages
4,338
Reaction score
3,519
Trying to do this visually would be more accurate if the camera is set to a higher frame rate and the distance between the points of comparison is larger.

I know somebody on here bought an old radar gun and rigged up a text overlay. I've thought about doing the something similar because I'd enjoy setting off some street racer's radar detectors.
 

darrenph1

Getting comfortable
Joined
Feb 10, 2017
Messages
108
Reaction score
42
I know somebody on here bought an old radar gun and rigged up a text overlay. I've thought about doing the something similar because I'd enjoy setting off some street racer's radar detectors.
I like this idea, gonna have to look for that thread.

$129. Calibration is required.
I reached out to this software maker. The camera I use for street traffic overview is a PTZ (SD52C225U) pointed down the street in the morning and up the street in the afternoon. I wasn't sure if the software need a locked off camera or if the PTZ would be ok. I'd even be ok if it was only accurate during the morning traffic.
 

aristobrat

IPCT Contributor
Joined
Dec 5, 2016
Messages
2,982
Reaction score
3,180
Unless they started back up, there were a bunch of SPEEDCAM reviews that mentioned the author abandoned it and newly purchased licensed won’t activate.
 

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,005
Location
USA
Any image analytics approach to this is going to require calibration of course, unless your camera has the ability to determine real world sizes (this area has seen quite a bit of development recently, but not in IP cams!).

Some day I'd like to try building software that can determine vehicle speed from a camera pointed at a road. Although I am not enough of a mathematician or computer vision expert to do a really good job of it, I think I could probably make a speedometer that is pretty close to reality, especially if the camera is positioned carefully.

For example I have this camera pointed at the road going past my house and I think it would be pretty good for measuring vehicle speed.



Some object detection code could be used to track a vehicle between multiple frames and determine the distance traveled in pixels. Then just multiply the number of pixels times the real world size of a pixel and you have a real world distance. Divide by the time between the two frames, and you have a speed. No markers required. No high frame rate required.

One hard part is knowing the amount of real world space covered by every pixel. This will vary across the frame, and also vary with the object's distance from the camera. A simple program, the kind I would write, would just assume that every pixel in the frame was the same size, and this would contribute to lower accuracy. That would probably be okay for a camera like mine which is a fairly narrow view and close to a 90 degree angle from the road:



Of course, there are actually two roads in this camera's view, and one of those roads is at a worse angle to the camera. It would be much tougher to accurately measure the speed of vehicles on that road.



You also need to know very accurately and precisely how much time elapsed between the two video frames. Like, how many milliseconds apart the frames are. A vehicle going 30 MPH moves 1 foot in just 23 milliseconds, so being off just a little bit in the frame timing would have a huge impact on the speed calculation. If the camera isn't capable of providing that level of precision, then you would need to average the speed over many frames in order to cancel out the timing errors.

So yeah, there's a lot of complexity here. It really makes me appreciate a piece of software that claims to be able to measure speed across multiple lanes of traffic.

Doing the same job at night also becomes a lot harder because you would need much smarter object detection code to figure out the vehicle outline when there are headlights and taillights on.
 

tangent

IPCT Contributor
Joined
May 12, 2016
Messages
4,338
Reaction score
3,519
I like this idea, gonna have to look for that thread.
I think this was the thread: I'm Tempted To Start Shaming The Neighbors
Also stumbled on this in another thread pageauc/speed-camera

I reached out to this software maker. The camera I use for street traffic overview is a PTZ (SD52C225U) pointed down the street in the morning and up the street in the afternoon. I wasn't sure if the software need a locked off camera or if the PTZ would be ok. I'd even be ok if it was only accurate during the morning traffic.
I think a fixed camera is going to work best. I'd assume a PTZ would need to be calibrated for each preset and software like this might not be able tell if the camera had moved.

The software @bp2008 linked does specify that it needs a camera with at least 30 fps.
 

J Sigmo

Known around here
Joined
Feb 5, 2018
Messages
997
Reaction score
1,333
Doing this automatically is an interesting problem. Doing it by hand, on a case by case basis as you review already-captured video will be much easier, of course.

If one built a laser speed detector that operates the same way as the police units do, and also added radar as well, it would set off the laser and radar detectors commonly used. The speed measurement function wouldn't even need to work, as long as the patterns of emission mimicked the PoPo's equipment.

However, you may want the speed measurement to be effective, because technically, jamming is illegal in the US.

But another thing to consider is that you can get extremely inexpensive radar motion/presence sensors, and those wouldn't be considered jamming if they had some functionality. You could use one as an alert or alarm detector with the side benefit of setting off radar detectors.

But I will also say that people with radar detectors figure out where the false alarms come from pretty quickly if they drive the same route often. Back when I used a radar detector, I knew where the stores in my area that had radar door actuators were. ;)
 

darrenph1

Getting comfortable
Joined
Feb 10, 2017
Messages
108
Reaction score
42
So the maker of Speedcam Traffic sent me a trial. I'm searching on here but can't find this info: What's the address to connect to a substream of one of my cameras?

Anyone else wanna have a go at it? LINK

EDIT: OK I found this:

http://User:password@CamIP/cgi-bin/mjpg/video.cgi?channel=1&subtype=2


But it still ask for a user/password when I test in the a browser first...

Edit 2: change end of that string and I'm in!!

http://User:password@CamIP/cgi-bin/mjpg/video.cgi?channel=1&subtype=1

EDIT 3: I set up the camera and lanes but it drops the camera at some point. Let me know if anyone else has better luck or hints on settings
 
Last edited:

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,005
Location
USA
I ended up writing my own tool to do speed measurement, but it is was not very accurate (motion detection parameters likely need tweaked) or robust (it lost its stream after one day and didn't recover it) so it is on hold until I want to sink more time into it. But here is a test video showing what I came up with.

 

darrenph1

Getting comfortable
Joined
Feb 10, 2017
Messages
108
Reaction score
42
@darrenph1, how did the trial of Speedcam Traffic go?
Not so good, it kept losing the stream and quitting the application. I did get one good read off of it when I had it set for 1 direction but it needed more dialing in for both directions on my street. I gave up after a couple days trying it out...
 

SyconsciousAu

Getting comfortable
Joined
Sep 13, 2015
Messages
872
Reaction score
825
The minister for war and finance was complaining about the speed of cars in the area yesterday so I went googling for a solution and this thread came up.

Found something that looked very much like what @bp2008 was doing.


When I have a bit more time I'll play with it

For those looking for the radar threads



 

Acvc98

n3wb
Joined
Jan 28, 2022
Messages
1
Reaction score
0
Location
Sydney
This was the measurements they used. It doesn’t seem that they cared about the parralax error, shadow effect, the measurements of the car or any of the necessary information to measure the chance of error
 

Attachments

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,005
Location
USA
It is certainly possible to determine highly accurate speed of travel from a video, if the frames were captured with consistent and predictable timing.

It is also really easy to get it wrong and I wouldn't trust just anyone to have the spatial reasoning and mathematical skills required.
 

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,005
Location
USA
What would the Margin of error be if the they didn’t include parralax or shadow effect or any of those.
I don't know, it all depends on the specifics of the situation. What is "shadow effect"? Something you made up?

Also what is the equation to count pixels and frames from security footage.
That question doesn't even make sense.
 

alastairstevenson

Staff member
Joined
Oct 28, 2014
Messages
15,930
Reaction score
6,778
Location
Scotland
The shadow effect is from a study produced by the university of Washington
That's rain shadows caused by nearby mountains?

How do you find out how many frames per second there are in a video
That and much more is held in the metadata of a video file.

Could you explain how you would determine a cars speed at night time.
Determine the elapsed time that it takes to traverse 2 or more points that have a known distance between them.

What equations would you use to get an accurate speed.
Speed = distance divided by time.
 
Top