GithubHelp home page GithubHelp logo

caothu3d / animal-tracking Goto Github PK

View Code? Open in Web Editor NEW

This project forked from colinlaney/animal-tracking

0.0 2.0 0.0 59.97 MB

Object tracking with OpenCV in an open field behavioral test

Home Page: https://youtu.be/GebcshN4OdE

License: Creative Commons Zero v1.0 Universal

Python 100.00%

animal-tracking's Introduction

Animal Tracking

Object tracking with OpenCV in an open field behavioral test


Origins

Input sample video is rat.avi placed in the root directory.

Output video demonstration is placed on the link below.

Open Field Test (Animal Tracking with OpenCV)

After processing the input video(s) by the script track.py you will get new directory <current date>_distance with CSV table

Animal Distance Run Time
ratN 56.38 420.1
... ... ...

and two subdirectories

  1. timing with processed video(s) as above
  2. tracks with images of animal(s) track(s) as on the left side of processed video

Prerequisites

Code Environment

Packages

Tracking is based on very simple image preprocessing and processing algorithms implemented in OpenCV, therefore OpenCV is the only requirement. To install it on your python environment type pip install opencv-python in your terminal.

Codecs

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.

Camera Environment

Since the pixels of an animal contour is embedded to the floor and the floor contour is embedded 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.

Example of contrast

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.

Crop right square of the 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.)

User Interface

If requirements are complied then after starting the script you will get a 1st frame of video to be proccesed

Good fit

The right 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.

If you're satisfied the look of the floor you can press any key except ESC or click right mouse button to continue. Else you are free to determine the right way of highlighting the area of the floor. To do that click left button on each corner of the floor strarting with any one.

Fitting Fitting Fitting Fitting Fitting Fitting Fitting

Immediately after click on the 4th corner the processing will start.

animal-tracking's People

Contributors

colinlaney avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.