Animal-Identification-from-Video

January 9, 2022 ยท View on GitHub

Repository of annotated videos of multiple animals and MATLAB code for processing the data

ExampleAnnotation

1. Videos

The original videos included in this repository have been sourced from Pixabay under Pixabay License

  • Free for commercial use
  • No attribution required

The video data is summarised below:

Short NameVideo Name# FramesSize# Bounding boxes# Identities
PigsPigs_49651_960_540_500f.mp4500( 960, 540)618426
Koi fishKoi_5652_952_540.mp4536( 952, 540)16359
Pigeons (curb)Pigeons_8234_1280_720.mp4443(1280, 720)470016
Pigeons (ground)Pigeons_4927_960_540_600f.mp4600( 960, 540)307917
Pigeons (square)Pigeons_29033_960_540_300f.mp4300( 960, 540)489228

Annotated videos are available here:

2. Data

The data is stored in Excel files with names BB_XXX.csv, where XXX stands for the name of the video. Each Excel file is organised as follows:

Namexywhfilenamemax_xmax_y
Mahrez105985221312scene00001.jpg1280720
Torres686174367342scene00001.jpg1280720
Sterling564132283145scene00001.jpg1280720
Silva102557356163scene00001.jpg1280720
........................

The columns are: Names of the individual animals (class labels), the x and y coordinates in pixels of the top left corner of the bounding box, the (w)idth and (h)eight of the bounding box in pixels, the filename containing the frame of the video and the horizontal and vertical image dimensions. The file format was chosen to match that outputted by the labelling software provided by https://www.makesense.ai/.

3. Code

MATLAB functions

  • trim_video(video_name, output_file_name, number_of_frames) Trims a video to a desired number of frames.
  • store_frames(im_folder,video_file) Breaks a video into frames and saves them in a given folder. The frames are named scene00001.jpg, scene00002.jpg, etc.
  • create_annotated_video(image_folder, bb_file_name, label_flag) Creates an MP4 annotated video from the video stored as frames scene00001.jpg, scene00002.jpg, ... and a csv file with bounding boxes in the format explained in Section 2. The label flag determines whether the bounding boxes should be labelled. The default value of label_flag is True.
  • create_clips(folder,bb_file) Saves the clips from the frames in 'folder'. Each frame is examined in turn and the clips from the bounding boxes are cropped and stored in sub-folders with the name of the individual. The clip file names are formed as 'IndividualsName_frame_XXXXX.jpg'.
  • show_annotated_frame(im_folder,f_name, bb_file) Reads image 'f_name' from 'im_folder' and displays the image with overlayed labelled bounding boxes. Annotations are in the bb_file csv file (see create_annotated_video for the csv file format).

Python scripts

  • ClipClassification.ipynb Runs a classification experiment with simple feature spaces (handcrafted features).
  • SimpleFeaturesClassification.ipynb Runs a classification experiment with deep learning approaches (CNN and transfer learning).
  • CheckPythonFeatureExtraction.ipynb Shows examples of feature selection from an image.
  • FeatureExtractor.py Contains a collection of feature extraction functions.