Is there a way to calculate speed of cars on camera

Discussion in 'Chit-Chat' started by darrenph1, May 12, 2019.

Share This Page

  1. darrenph1

    darrenph1 Getting comfortable

    Joined:
    Feb 10, 2017
    Messages:
    107
    Likes Received:
    40
    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?
     
  2. J Sigmo

    J Sigmo Known around here

    Joined:
    Feb 5, 2018
    Messages:
    763
    Likes Received:
    786
    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: May 12, 2019
    darrenph1 likes this.
  3. bp2008

    bp2008 Staff Member

    Joined:
    Mar 10, 2014
    Messages:
    8,764
    Likes Received:
    5,840
    This software claims to do it, probably without any markers, painted or otherwise. SPEEDCAM TRAFFIC
     
    tangent and darrenph1 like this.
  4. tangent

    tangent IPCT Contributor

    Joined:
    May 12, 2016
    Messages:
    3,853
    Likes Received:
    2,516
    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.
     
    looney2ns likes this.
  5. tangent

    tangent IPCT Contributor

    Joined:
    May 12, 2016
    Messages:
    3,853
    Likes Received:
    2,516
    $129. Calibration is required.
     
  6. darrenph1

    darrenph1 Getting comfortable

    Joined:
    Feb 10, 2017
    Messages:
    107
    Likes Received:
    40
    I like this idea, gonna have to look for that thread.

    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.
     
  7. aristobrat

    aristobrat IPCT Contributor

    Joined:
    Dec 5, 2016
    Messages:
    2,205
    Likes Received:
    1,935
    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.
     
    darrenph1 likes this.
  8. darrenph1

    darrenph1 Getting comfortable

    Joined:
    Feb 10, 2017
    Messages:
    107
    Likes Received:
    40
    Good to know! Thanks.
     
  9. bp2008

    bp2008 Staff Member

    Joined:
    Mar 10, 2014
    Messages:
    8,764
    Likes Received:
    5,840
    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.

    [​IMG]

    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:

    [​IMG]

    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.

    [​IMG]

    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.
     
    darrenph1 likes this.
  10. tangent

    tangent IPCT Contributor

    Joined:
    May 12, 2016
    Messages:
    3,853
    Likes Received:
    2,516
    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 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.
     
    bp2008 and darrenph1 like this.
  11. J Sigmo

    J Sigmo Known around here

    Joined:
    Feb 5, 2018
    Messages:
    763
    Likes Received:
    786
    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. ;)
     
  12. darrenph1

    darrenph1 Getting comfortable

    Joined:
    Feb 10, 2017
    Messages:
    107
    Likes Received:
    40
    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: May 17, 2019
  13. aristobrat

    aristobrat IPCT Contributor

    Joined:
    Dec 5, 2016
    Messages:
    2,205
    Likes Received:
    1,935
    @darrenph1, how did the trial of Speedcam Traffic go?
     
  14. bp2008

    bp2008 Staff Member

    Joined:
    Mar 10, 2014
    Messages:
    8,764
    Likes Received:
    5,840
    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.

     
    aristobrat likes this.
  15. darrenph1

    darrenph1 Getting comfortable

    Joined:
    Feb 10, 2017
    Messages:
    107
    Likes Received:
    40
    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...