Small Animal Video Tracking for Activity and Path Analysis Using a Novel Open-Source Multi-Platform Application (AnimApp)

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.


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 system 8 (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 previously 12 . 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 www.nature.com/scientificreports www.nature.com/scientificreports/ 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 Figure 1. Graphical abstract. Digital video captured from a variety of possible sources can be analysed by the AnimApp program directly on an Android-compatible smartphone or tablet for small-batch files, or transferred to a computer for video trimming and conversion, and high-throughput high-resolution analysis. AnimApp running on either platform gives total movement summary and .csv formatted tracked path for further analysis in other software (example of tracked path processed with colouring representing instantaneous velocity, using R and ggplot2 19,20  www.nature.com/scientificreports www.nature.com/scientificreports/ 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 tests 9 , while direct animal handling has been reported to have an effect on anxiety-related behaviour 12 . Mouse activity was measured for Upon opening a video file in AnimApp, the first frame is shown as a preview. A green marker square can be drawn for video cropping ('Crop' switch), or alternatively for reference to a known scale such as a visible ruler. (b) Activating the "Threshold" switch allows precise setting of the Hue, Saturation and Value (HSV) sliders in order to set the colour threshold for animal detection. The slider under the preview frame can be moved to test the threshold settings frame-byframe throughout the video. Preset HSV thresholds can be loaded from the "Presets" tab (see Supplemental  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 behaviour 6 . 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 www.nature.com/scientificreports www.nature.com/scientificreports/ 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 mice 10 . 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).

conclusion
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 animals [13][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 software 10 . 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
Animals. 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.
Video recording. 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 www.nature.com/scientificreports www.nature.com/scientificreports/ 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 analysis. 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 OpenCV 16 or JavaCV 17 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.
2 (x 1 , y 1 ) -initial location of the object. (x 2 , y 2 ) -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 package 19,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 larvae 4 . 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).
Statistics. All statistical tests were performed in R 3.4.2 19 . 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.