The analysis of animal locomotion is critical for characterizing and ultimately understanding behaviour. While locomotion quantification of single animals is straightforward, simultaneous analysis of multiple animals in a group is challenging. If performed manually, such analyses are labour-intensive and potentially unreliable, thereby necessitating the use of machine vision algorithms for automatic processing. Machine vision algorithms need to reliably label each animal and maintain all animal identities throughout the video-recorded experiment. This allows detailed characterization of behaviours such as taxis, locomotion and social interaction. In this study, we present an algorithm for analysing the locomotion behaviour of the fruit fly Drosophila melanogaster, a popular model organism in neurobiology. Our algorithm detects all flies inside a circular arena, determines their position and orientation and assigns fly identities between consecutive frame pairs. Position and orientation of the flies are accurately estimated with average errors of 0.108 ± 0.006 mm (approximately 5% of fly body length) and 2.2 ± 0.2°, respectively. Importantly, fly identity is correctly assigned in 99.5% of the cases. Our algorithm can be used to quantify the linear and angular velocities of walking flies in the presence or absence of various behaviourally important stimuli.