Photo Speed Radar – Set Up, Operation, and Analysis

This is the final part of a four part series describing this project. This “home made” system consists of a Raspberry Pi 3, Model B with attached camera and telephoto zoom lens and a Bushnell Speedster Radar Gun adapted to input doppler pulses to the RPi 3. All of this has been described in the previous parts. How to use the system and its results is described here.

Set Up

Operation

Analysis

Speeder Example

Conclusion

Set Up

Once a location where the unit will operate is chosen, the intial set up is mostly a one time effort. Reference to the following image helps understand what needs to be done.

Setting Up the System

The telephoto zoom lens magnification setting defines the field of view as well as the ability to read license plates. High magnification will increase license plate readability but the more limited field of view may not capture images of vehicles going in both directions. The right compromise needs to found by trial and error. The short video demonstrates an acceptable setting.

Field of View

Note the car is mostly centered in the field of view. Experimentally this was determined to be the third measurement cycle. Which measurement cycle at which this occurs is needed by the code (see previous part three).

Operation

Focusing the telephoto zoom is somewhat tricky since a precise focus is sensitive to very slight rotations of the lens adjustment. Since the unit is normally operated “headless” via SSH, the trial and error focus process is thus: take a still image, SCP image to host computer, view image and make small adjustments to focus, then repeat.

Setting the Pi camera shutter speed is the next most important item. Auto exposure must be disabled and a shutter time between 200 and 400 microseconds was found to function well. The speed of vehicles would blur the readability of license plates otherwise. To accomplish these settings v4lt-utils must be installed on the RPi 3 and the tool v4lt-ctrl run as follows for the case of 200 microseconds:

v4l2-ctrl --set-ctrl=auto_exposure=1
v4l2-ctrl --set-ctrl=exposure_time_absolute=2

Finally, the radar gun is operated continuously by putting in place the jumper described in part two, Description of Hardware. The executable described in part three, Description of Code is then run. The images of vehicles collect in the same directory of the executable.

Analysis

A large number of saved images will result, all in chronological order.

Saved Images

All relevant information is contained in the file name. Therefore, the use of shell file tools along with a small custom written program produced a script that performs some useful analysis.

  1. A file of all speeds. This is useful for doing statistical analysis on the speeds for the time period observed.
  2. A file of all speeds greater than 32 MPH. Similarly useful for analyzing the statistics of speeders. In a 25 MPH zone common for residential streets this threshold is typically used to define a speeder.
  3. A directory of “speeder” images. Typically, one wants to save the speeder images. Putting them in their own directory allows for the original directory of all images to be bulk erased.

The script and its components are shown below for whomever may wish to use them. First, get_speeds.sh

#!/bin/bash

ls *.png > file
sed 's/-/ /g' file | sed 's/.png//g' |  awk '{print $7}' > speeds
./read_file
./move.sh file_speeders

Next is read_file.cpp , which is compiled to produce read_file

#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>   /*atof*/

using namespace std;

int main() {

    string line;
    string filename;
    ifstream in("speeds");
    ifstream file_in("file");
    ofstream file_out("file_speeders");
    ofstream out("speeders");
    float speed;

    while(getline(in, line)) {
        speed = atof(line.c_str());
        getline(file_in, filename);
        if(speed > 32.0){
           out << line << endl;
           file_out << filename << endl;
        }
    }
    out.close();
    in.close();
    file_in.close();
    file_out.close();
}

Finally, move.sh

#!/bin/bash

filename="$1"
while IFS='' read -r line || [[ -n "$line" ]];
do
    name="$line"
    cp $line Speeders/
done < "$filename"

Speeder Example

Picked as an example is that of a driver who each day speeds down the street (which is down hill) well over the speed limit around the same time of day.

Speeder “Poster Child”

What is interesting with photos such as this one is the distortion in the direction of vehicle movement (note oblong wheels, long axis along a one to 7 o’clock direction). The shutter time is 200 microseconds and in that time the pixel scan, starting on the bottom, progressively rises to the top as the vehicle in that time moves a bit to the right, creating the distortion. The camera is mounted upside down, so apparently if the camera were mounted upright, the distortion would be opposite (long axis along a 11 to 5 o’clock direction).

Conclusion

This completes the four part series of Photo Speed Radar, which describes the project in considerable detail. A radar speed camera was made that performs well. It captures license plates and documents them with speed along with date and time of day. A maximum of a few hundred dollars was spent on the principal elements of the system. Required to get this done was hacking the radar gun, using an RPi 3 with a camera equipped with a telephoto zoom lens, developing some simple circuitry to interface the radar gun to the RPi 3, and writing code.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *