Panning shots are easy

It’s been some time since I last wrote a blog post. A couple of weeks ago I went to Marrakesh, whilst I was out there I tried to take some panning shots of the Moroccan traffic.


Panning shots are where you take the photo whilst rotating the camera to track a moving object. This should blur out the background of the shot whilst keeping the moving object in focus. The shot is great for giving a sense of movement and dynamism whilst keeping the detail of the moving object.

The key for getting a good panning shot is patience and plenty of subjects. You don’t need a special camera, simply one where you can control the shutter speed. The best way to practise panning is to find a seat set back from a busy road. Depending on the speed of the traffic and the distance away from the camera you will need to choose a shutter speed between 1/5 to 1/50th of a second. There is no simple rule, you will need to experiment with different shutter speeds to get the best outcome.

In bright sunlight, such as in Morocco you might need to use a filter to prevent saturating the camera sensor at such slow shutter speeds. I use a very cheap variable neutral density filter which allows me to get a 1/10th of a second shutter speed with an aperture of f/8 in bright light. If you can’t get hold of a cheap folder you can simply wait for the light levels to go down.

Following a moving target is the hardest part of taking this type of shot. Some cameras will help you by giving you panning  image stabilisation. You need to rotate the camera steadily, to do this you need to start tracking the subject when it is as far away as possible. Make sure you are smoothly tracking it, before pressing the shutter and try not to press the shutter with too much force such that you introduce camera shake. Some photographers use a tripod or monopod to get the smoothest pan however a tripod head with a smooth movement can be quite expensive.

To get the whole of the subject in focus, you need to press the shutter release when it is travelling perpendicular to the camera lens. If the object is moving at an angle to the lens you will likely get some parts in focus and others out of focus. You can see this effect in the photo below.

The reality is that luck plays a huge part even amongst experienced photographers. I took about 100 photos to get the 5 images I’ve posted here. It’s quite likely that 90% of your photos will be blurry but with enough patience you should get some great shots.




Disappearing Time

Time seems to disappear so quickly and I always have so many things to do. I get ready for work, go to work, come back from work, go swimming, go shopping, cook, eat and wash up dinner, watch the news, write an entry on my blog, read a bit of my book and go to bed.

I seem to need a lot more time. I’d like some time to work on my side projects, some time to make and write Christmas cards. What I’m probably not very good at is prioritising. I’m writing this blog post when I could be doing something more important. Never mind, there’s always tomorrow!

Fake owls

Today whilst I was out I thought I saw an owl. The owl appeared to be sat on top of some high voltage wires in the railway substation. I took a couple of photos with my phone, a train came past, and the owl hardly moved. I got a bit suspicious so I went on Google Street View to see what the owl was actually sitting on and this is what I saw:

The owl is of course a complete fake. It’s there to deter other birds from sitting on the wires in the substation which could lead to them shorting out the power.

In my defence it was getting quite dark so I couldn’t see the fake owl very clearly. Next time I’ll just look out for the foxes, they’re definitely real.

Training Schedule

I’m starting to get back to fitness. I’m able to run at a moderate pace for 10 miles but I’m still lacking my old strength and endurance. I need a proper training schedule to ensure I’m going to be ready for my marathon in just 4 months time.

Here’s what my schedule looks like:

Monday: Swimming for 1 hour, running every day is not a good idea and a swim is great for stretching and endurance.

Tuesday: Reps run with Worthing Harriers, this is typically hills, fartleks or some other sort of reps session.

Wednesday: Rest day, I will probably use this for a shorter run as I get into 2016. Use Wednesday to do strength work at home working on the core and upper body.

Thursday: Moderately long run with Worthing Harriers, this is typically a 8-11 mile run around the streets of Worthing.

Friday: Long afternoon run if possible, I get the afternoon off work on a Friday so I need to try and use the light in the afternoon to go for a run going into the countryside.

Saturday: Race (if there is one) otherwise short tempo run. Need to run 10+ miles at race pace starting around 8 minute miling upping to 6:30 miling by March time.

Sunday: Morning long run with Worthing Harriers, I need to start around 12 miles, upping this to 20+ miles in March.

That’s my plan and I will try to stick to it as close as possible from now on (eek).

Level crossings part 2

Two weeks ago, I discussed an outline of how to predict when then level crossing near my flat is open or closed. I made an aside that I could use a camera to detect when the crossing is open or closed.

I’ve realised that I have an old tablet that will work great for this purpose. I can put it on the windowsill plugged into it’s charger and use it to report back on the level crossing.

Now I just need to implement the technology to make that happen. I’ve got two choices here: it’s a windows based tablet so I can create an executable using something like openCV or I can create a browser based application.

A while back I started doing a project which relied on HTML5 to do some basic image recognition. I’ve decided I’m going to try that approach again because it makes my solution so easy to port. If I get a new device, as long as it runs the Chrome web browser then it should be able to do the exact same task. The development also requires only two really simple tools, the browser and a text editor to write code in.

Here’s the plan of attack:

  1. I’m going to create a page with a HTML5 video element and a 2D canvas element
  2. The video from the device’s camera is set to be the source of the video
  3. At fixed time periods the video is copied into the canvas
  4. Once an image is loaded into the canvas, the individual pixels can be read
  5. The pixels are read in an intelligent way to determine if the level crossing lights are flashing or not.
  6. This data is sent to the server

The first four steps are fairly trivial to implement once you know what you are doing. The fifth step is where the magic happens.

This image recognition task is actually quite simple. Determining if a light is on or off is a simple task. What makes the task more difficult is the fact that the lights are sufficiently far away from my flat that they are quite small, they are also right behind a set of traffic lights and the lighting conditions change dramatically throughout the day.

My first approach is to try to resolve the barrier lights from the traffic lights. Its just about possible with the camera on the tablet. I simply need to compare the red value of the point where the lights are against the red value of another reference point just to the side of the barrier lights. I need to make sure I choose this reference point such that it is always darker than the lights no matter what the illumination conditions.

Now I just need to set the camera very still on my windowsill!

I set the webpage to requests a PHP page whenever the state of the crossing changes. The PHP page updates a MySQL database. I’ve then created another simple PHP page which reads the data from the database and displays a pretty graph. In my third post I’ll report on my data findings.


It’s the first of December so it’s time to get out the advent calendar. I’m not a huge fan of the “traditional” advent calendar. What’s the point of tiny poor quality chocolates? If I wanted the chocolate I wouldn’t buy it in over-priced calendar form.

I do have a more contemporary advent calendar. I’m participating in the Advent of Code. Instead of chocolates, two puzzles are served up each day which must be solved using code. The challenges are all Christmas themed and are (at least so far) fairly easy and fun. Even a programming beginner could have a go, it’s a great way to get started.

Great cities

Yesterday I went to a talk about the mathematics of relationships and why people congregate in cities. The speaker argued that the average probability of two people having a relationship (any sort of relationships: client, employer, lover, friend…) is inversely promotional to the number of people in their social sphere. His definition of a social sphere was the people that are located in the area which you can travel to in less time than the other person.

The main point that came out of the talk is that distance in terms of time is more important than real distance. The best cities are those with a good transport network which allow many opportunities for relationships.

The talk explained why over 50 million people migrate to cities each year. Cities offer so many more potential relationships than the surrounding population.

I’d like to look into this topic in closer detail but I’m on holiday at the moment.

Science vs engineering

This evening I went to an event at the London Science Museum. Once a month they open the museum in the evening and put on special guests, talks, activities and alcoholic drinks.

It was a great evening with some interesting talks and some fun activities. What really struck me was the gender balance. I would (non-scientifically) estimate that just over 50% of the visitors were female. For me this seems really unusual as I’m used to men easily outnumbering women in all the engineering I’ve ever been to.

At university, about 25% of the engineers were female, at work less than 10% of the engineers are female. In fact government statistics say that only 6.9% of all professional engineers are female.

So is science really that different? Well yes in terms of the statistics. 40% of science professionals and researchers are female and the Science Museum say that 48% of their visitors are female.

I’d like to find out what is causing this huge difference, there is such a big overlap between modern science and engineering. Clearly, from the turnout at the Science Museum this evening, women really enjoy learning about science. I wonder what would happen if it were renamed the “Engineering Museum”.


In the soft evening light I took this image of a seagull standing above the surf. The cold weather has some benefits, more sunny evenings. I believe this is a great black-backed gull. I also managed to capture some other gulls:

Little gull
Little gull
Black-headed gull
Black-headed gull

Actually it turns out that telling gulls apart isn’t easy (those both might be black-headed gulls or little gulls)

Xmas game part 1

I like to do something special for Christmas. Most years I make my own custom Christmas cards. 5 years ago I produced a small game to celebrate and I want to try producing a Christmas themed game again.

Step one is to come up with a concept. I’ve spent a while thinking about this, the game needs to fulfil a few criteria:

  • It needs to be simple enough that I can implement it in a few days
  • The animation needs to be really simple (I have no real animation skills)
  • The game needs to be accessible, suitable for all ages and abilities to play
  • It needs to be fun
  • It needs to have some link to the festive season

After studying a few different types of games and thinking very hard about how I can produce a game I came up with the following idea. A platformer which involves a polar bear jumping between platforms. The game ends when the bear ends up in the water. Points are scored for each jump successfully completed between platforms. The game starts off easy with small gaps and large flat platforms. As the game progresses the gaps get larger, the platforms become smaller, inclined and slippery. The image at the top of the post is my first drawing of the concept.

The next step splits the game into two parts: the game mechanics and the styling. The game mechanics includes all the physics, rules and controls of the game whilst the style includes all the animation of the objects and all the different images and textures needed. Once these two parts are completed we can integrate them and test out the game.

I’m going to start with the game mechanics. There are two objects in this game: the polar bear and the platforms. The platforms will scroll horizontally to give the apparent forward (or backward) motion of the bear whilst the bear will move vertically to give its vertical motion.

There will be 3 inputs to the game, one input will make the bear run faster (accelerate), one will make the bear run slower (decelerate) and one will make the bear jump. The longer the jump control is held down the more powerful the jump. The jump is commenced as soon as the jump control is released.

I can now start putting together the equations to model the behaviour of the bear object. The bear has 4 parameters: horizontal and vertical displacement sx and sy and horizontal and vertical velocity vx and vy. At regular intervals (say 50 times per second) the forces on the bear are calculated and this affects the velocity parameters. The velocity parameters are then used to update the displacement parameters. Once the new displacement parameters are known, collisions can be detected. I’ll come back to collisions.

First lets look at the forces on the bear. When in the air there are two forces affecting the bear: gravity and air resistance. Gravity always acts only on the vertical component and has a constant effect of magnitude g (gravitational acceleration). Air resistance acts proportionally to the velocity of the bear in the direction opposite of the velocity. We can easily split this into a vertical and a horizontal component.

This gives us our two equations:

vxn+1 = a * vxn

vyn+1 = b * (vyn – g)

where a is the horizontal aerodynamic parameter, b is the vertical aerodynamic parameter and g is the gravitational parameter. (a and b can be the same or can be different to give slightly more adjustable physics)

When on a platform there is a further force from the player controlled acceleration/deceleration. We also need to consider the effects of slippery surfaces. The amount of friction between the bear and the surface limits the force in the direction of the surface of the platform.

We can model this as a velocity in the direction of the surface of the platform.

vsn+1 = c * (vsn – g * sin(θ) + d * cos(θ) + e)

where c is platform aerodynamic parameter and d is the friction parameter and e is the player controlled acceleration parameter.

Finally we have a force from jumping, since a jump is instantaneous we simply add an amount of velocity depending on how long the jump control has been pressed for. The jump is always normal to the surface of the platform.

It’s very difficult to give exact numbers for each of the parameters. The parameters give the game it’s feel. We can give more or less gravity, make the bear faster or slower, make the bear more or less responsive and the platforms more slippery. To get a feel for where the game feels right requires some testing.

Finally we have collision detection. If we are currently on the platform we are testing for whether the bear has gone off the edge of the platform. If we are in the air we are testing for if the bear has hit anything. We test if the bottom edge of the bear bounding box has hit the water or the top of a platform and we test if the right hand edge of the bounding box has hit the side of a platform. Only in the case where the bear hits the top of the platform does the game continue. The velocity of the bear in the direction of the surface of the platform is set as the new velocity with the normal component discarded.

This translates to quite a number of rules and equations but put them all together and you get this demo. The platforms are the red objects, the bear is the yellow object. The arrow keys control the acceleration/deceleration and the space bar makes the bear jump. It’s not the finished article by any means but it gives a framework to start from.

Next time I’ll be looking at producing the graphics for the game especially the animation of the bear.