Experimental biological model system outcomes such as altered animal movement capability or behaviour are difficult to quantify manually. Existing automatic movement tracking devices can be expensive and imposing upon the typical environment of the animal model. We have developed a novel multiplatform, free-to-use open-source application based on OpenCV, called AnimApp. Our results show that AnimApp can reliably and reproducibly track movement of small animals such as rodents or insects, and quantify parameters of action including distance and speed in order to detect activity changes arising from handling, environment enrichment, or temperature alteration. This system offers an accurate and reproducible experimental approach with potential for simple, fast and flexible analysis of movement and behaviour in a wide range of model systems.
The majority of experimental in vivo surgical models or animals generated following genetic manipulation lead to physiological effects impacting behaviour and locomotion1. Induction of chronic pain or light sensitivity, for example, may represent a useful outcome in an experimental model of disease, but these behaviours are difficult to quantify without the aid of automated animal tracking devices and complex analytical systems. Such investigations are reliant on, and often limited by, the selection of an appropriate method of assessment.
Existing methods compromise between the quality of motion data collected, ease of setup of the chosen device and the overall level of throughput. Infrared movement sensors can be deployed for long periods of time with minimal supervision, but only provide low detail information about average rodent activity per home cage2. In contrast, use of multiple high-resolution CCD cameras provides high quality recording and analysis of movement such as the detection of subtle gait abnormalities, but this approach does not lend itself to high throughput analysis of mice3. Similar strategies exist to quantify insect locomotion at either the larval or adult stage, ranging from manual counting of grids crossed4 to automated counting of infrared beam crosses5 and automated video tracking6,7,8. Use of a dedicated filming stage for rodents or insects allows for clear detection but potentially disturbs normal behaviour while further increasing barriers-to-entry9, but may be necessary for detection of behaviours such as grooming10. Alternatively, filming natural movement in the home cage currently requires a dedicated computer and cage setup11. Established institutions which focus on small animal behaviour may invest in such complex systems, however there are few methods available for researchers without dedicated infrastructure to easily and flexibly test for reproducible changes in movement or behaviour.
Here we describe movement capture of small animals in their home environment, and analysis using a novel open-source OpenCV-based application called AnimApp. This system uses low-cost equipment which is easy to set up and mostly already available to the average animal researcher. The mobile version of the app, targeted at Android smartphones, is very simple to install and use, and does not require processing of files on a standalone computer, while a desktop (PC/Mac/Linux) version is also available for batch processing of videos from any digital recording device. We find that mice are highly active when using the home cage as a stage, meaning that this approach is fast (2 minutes per mouse) and results in reproducible detection of altered activity. AnimApp tracking of insect larvae movement and contractions further highlights the adaptability of this system for use with a wide range of animal model organisms and output criteria.
Results and Discussion
This research project demonstrates how an animal or object with sufficient background contrast can be digitally filmed and assessed using AnimApp, as depicted in the workflow example (Fig. 1). Three distinct experimental model systems common in laboratory and pre-clinical research (Drosophila melanogaster adult flies and larvae, white mice with added colour contrast, and black mice alone or in the presence of stimuli such as housing), were employed to develop and validate the application for use in assessing parameters of behaviour and activity in situ.
Recording with a smartphone was found to offer greater flexibility in recording parameters along with the availability of direct processing within the device through the AnimApp application. Alternatively, video files recorded by webcams or other cameras could be transferred and processed using the desktop version of AnimApp. Longer videos and larger datasets were analysed using the desktop version in order to take advantage of increased processor speed and batch processing. AnimApp quantifies total movement overall, as well as creating an individual record detailing the path taken, as well as animal size and shape at each frame. An overview of AnimApp function is depicted in Fig. 2a. Using the first frame of a video file, AnimApp allows the user to crop the image and set a scale of known size by dragging a rectangle over the image. Optimising and setting of colour threshold based on Hue, Saturation and Value (HSV) colour space (Fig. 2b) allows AnimApp to find the desired object within the field of view for path tracking (Fig. 2c). Common thresholding settings are pre-installed, while user-defined thresholding values can be loaded from the “Presets” menu (Supplementary Fig. 1a), and exported for sharing to aid in reproducibility. As AnimApp requires a HSV colour difference in order to detect an object over a background, careful experimental setup with respect to lighting, filming distance and video capture techniques are necessary. With ease of use in mind, we have developed our software to accept several video types as input. In dark environments, or for fast-moving small animals, other video sources such as infrared, night-vision, or high-speed digital cameras may be used, and the video files imported to computer or mobile device for analysis in AnimApp. However, all animal tracking presented in this paper was successfully performed with standard lab lighting and in-built mobile phone camera.
After frame-by-frame analysis, AnimApp generates a plot of the tracked object, with a slider allowing inspection of the path frame-by-frame through the video, and a measurement of total distance travelled to the frame selected. A comma-separated variable file (.csv file) named AnimApp_summary.csv provides a log of each analysis with the number of video frames, distance moved and scaling factor applied. AnimApp also generates a threshold settings log file (labelled Video.mp4.settings.txt) and an individual path file (Video.mp4.csv) containing information regarding the object at each frame (object centroid, frame number, and centroid, width and length of minimum rotated rectangle, described in Fig. 2d). This information can be further processed in other analysis software. A video of an adult Drosophila is provided as an example of simple animal detection and tracking in a standard clear glass tube as in the Drosophila ARousal Tracking system8 (Fig. 2e), with instantaneous object velocity calculated for path colour (Fig. 2f). Locomotion distance binning is available in app, and can be adjusted by selecting the bin size within the “Presets” tab (Supplementary Fig. 1a), and example output for this video are shown for bin width 10 and 25 (Supplementary Fig. 1b,c). This example Drosophila video file, a threshold preset file and an R script for calculation and display of path with velocity are supplied as Supplementary Files.
For rodent filming, home cages were opened and enrichments removed, before recording mice individually from a suspended smartphone (Fig. 2g). Prior to filming, mice were handled indirectly using a cardboard tube in order to reduce animal anxiety, as described previously12. For initial optimisation, black C57Bl6 and white NOD/SCID-GAMMA (NSG) mice were used. The strong contrast of C57Bl6 mice to the white bedding background allowed accurate detection directly, while the NSG mice required colour marking on the base of their tail with permanent marker to increase contrast before recording. Mice were primarily filmed in isolation in their own home cages, after removal of loose bedding and enrichment objects, leaving only chip flooring. When using the home cage as a recording stage, mice frequently displayed digging and searching behaviour, as well as rearing to the cage walls, but spent minimal time grooming or otherwise stationary. Mouse behaviour was notably altered when a clean empty transport box was used as a recording stage (tracked paths shown respectively in Fig. 2h). Drosophila larvae were placed individually on clear petri dishes containing 2% agar, over a black background (Fig. 2i,j). We have also tested and successfully tracked other insects such as ladybirds (Supplementary Fig. 1d,e), as well as animal features (Supplementary Fig. 2), indicating that AnimApp can be used to track a wide range of targets.
The length of each filming session for C57Bl6 mice was optimised to balance accuracy of measurement with time efficiency. Since the animals do not move evenly throughout a recording session, short videos are prone to high measurement variation. By taking a single 6 minute source video of each mouse, and splitting this into 3, 2, 1 and 0.5 minute segments, we analysed the coefficient of variation arising from different video durations. 2 minute sections produced less than 10% variation in movement quantification compared to the complete 6 minute source (Fig. 3a), which we considered acceptable, however less active animals may require longer video durations to achieve a similar level of accuracy.
To determine whether the activity of the subject mice changes as the animals become accustomed to the presence of the camera, movement quantification from the 1 minute segments of the source videos were assessed in chronological order (Fig. 3b), and indicated no significant change in activity level throughout filming. However, more consistent results are seen in the later minutes of recording, suggesting that shorter duration videos may be equally accurate if a period of acclimatisation to the recording stage is extended.
As the filming environment would be expected to alter rodent behaviour, 2 minute videos taken of C57Bl6 mice using a “standard” home cage were compared to those filmed in completely clean “empty” transport boxes of similar dimensions. Mouse behaviour was considerably altered in the empty transport box, evidenced by significant reduction in movement distance (Fig. 3c). This indicated that for quantifying maximum movement ability, the use of the animals’ own home cage as a recording stage is superior to an empty stage. However, experimental designs which focus on interventions to increase exploratory behaviour or confidence may find benefit in using a clean sterile recording stage. These findings indicate that our analysis system is capable of detecting subtle changes in behaviour arising from an altered environment.
Movement of individual NOD/SCID-GAMMA mice was analysed through repeat recordings over the course of 6 weeks to test reproducibility of movement for individual animals between filming days (Fig. 3d). Surprisingly, reproducible differences between cage-mates are detectable, suggesting subtle differences between each individual in baseline disposition to movement.
To test the flexibility of this method, our AnimApp system was used to measure behavioural changes in response to the introduction of an enrichment object to the home cage stage and direct animal handling (“scruffing”). Tracking of rodent interaction with novel objects has been described in open field tests9, while direct animal handling has been reported to have an effect on anxiety-related behaviour12. Mouse activity was measured for 2 minutes before and immediately after introduction of red transparent housing to the centre of the home cage, then removal of the housing was followed by the mouse being scruffed for 10 seconds, during which time the animal was held inverted to simulate an experimental procedure such as intraperitoneal injection. Filming then resumed for a further 2 minutes (Fig. 3e). Notably, the introduction of housing and the handling-induced anxiety both caused a reduction in total mouse movement. To further characterise mouse behaviour in each condition, the total percentage of time spent in the centre of the recording stage was also determined by detailed analysis of AnimApp path output (Fig. 3f), and revealed a significant attraction of the animals to the red housing unit. Further analyses of behaviour such as interactions with specific locations, local environments within the cage, or even interactions between two different animals are possible with careful analysis of output path files. This highlights how AnimApp can be used for quantifying behavioural changes in terms of overall animal activity, path taken and interactions made by each individual animal. As with any behavioural study, this quantification does not discriminate between the causes of such changes, so careful experimental design is required to interpret the results.
The AnimApp application was also investigated for use in the assessment of movement of individual Drosophila larvae in a petri dish, using 1-minute videos of larvae inside an incubator set at 19 °C or 37 °C. Overlaying output movement paths normalised to the starting location provided a method of readily visualising differences (Fig. 4a). Larval contractions, also known as strides, have previously been used as a measurement of locomotion behaviour6. By using the length and width of the larva throughout the recordings, larval contractions could be assessed (denoted by green line, Fig. 4b), followed by further processing to determine the mean amplitude of larval contractions (dashed line, Fig. 4b). Turning larvae can be detected by increases in the ratio of larval length to width (black line, Fig. 4b). The standard method of manually quantifying larval movement, by counting grid line crossing events (Fig. 4c) was compared to automatic locomotion quantification by AnimApp (Fig. 4d). Both methods provided similar results, showing significantly lower average movement in 1 minute for larvae incubated at 19 °C compared to 37 °C (p < 0.001 for both methods). AnimApp was much faster to use than manual grid counting, and more precise in detecting movement, resulting in a reduced variance of data points. Mean contraction amplitude was also significantly suppressed by 19 °C incubation (p < 0.001, Fig. 4e).
To explore tracking of multiple colour tags within a single video, we used AnimApp to analyse a video published previously for M-Track, an app designed to detect grooming behaviour in mice10. The video shows a white mouse with paws labelled with red (right paw) or blue (left paw) colouring. By running the video on AnimApp with appropriate thresholding for different colours, individual detection of each paw and the whole mouse body were successful. In comparison to the published results by M-Track, AnimApp produces accurate results showing very similar patterns of motion for each paw (Supplemental Fig. 2).
The AnimApp software provides a novel technique for the low-cost analysis of movement and behavioural responses in small animal research, using model organisms ranging from rodents to Drosophila. AnimApp outputs the total distance movement and time of the input video, frame-by-frame location of the subject, along with width, length and angle information with scaling to convert pixel distances to millimetres. Further analysis of path is flexibly performed using software such as R, example scripts for which are available in the Supplementary Methods. Using a home cage filming stage, AnimApp was able to detect subtle changes in mouse activity arising from the introduction of an enrichment object, manual handling, and even baseline variation between individual animals. The use of a home cage as a recording stage was also shown to increase activity in rodents, allowing for sensitive detection of any reductions in maximal animal activity. The shape of the detected animal can be further analysed to give information about strides and turning, particularly when using a model organism with a consistent dorsal profile, such as Drosophila larvae, while creative camera and recording stage setup could allow for quantification of movements in other axis directions, such as burrowing or rearing. AnimApp allows for the combination of recording and activity processing in a single smartphone or tablet, providing a fast and easy measure of activity, while further post-processing can be performed with the detailed path output files generated in AnimApp.
Tracking of multiple animals or animal features within the same video is a difficult problem, particularly in animals such as mice that frequently cross paths with one another. Other software have devised methods to track multiple animals13,14,15. The motivation of the current work was to provide a mobile device-based user-friendly interface without a steep learning curve or complex software dependencies, while being able to track individual movement accurately. However, we show that animal parts tagged with distinctly different colours can be accurately tracked, giving comparable results to dedicated software10. Such a method could in principle be extended to track multiple animals in AnimApp by marking each with unique colours, and processing for each colour individually in AnimApp. Merging this resulting data could provide an accurate analysis of multiple animal paths in the same video.
Potential indications for the AnimApp assessment approach include disease or genetically modified models, quantification of movement ability as a surrogate for pain, attraction or repulsion to food or other chemicals, light sensitivity or general anxiety. The raw path output also allows for quantification of attraction or repulsion from sources, and for further detailed mapping of movement path, for example if used with a maze filming stage. However, animal activity can be altered positively or negatively by both noxious or enriching stimuli, so interpretation of any results must take into account experimental design and comparison to other established complementary methods.
This study describes the development and validation of a new, free-to-use open source program aimed at reducing researcher time, improving experimental design and refining current techniques common in preclinical model studies assessing behaviour and activity outcomes. The incorporation of the AnimApp program into commonly used hand-held devices offers a reliable, cost effective and minimally invasive approach to the study of a variety of experimental model systems, in particular those where alterations in movement are indicative of specific causation, e.g. pain, neurological disease, muscle weakness.
Equipment and Methods
All animal experiments were conducted in accordance with the Animals Scientific Procedures Act of 1986 (UK) under UK Home Office Project License 30/2996 and PCCCC8952. Protocols were approved by the Animal Welfare and Ethical Review Body of the University of Oxford.
C57Black/6 (C57Bl6) and NOD/SCID-GAMMA (NSG) mice were routinely housed in individually ventilated cages in adherence to Home Office guidelines. Mice were transferred between recording stages and transport boxes without direct handling, by use of a cardboard tube. All Drosophila used were of isogenic background (iso31). To collect L3 larvae, 20% sucrose solution was poured into vials containing iso31 larvae, and after 15 minutes of incubation, floating L3 larvae were collected, washed with distilled water, gently dried, and placed onto petri dishes containing 2% agar. These petri dishes were then placed into incubators at the desired temperature.
Videos were filmed using an Android mobile phone, at 1920 × 1080 resolution, 29 frames/second (rodents) or at 640 × 480 resolution, 15 frames/second (larvae), using the open-source Open Camera Android app. Where necessary, video resolution was reduced, or audio removed from recorded video using ffmpeg v2.8.14-0ubuntu0.16.04.1. The camera or mobile phone was mounted on a flexible “Gooseneck”-style mounting arm with spring clamp, for easy positioning. In cases where poor contrast was expected between the animal and the background (e.g., a white mouse), coloured Sharpie permanent markers were used to make a 0.5 cm long mark at the base of the tail. A 30 cm ruler was placed in the video to give a scale measure for conversion of pixels to centimetres.
Video files in a common format such as MP4 or AVI were read frame-by-frame using a Python (desktop) or Java (Android) framework (leveraging the OpenCV16 or JavaCV17 libraries respectively). Each frame was then thresholded by HSV values provided by the user at the command-line (desktop) or using a graphical user interface (Android). From the thresholded frame, contours were identified (OpenCV uses the method developed by Suzuki et al.18 internally) and the position and dimensions of the largest contour were recorded in a comma separated variable (CSV) file for plotting and further analysis. Euclidean distance between consecutive points was calculated as follows and summed to give the total distance travelled.
(x1, y1) – initial location of the object.
(x2, y2) – location of the object in the consecutive video frame.
All source code used for this video analysis are freely available for download. The code can be downloaded from https://github.com/sraorao/animapp_desktop for the desktop version (also available as a pre-packaged Docker container for the Ubuntu platform), and from https://github.com/sraorao/AnimApp for the Android version. Instructions for installation are provided in Supplementary Data and at the respective web pages. AnimApp Android is also available for free installation via the Google Play store at https://play.google.com/store/apps/details?id=com.oxford.srao.animapp. Android app output (.csv) and settings (.txt) files are generated within the internal storage “Download” folder, for ease of location.
Post-processing of movement paths was performed using R and visualised with the ggplot2 package19,20, with colouring relating to animal velocity or larva length (see Supplementary Data Files). Instantaneous velocity was calculated as an average of distance travelled per 10 consecutive frames, equivalent to 333 ms. R scripts for calculating and plotting these variables are provided as Supplementary Files. For manual quantification of larval movement, the same videos that were analysed automatically were loaded on a desktop computer and a semi-transparent grid was overlayed on top. Events of larvae passing through a grid line were counted, in a method reflecting the current standard assay for locomotion in larvae4. For larval contraction analysis, the largest dimension of the identified contour was considered the length of the larva, and the ratio of the largest and smallest dimensions was used to distinguish movement-related contractions (strides) or changes in direction (turns).
All statistical tests were performed in R 3.4.219. Comparison across two groups was performed using Unpaired Student’s t-test with Welch’s correction, and using ANOVA followed by Tukey’s test for multiple comparisons.
Tappe-Theodor, A. & Kuner, R. Studying ongoing and spontaneous pain in rodents - challenges and opportunities. Eur. J. Neurosci. 39, 1881–1890 (2014).
Tang, X., Orchard, S. M. & Sanford, L. D. Home cage activity and behavioral performance in inbred and hybrid mice. Behav. Brain Res. 136, 555–69 (2002).
Sheets, A. L., Lai, P.-L., Fisher, L. C. & Basso, D. M. Quantitative Evaluation of 3D Mouse Behaviors and Motor Function in the Open-Field after Spinal Cord Injury Using Markerless Motion Tracking. PLoS ONE 8, e74536 (2013).
Nichols, C. D., Becnel, J. & Pandey, U. B. Methods to assay Drosophila behavior. J. Vis. Exp. JoVE 3795, https://doi.org/10.3791/3795 (2012).
McParland, A. L., Follansbee, T. L. & Ganter, G. K. Measurement of Larval Activity in the Drosophila Activity Monitor. J. Vis. Exp. e52684, https://doi.org/10.3791/52684 (2015).
Aleman-Meza, B., Jung, S.-K. & Zhong, W. An automated system for quantitative analysis of Drosophila larval locomotion. BMC Dev. Biol. 15, 11 (2015).
Slawson, J. B., Kim, E. Z. & Griffith, L. C. High-resolution video tracking of locomotion in adult Drosophila melanogaster. J. Vis. Exp. JoVE 1096, https://doi.org/10.3791/1096 (2009).
Faville, R., Kottler, B., Goodhill, G. J., Shaw, P. J. & van Swinderen, B. How deeply does your mutant sleep? Probing arousal to better understand sleep defects in Drosophila. Sci. Rep. 5, 8454 (2015).
Samson, A. L. et al. MouseMove: an open source program for semi-automated analysis of movement and cognitive testing in rodents. Sci. Rep. 5, 16171 (2015).
Reeves, S. L., Fleming, K. E., Zhang, L. & Scimemi, A. M-Track: A New Software for Automated Detection of Grooming Trajectories in Mice. PLOS Comput. Biol. 12, e1005115 (2016).
Tungtur, S. K., Nishimune, N., Radel, J. & Nishimune, H. Mouse Behavior Tracker: An economical method for tracking behavior in home cages. BioTechniques 63, 215–220 (2017).
Hurst, J. L. & West, R. S. Taming anxiety in laboratory mice. Nat. Methods 7, 825–826 (2010).
Pérez-Escudero, A., Vicente-Page, J., Hinz, R. C., Arganda, S. & de Polavieja, G. G. idTracker: tracking individuals in a group by automatic identification of unmarked animals. Nat. Methods 11, 743–748 (2014).
Sridhar, V. H., Roche, D. G. & Gingins, S. Tracktor: image-based automated tracking of animal movement and behaviour. bioRxiv 412262, https://doi.org/10.1101/412262 (2018).
Rodriguez, A. et al. ToxTrac: A fast and robust software for tracking organisms. Methods Ecol. Evol. 9, 460–464 (2018).
Bradski, G. The OpenCV Library. Dr Dobbs J. Softw. Tools (2000).
Audet, S. JavaCV. Available at, https://github.com/bytedeco/javacv (2018).
Suzuki, S. & Abe, K. Topological structural analysis of digitized binary images by border following. Comput. Vis. Graph. Image Process. 30, 32–46 (1985).
R Core Team. R: A Language and Environment for Statistical Computing. (R Foundation for Statistical Computing, 2017).
Wickham, H. ggplot2: Elegant Graphics for Data Analysis. Media 35, (Springer, 2009).
The research was supported by the National Centre for the Replacement, Refinement and Reduction of Animals in Research (NC/M000133/1) and Arthritis Research U.K. Career Developmental Fellowship (20631) (J.R.E.).
The authors declare no competing interests.
Publisher’s note: Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.