Input sample video is rat.avi placed in the root directory.
Output video demonstration is placed on the link below.
After processing the input video(s) by the script
track.py you will get new directory
<current date>_distance with CSV table
and two subdirectories
Tracking is based on very simple image preprocessing and processing algorithms implemented in OpenCV, therefore OpenCV and Numpy are the only requirement. To install it on your python environment type
pip install -r requirements.txt in your terminal.
Initially the script takes no arguments, scans its own directory and searches all AVI files encoded with H.264, but it is up to you which file extension the script will search. To make a choice just replace all
*.avi strings in the source code by your own extension.
Since the pixels of an animal contour are nested to the floor and the floor contour is nested to the box walls (animal ⊂ floor ⊂ walls), the floor have to be as contrast to its neighbors in this triplet as possible for better distinction between all of them. For example: white walls, black floor, and white animal or vice versa is the best case.
Because it's hard to fit the floor of the box within camera frame in the laboratory, the script makes some preprocessing. The script takes a certain part of each frame of the videos. It takes a right square
frame[:, w-h:w] of a frame with sides equal to height
h of a frame.
That's why the box with an animal have to be placed in the right area of camera field of view.
(You are free to change this behavior replacing
frame[:, w-h:w] (right square) by
frame[:, 0:w-h] (left square), or just flip horizontally your video if you want to leave the script untouched.)
If requirements are complied then after starting the script you will get 1st frame of the video to be proccesed
The right half of the window is the ordinary frame with the floor highlighted by the red quad. This highlighted area is stretched by homographic transform up to the square area on the left left half of the window.
ESCor click right mouse button to continue.
Immediately after click on the 4th corner you can either
Enterand the processing will start or