Simple Mouse Tracker (SMT) is a video tracker software based on Open CV. It intends to track body, head and tail cordinates (X,Y) of a single color mouse over a homogeneous color background.
The SMT runs on any platform that supports Python. Software requirements are:
- Python >= 2.7.*
- NumPy >= 1.7.* (see: http://www.numpy.org/)
- OpenCV 2 (see: http://opencv.willowgarage.com/wiki/)
Note: This steps were only tested with 32bits Python version.
-
Download and install python 2.7 32bits
http://www.python.org/download/
-
Download and install numpy 32bits for python 2.7
http://sourceforge.net/projects/numpy/files/NumPy/
-
Download OpenCV 2.4.2 and unzip it to
C:\
http://sourceforge.net/projects/opencvlibrary/files/opencv-win/
-
Add Python to the Windows PATH. (check here how to: http://www.computerhope.com/issues/ch000549.htm)
-
Add
c:\opencv\build\x86\vc10\bin
to the Windows PATH -
Copy the file
c:\opencv\build\python\2.7\cv2.pyd
toc:\Python27\Lib\site-packages\
directory -
Open the command console:
- Start
- Run
- Command
- Type
cmd
- At the command window type
python
-
To check if it is correctly installed run the following python command:
>>> import cv2
If nothing happens everything should be OK.
Run the following installation commands:
$ sudo apt-get install python2.7
$ sudo apt-get install python-numpy
$ sudo apt-get install python-opencv
-
Unzip the zip file to any folder in your computer (e.g.
/home/user/mt
). -
From the console run the following command:
$ python /home/user/mt/create_project.py
If you get the following message, the installation should be fine:
usage: create_project.py [-h] [-p POLY] project video
create_project.py: error: too few arguments
Note: In the above command replace /home/user/mt
by you own settings.
Note: Before start remember that the examples in this section assume the following:
- The mouse tracker was installed in
/home/user/mt
. - We have a video file named 'video.avi' in the directory '/home/user/myvideos';
- We call the project 'test' and will save it in the directory '/home/user/myprjs'
In the command line run:
$ python /home/user/mt/create_project.py /home/user/myprjs/test /home/user/myvideos/video.avi
This will create the subdirectory test
under the directory /home/user/myprjs
. This directory will contain all the data files relative to the project.
In the command line run:
$ python /home/user/mt/set_mask.py /home/user/myprjs/test
You should see the video running in two windows 'Original' and 'Mouse'. The 'Original' one is your video as you acquired it, the 'Mouse' is the binary version accoring to the threshold options defined. The goal here is to have the mouse showing up as a white blob on a black background in the 'Mouse' window. Nothing else should appear white in that window. To acchieve that you can:
-
Drag around the blue dots in order to include as much as you can from the arena without adding noise.
-
Click the mouse right button to add more dot's to the polygon and fine tune the area.
-
Play around with the
_thresh
parameters in the/home/user/myprjs/test/project.cfg
file:_thresh: [ 70, 35 ]
When done press the 's' key to save the new mask into the project or 'q' to quit without saving.
In the command line run:
$ python /home/user/mt/get_data.py /home/user/myprjs/test
This will create the file /home/user/myprjs/test/coords.dat
with all the coordinates from the tracking. If you want to watch the video during the analysis (this will be a lot slower!) do:
$ python /home/user/mt/get_data.py -s /home/user/myprjs/test
Notice the '-s' option.
Each time you run get_data.py
a new version of the coords.dat
file wil be created and the previous one will be renamed coords.dat.NNN.bak
.
In the command line run:
$ python /home/user/mt/view_data.py /home/user/myprjs/test
This will show you the result of the tracking. Remember: The red dot should always match the nose of the mouse!
Useful options:
- You can jump for a given frame using the '-j' parameter.
- You can slowdown the video with the '-d' parameter.
The following command will show the results from frame 1050 on, with an interval of 300 ms between frames:
$ python /home/user/mt/view_data.py -j 1050 -d 300 /home/user/myprjs/test
Often the get_data.py
script makes a lot of mistakes when classifying the nose and the tail. If this is your case you can try to correct the mistakes after processing all the file using the following command:
$ python /home/user/mt/fix_data.py /home/user/myprjs/test
This will analyse the 'coords.dat' and try to correct the mistakes by the relative movement of the head, tail and body during the whole video.
When done a new /home/user/myprjs/test/coords.dat
will be saved.
$ python /home/user/mt/calc_backbone.py /home/user/myprjs/test -b 5
This will calculate the line that divide the mouse blob in half, basing in N number of points (option -b).