CODE.
This page contains source code for most of the in-house software we use in the lab. All of it (for the moment) is in Python. All this code is free to use and redistribute under the GNU license. Most of it has been used in one or another of our publications. Please acknowledge us if you use this code for anything that gets published. Please also feel free to contact us if you have questions or requests for modified versions of the code. All the code is in zipped folders (since browsers won't let you download 'naked' code).
Tracking.
A lot of our experiments involve tracking animals moving around in arenas (either in videos or sequences of images). We use automated tracking software to do this. Mostly we use our own software, which you can download below. However, there is a lot of great FREE tracking software out there that is more sophisticated than ours. We particularly recommend IDTracker. Our tracker (and all its variations) is written in Python and depends on OpenCV, which you will need to install before using it.
When I was young and naive, I believed that you could write a general-purpose tracker that would work on any video, any animal, any background. Now that I'm older and more jaded, I generally make a separate version of the tracker for different experiments with different needs. The basic tracker is good for most things, and each variation on it is described briefly below.
When I was young and naive, I believed that you could write a general-purpose tracker that would work on any video, any animal, any background. Now that I'm older and more jaded, I generally make a separate version of the tracker for different experiments with different needs. The basic tracker is good for most things, and each variation on it is described briefly below.
![]()
|
This is our general-purpose tracker. It should work for most basic applications. It will track any number of moving objects against a contrasting background from a video. It does not keep track of identities across frames (i.e., it doesn't really make trajectories).
|
![]()
|
Sometimes, you need to track a LOT of videos. This is a batch tracker. It works exactly like the general one above, but it tracks all the videos in a folder, one after the other. You go home, relax, and it's all done when you come in the next morning.
|
![]()
![]()
|
Sometimes you don't want to make a video and then track it separately, you prefer to track things as they happen. This version is basically the same as the general one but tracks from a live stream rather than a file. It has a companion script, ROIMaker, that you need to run first to make the background image and tracking zones. This works pretty well for 3-4 targets; any more than that and slower machines will struggle to keep up. It will also optionally record the raw video, so you can always use the regular tracker on it later if it didn't track very well.
|
![]()
![]()
|
A while back, we wanted to track some rats that we had painted in various colors. Rats have tails that change shape a lot which was messing up our tracking them by color, so I made this variant of our tracker. It can track targets by color, using a template made in advance by the "TemplateMaker" script. It will also exclude the tails of the rats from tracking, giving a more accurate location of the body of the rat, and improving the color-based detection.
|
![]()
|
This program does the rest of the work, after the tracking. It will read in tracks, either from our tracker or from IDTracker, and let you view them or fix them. It will save a video with the tracks superimposed and even show interaction networks, if you want. It is also a track editor: it will let you re-assign track segments to different individuals to correct for identities skipping during tracking, the most common problem. You can also manually delete track points and manually re-track them, without affecting the rest of the data.
|
![]()
![]()
|
These are our general-purpose ethologger. It allows you to define some zones on an image or video, and then record animals entering or leaving there, by clicking on the image inside some zone. You can specify the ID of the animal for each event. This is useful, for example, for manually tracking animals moving in and out of specific areas. The first one runs over a sequence of images in a folder, the second one runs on videos. You can navigate the images or videos and set the playing speed, etc. Data can be entered in multiple sessions.
|
![]()
|
This is a slightly different, more traditional, ethologger. This one does not record positions of events, but lets you define lots of different event types and assign each one a shortcut key. It records an event each time you hit the key.
|
social network measures.
In our experiments on Japanese quail, we often calculate the dominance hierarchy in a given group. We pair the birds up and have them 'fight' over right-of-way to see who wins in each contest. The first script below (CCL_Pairing) gives the algorithm we use to pair up the birds so that everyone meets everyone else and no-one runs more than once a day. This may seem trivial but it isn't. The other script, CCL_Elo, takes as input a list of the contests between pairs of individuals. It generates a set of Elo scores which define the dominance hierarchy (higher score = more dominant). It also calculates a randomized Elo score and confidence intervals on it, and two common measures of transitivity (Kendall's K and Landau's h), which measure how strict the hierarchy is by counting closed triangles (e.g., if A beats B, B beats C, and C beats A, then the hierarchy is not linear). A sample data-set is included.
![]()
|
![]()
|
other things.
![]()
|
This is a script for reading files generated by MedPC operant boxes. The files they create are not very easy to work with. This script will let you select certain variables and will output them into an Excel file in a way that is (I think) much easier to analyze.
|
![]()
|
This is a simple capture script, that will record video from any capture device (like a webcam). It lets you specify a device, a name for the output file, the frame rate, and the resolution.
|
![]()
|
This is a simple frame grabber. You can use this to save frames from a video as images. You can specify frame numbers in advance, or grab frames as the video plays.
|