October 3, 2016
A while ago I was asked to take a look at a video, recorded on a rear-facing camera, of a close pass by a lorry driver to see if I could estimate how close the lorry came to the bike and its rider. I’ve done this a couple of times before and I figured it might be worth writing up the process.
Step 1: extract an image
The first step, of course, is to watch the video and extract a suitable frame. It needs to be one which shows the vehicle in the process of passing, but which also shows enough of the vehicle to be able to draw construction lines around it. Fortunately, the size and shape of HGVs make this rather easier than for smaller and curvier vehicles. This is the frame I used in this case: the cab is clearly alongside at this point, but a considerable length of the chassis remains in view.
Step 2: correct for distortion
Most action cameras and evidence cameras have rather wide-angle lenses that exhibit significant distortion. For most purposes this isn’t a big deal, but measurement is best done with straight lines, so it’s important to try and straighten any curves. You can check straightness by drawing straight lines over the top: it’s far easier to spot shallow curvature this way than it is to eyeball it in isolation.
Ideally, you’d calibrate a camera by recording an image of an orthogonal grid, and then establishing a transformation in your preferred image editing application (most of which should allow you to save the process as a macro or somesuch) which converts the recorded image to its true orthogonal state. If you’re looking for a grid, a brick wall may well be an adequate test card.
But simply correcting for barrel distortion (which is where straight lines appear to bow out towards the nearest edge of the image) should be good enough for most purposes. You can do this in Photoshop, Paintshop or whatever, but just play with the level of correction in whatever tool you have until you can draw decently-fitting straight lines over pretty much everything that should be a straight line.
After a little trial and error, here’s my corrected version of the above image. It’s not perfect—if I was doing this relatively often with my own camera I’d spend time calibrating it with a grid—but the lines which head to the vanishing point (ie the kerb and the lines running along the side of the lorry) are straight, which is the main thing for this purpose.
Step 3: draw construction lines
The next step is to draw construction lines on the image. I would recommend using a vector illustration tool; if you don’t have one, Inkscape is free and works well.
First, draw lines running along the length of the vehicle, extended to a common vanishing point. Draw several, in order to minimise errors.
Next, draw lines running along the road, again extended to a common vanishing point. This is a little trickier, as roads aren’t dead straight, but in many cases they’re not far off—at least over the distances that we need for this purpose. You want the lines to be close to parallel with the nearfield, and worry less about the road in the distance.
Again, draw several if you can, to minimise errors: here I’ve used the drain cover as an additional guide. Some of these are going to be used for measurement, though, so at the very least you’ll need two lines which represent the edges of something that you can measure or estimate: typically, that means a line at each edge of the lane. Here, that means the centre line of the carriageway and the bottom edge of the kerb.
Note that the vanishing point is not necessarily in exactly the same position as that of the lines from the vehicle (though it may be). That’s not a mistake. In fact, it suggests something: in this case, that the lorry may still be moving out slightly; in other words, the point at which it will be furthest from the kerb is actually beyond the cyclist. That’s pretty common: it’s due to people underestimating the time to reach a more slowly moving object ahead. Anyone who’s ridden on the road will have experienced it, and it’s been dubbed an “aftertake”. Naturally, had the two vanishing points been swapped left-to-right, it would have suggested that the lorry was moving back towards the kerb at this point.
Next is the slightly trickier bit. In the following image, the following lines have been added:
- a magenta line marking the vertical rear edge of the vehicle body
- a yellow line marking a line across the road, perpendicular to the road itself, where the rear tyre contacts it (ie immediately below the axle) running from the carriageway edge to the centre line (ie the width of the lane)
- a magenta line which runs parallel to the previous vertical construction line and passes through the top and bottom of the wheel rim (or, because the body overhangs the wheels) very slightly to the right of it
- a green line which runs from the road vanishing point through the intersection of the two previous lines; this represents the imaginary line on the road which lies immediately beneath the edge of the vehicle body
These lines are a little prone to error, and a diligent approach would calculate the most extreme positions at which these lines could reasonably lie.
The yellow line is the main thing that we’re looking at. Its length represents the width of the lane, but it is bisected by the green line beneath the edge of the vehicle.
This means that if we know the width of the lane, we know the distance of the vehicle from the kerb, which is the width of the space afforded to the cyclist.
Unusually, this image also shows the rear wheel of the bicycle, meaning that using the vanishing point of the road (which assumes that the bicycle is moving parallel to the road, but this can be confirmed by watching the video) we can draw a line through the centreline of the bicycle, noting the point at which it intersects the yellow horizontal line.
Now that we have our construction lines, we can start measuring things.
Step 4: make image measurements
The yellow line becomes our main focus. It represents a line across the lane, perpendicular to it, with the following pertinent distances measurable in relative terms:
- AD, the width of the lane
- BD, the distance of the vehicle from the nearside edge of the carriageway
- BC, the distance of the vehicle from the centre line of the bicycle
By measuring the lines in the drawing application, we can find the following (ignoring units, as we’re only interested in relative proportions at this stage):
- AD = 424
- AB = 287
- BD = 137
- BC = 68
- CD = 69
At this stage we have something useful, in that we can express everything in relative terms, but in order to make a useful statement about how close the pass was, we need to know what at least one of those equates to in the real world. Normally this will only be possible for distances between two fixed points, the only instance of which in this case is AD, the lane width.
If we express the other measurements in terms of AD,
- AB = 287 = 0.677AD
- BD = 137 = 0.323AD
- BC = 68 = 0.160AD
- CD = 69 = 0.163AD
Step 5: obtain a real-world measurement
One way of measuring the lane width would be to visit the scene with a tape measure. That’s not always possible to do safely, or indeed at all, of course. So we need another way.
In this case, we can derive it from another known measurement. We’re going to use the width of the HGV.
Here’s a frame from slightly earlier in the video, showing the full width of the lorry. Again, we draw construction lines along the road meeting at a common vanishing point, then the yellow line across the lane where the wheels meet the road, and finally two vertical magenta lines marking the sides of the cab at the front axle. Again, this last part has some room for error, particularly at the offside of the vehicle, and a diligent process would not only establish the possible extremes but repeat the measurement using multiple images.
We can find the physical width of the vehicle easily enough: it’s a Daf CF, and the front axle width is 2.55m. This equates to the distance between the magenta lines, which measures 213 units in our image (note that the front hubs sit proud of the tyres, and the magenta lines above are placed to reflect that). This means we can figure out the length of the yellow line, which is 319 units long in the image.
We arrive at a lane width of 3.82m.
Step 6: derive the remaining real-world measurements
Of course, that lane width of 3.82m is (assuming a constant lane width over this short distance) AD. Hence, if AD is 3.82m,
- AB = 0.677AD = 2.59m
- BD = 0.323AD = 1.23m
- BC = 0.160AD = 0.61m
- CD = 0.163AD = 0.62m
So the HGV is roughly 1.23m from the kerb and 0.62m from the centre line of the bike.
The final step is to determine the HGV’s distance from the rider, which involves measuring the width of the rider on the bike. In this case, that’s 0.56m, so we subtract half of that from the centre line distance.
We’re left with 0.34m (about 13 inches). That’s pretty close for such a large vehicle, especially at a reasonably high speed.
As I’ve noted, there is some potential error in the above figure but, if required, with some more work it would be possible to state a range of potential values with greater confidence. If greater accuracy were required then the routes I’d take to reduce error would be:
- to calibrate the camera properly with a test grid to give the best possible rectilinear images to start from;
- where lines are unclear (the vertical lines are the most susceptible to error), to make measurements at the extremes of what is viable to give a range of errors;
- to repeat the measurements using multiple frames; and
- to take measurements at the scene if possible.
In this case, I’m a little wary of the lane width measurement: 3.82m is quite high. If the lane were a standard 3.65m width, we’d have ended up with a passing distance of about 30cm. Ideally, I’d pay the road a visit at night when no traffic was passing and whip out a tape measure.
If you ever do need to give evidence to the police then video footage can obviously be fairly compelling. But if you do need to confidently provide numbers then it does take a little work to calculate them, and it helps to have images that lend themselves to that process. There’s an element of luck here: the straighter the road and the larger the vehicle, the more you have to work with, but you can give yourself a better chance of usable footage if the camera is well-mounted, with visibility of the road in the nearfield.
Hopefully, though, you’ll never need to do this at all.