visiannot.tools.video_loader

Summary

Module with functions for loading image and video files

Functions

visiannot.tools.video_loader.get_data_video(path)

Loads video data with openCV

visiannot.tools.video_loader.get_duration_video(path)

Gets duration of a video file

visiannot.tools.video_loader.read_image(path)

Reads an image with openCV

visiannot.tools.video_loader.transform_image(im)

Changes the order of an image channels in order to get RGB color, may reverse the first and second axis (in order to transform shape (width, height, 3) to (height, width, 3)).

API

Functions

visiannot.tools.video_loader.get_data_video(path)[source]

Loads video data with openCV

Parameters

path (str) – path to the video file

Returns

  • data_video (cv2.VideoCapture) (None if video file does not exist)

  • nframes (int) – number of frames in the video (0 if video file does not exist)

  • fps (int or float) - frame rate of the video (-1 if video file does not exist)

visiannot.tools.video_loader.get_duration_video(path)[source]

Gets duration of a video file

Parameters

path (str) – path to the video file

Returns

video file duration in seconds

Return type

float

visiannot.tools.video_loader.read_image(path)[source]

Reads an image with openCV

Parameters

path (str) – path to the image file

Returns

RGB image array of shape (width, height, 3)

Return type

numpy array

visiannot.tools.video_loader.transform_image(im, RGB_combination='BGR', flag_transpose=True)[source]

Changes the order of an image channels in order to get RGB color, may reverse the first and second axis (in order to transform shape (width, height, 3) to (height, width, 3)).

Particularly useful to display images retrieved with openCV. Indeed, openCV returns images of shape (width, height, 3) with BGR color.

Parameters
  • im (numpy array) – image array of shape (width, height, 3), where third axis is a 3-channel color

  • RGB_combination (str) – order of the color channel (as with openCV)

  • flag_transpose (bool) – specify if first axis and second axis must be reversed

Returns

image array of shape (height, width, 3) where third axis is RGB color

Return type

numpy array

If im is not a numpy array or is not a 3D array, then the output is im.