Open Field Assay Rodent Tracking
Behavioral neuroscience labs run a test called the Open Field Test all the time. You put a mouse in a walled box, film it, and watch where it goes. Anxious mice hug the walls and avoid the open middle. Calm, curious ones explore. From that simple footage you can pull real numbers: how far it moved, how fast, how much time it spent in the scary center, how long before it first ventured in.
The catch is the software. The standard tool, EthoVision, is expensive licensed software. The free alternative, DeepLabCut, is powerful but heavy: you train a pose model, label keypoints, and you really want a GPU. If all you need is "where is the mouse in this arena," that's a lot of overhead.
So I built oft-tracker. Point it at a video, click to outline the arena, and it gives you the standard Open Field readouts. It runs on a plain CPU with a lightweight YOLOv8 detector and a simple desktop GUI, so someone who doesn't code can run it.
How it works
The whole thing is one pipeline, from raw video to a folder of results.
- You pick a camera or a video file and type in a mouse ID.
- You outline the arena on the first frame by clicking a polygon.
- The arena gets split into a 4x4 grid, and the inner 2x2 becomes the "center" zone.
- Optionally, you tell it the arena width in cm so the output is in real units instead of pixels.
- For each frame, YOLOv8 finds the mouse and records where it is.
- At the end it smooths the path, computes the metrics, and writes everything out.
Finding the mouse
The core is a custom-trained YOLOv8-nano model that only knows one thing: what a mouse looks like. Each frame it runs detection, and I take the largest box as the animal.
This is deliberately simple. It's a single animal in a box, so "the biggest detection is the mouse" is robust and it shrugs off small false positives. It's not doing fancy identity tracking, and it doesn't need to.
The center vs. the walls
The most important readout in the Open Field Test is how the animal splits its time between the exposed center and the safe edges. I define the center as the inner four cells of a 4x4 grid over the arena.
Wall-hugging (the technical word is thigmotaxis) is the flip side, and it's the clearest anxiety signal. I count every frame where the mouse is within half a cell of any wall.
What comes out
After the loop, the raw path gets smoothed with a Savitzky-Golay filter so the speed numbers aren't dominated by jitter, and then everything gets aggregated with pandas. Into a results folder you get:
- a per-frame CSV and a two-sheet Excel file
- total distance, mean and max speed
- time in center, number of center entries, and latency to the first entry
- time spent wall-hugging
- an occupancy heatmap (where the mouse spent its time)
- a trajectory plot and a speed-over-time chart
The heatmap is just a per-pixel visit counter, blurred into the familiar warm-and-cool picture everyone recognizes.
Set it up
It uses uv (a fast Python package manager), so you don't need pip, uv handles the dependencies.
git clone https://github.com/harsh7z/oft-tracker.git
cd oft-tracker
uv run python main.pyThat opens the GUI: pick a camera or a video file, outline the arena, and it writes the metrics to a results folder.
Being honest about it
This is a focused tool, not a clone of EthoVision, and it helps to be clear about the edges.
The mouse detector is custom-trained, but the training data and scripts aren't in the repo, so I'd treat the model as "works well on my footage" rather than a validated benchmark. The tracking is a largest-box heuristic, so it's built for one animal, not several. Zones are computed from the arena's bounding box, so a very non-rectangular arena won't line up perfectly. And it measures movement and location, not freezing.
None of that is the point, though. The point is that a lab with a webcam and no budget can get the core Open Field numbers in a few minutes, without buying a license or training a neural network. That gap is worth closing.