CVideoIO

class ikomia.dataprocess.pydataprocess.CVideoIO

Define an input or output for a task dedicated to video management. This class is designed to handle video and instance can be added as input or output to a CWorkflowTask or derived object. It is the base class to define input or output of a video processing task. Several video output type can be defined according to the nature of the algorithm:

  • binary video

  • labelled video (graylevel connected components)

  • standard video

Source video can be either a file, an image sequence or a stream. Image data is stored as a numpy array. Derived from CImageIO.

Import

from ikomia.dataprocess import CVideoIO

Methods

__init__(arg1)

__init__( (object)self) -> None :

add_video_image(self, image)

Append image frame to the video.

get_current_pos(self)

Get the current frame index of the video or stream.

get_snapshot(self, position)

Get image of a single frame.

get_video_frame_count(self)

Get the total frames number of the video.

get_video_images(self)

Get all image frames extracted from the video.

get_video_path(self)

Get the path to the source video.

has_video(self)

Check whether the input or output has a video source.

set_video_path(self, path)

Set the source path of the video.

set_video_pos(self, position)

Set the current frame of the video.

start_video(self, timeout)

Start playing the video.

start_video_write(self, width, height, ...)

Write the video to disk.

stop_video(self)

Stop playing the video.

stop_video_write(self, timeout)

Stop writting to disk.

write_image(self, image)

Append a new image to the list of images to write to disk.

Overridden methods

clear_data(self)

Clear the current image at the current frame index.

copy_static_data(arg1, self)

See copy_static_data().

get_image(self)

Get the image at the current frame index.

get_unit_element_count(self)

Get the number of unit elements to process, ie the number of frames for a video.

is_data_available(self)

Check whether the video contains valid data.

Inherited methods

draw_graphics(self, graphics)

Draw given graphics items input in the image.

get_channel_count(self)

Get the static channel count information.

get_data(self)

Get the image data.

get_overlay_mask(self)

Get the overlay mask.

is_overlay_available(self)

Check whether the input/output have valid overlay mask or not

set_channel_count(self, nb)

Set the channel count of the image data.This property holds the required channel count as a static information.

set_current_image_index(self, index)

Set the index of the current image (2D plane) from a volume (3D image data structure).

set_image(self, image)

Set the image data

set_overlay_mask(self, mask)

Set the associated overlay mask.

Attributes

auto_save

Auto-save status

data_type

I/O data type

dim_count

Number of dimensions

description

Custom description to explain input/output type and use

displayable

Displayable status (Ikomia Studio)

name

I/O name

source_file_path

Path to the source file used as workflow input (if any)

Details

__init__((object)arg1) None
__init__( (object)self) -> None :

Default constructor

__init__( (object)self, (IODataType)data_type) -> None :

Construct a CVideoIO instance with the given data type. The data type must be one of these values:

  • IODataType.VIDEO

  • IODataType.VIDEO_BINARY

  • IODataType.VIDEO_LABEL

  • IODataType.LIVE_STREAM

  • IODataType.LIVE_STREAM_BINARY

  • IODataType.LIVE_STREAM_LABEL

Please note that internal image structure is empty.

Args:

data_type (IODataType): video data type

__init__( (object)self, (IODataType)data_type, (object)frame) -> None :

Construct a CVideoIO instance with the given data type. The data type must be one of these values:

  • IODataType.VIDEO

  • IODataType.VIDEO_BINARY

  • IODataType.VIDEO_LABEL

  • IODataType.LIVE_STREAM

  • IODataType.LIVE_STREAM_BINARY

  • IODataType.LIVE_STREAM_LABEL

Please note that internal image structure is empty.

Args:

data_type (IODataType): video data type

frame (Numpy array): 2D image (first frame of the video)

__init__( (object)self, (IODataType)data_type, (object)frame, (str)name) -> None :

Construct a CVideoIO instance with the given data type and the given image. The data type must be one of these values:

  • IODataType.VIDEO

  • IODataType.VIDEO_BINARY

  • IODataType.VIDEO_LABEL

  • IODataType.LIVE_STREAM

  • IODataType.LIVE_STREAM_BINARY

  • IODataType.LIVE_STREAM_LABEL

Args:

data_type (IODataType): video data type

frame (Numpy array): 2D image

name (str): input or output custom name (to give insights to end user)

__init__( (object)self, (IODataType)data_type, (str)name) -> None :

Construct a CVideoIO instance with the given data type and identification name. The data type must be one of these values:

  • IODataType.IMAGE

  • IODataType.IMAGE_BINARY

  • IODataType.IMAGE_LABEL

  • IODataType.VOLUME

  • IODataType.VOLUME_BINARY

  • IODataType.VOLUME_LABEL

Args:

data_type (IODataType): video data type

name (str): input or output custom name (to give insights to end user)

__init__( (object)self, (IODataType)data_type, (str)name, (str)path) -> None :

Construct a CImageIO instance with the given data type, identification name and video path . The data type must be one of these values:

  • IODataType.IMAGE

  • IODataType.IMAGE_BINARY

  • IODataType.IMAGE_LABEL

  • IODataType.VOLUME

  • IODataType.VOLUME_BINARY

  • IODataType.VOLUME_LABEL

Args:

data_type (IODataType): video data type

name (str): input or output name

path (str): video path

__init__( (object)arg1, (CVideoIO)arg2) -> None :

Copy constructor

add_video_image((CVideoIO)self, (object)image) None :

Append image frame to the video.

Parameters:

image (Numpy array) – 2D image

clear_data((CVideoIO)self) None :

Clear the current image at the current frame index.

clear_data( (CVideoIO)self) -> None

copy_static_data((CVideoIO)arg1, (CWorkflowTaskIO)self) None :

See copy_static_data().

copy_static_data( (CVideoIO)arg1, (CWorkflowTaskIO)self) -> None

get_channel_count((CImageIO)self) int :

Get the static channel count information. The method does not get the channel count property from the image data structure

Returns:

number of channel required for the input/output

Return type:

int

get_current_pos((CVideoIO)self) int :

Get the current frame index of the video or stream.

Returns:

current frame index

Return type:

int

get_data((CImageIO)self) object :

Get the image data.

Returns:

either 2D or 3D image buffer

Return type:

Numpy array

get_image((CVideoIO)self) object :

Get the image at the current frame index.

Returns:

Numpy array: 2D image buffer

get_image( (CVideoIO)self) -> object

get_overlay_mask((CImageIO)self) object :

Get the overlay mask. See set_overlay_mask() for more information.

Returns:

2D image buffer (8 bits - 1 channel)

Return type:

Numpy array

get_snapshot((CVideoIO)self, (int)position) object :

Get image of a single frame.

Parameters:

position (int) – index of the frame

Returns:

2D image buffer

Return type:

Numpy array

get_unit_element_count((CVideoIO)self) int :

Get the number of unit elements to process, ie the number of frames for a video. Used to determine the number of steps for progress bar.

Returns:

int: frames number of the video

get_unit_element_count( (CVideoIO)self) -> int

get_video_frame_count((CVideoIO)self) int :

Get the total frames number of the video.

Returns:

frames number

Return type:

int

get_video_images((CVideoIO)self) object :

Get all image frames extracted from the video.

Returns:

list of 2D images

Return type:

Numpy array list

get_video_path((CVideoIO)self) str :

Get the path to the source video. It can be a file path, a device ID or an url.

Returns:

source video path

Return type:

str

has_video((CVideoIO)self) bool :

Check whether the input or output has a video source.

Returns:

True if the source is valid, False otherwise

Return type:

bool

is_data_available((CVideoIO)self) bool :

Check whether the video contains valid data.

Returns:

bool: True if there is some valid data, False otherwise

is_data_available( (CVideoIO)self) -> bool

is_overlay_available((CImageIO)self) bool :

Check whether the input/output have valid overlay mask or not

Returns:

True if overlay mask is not empty, False otherwise.

Return type:

bool

set_channel_count((CImageIO)self, (int)nb) None :

Set the channel count of the image data.This property holds the required channel count as a static information. Such information can be useful when one designs a workflow and wants to inform about specific image structure towards future connected tasks.

Parameters:

nb (int) – channel count, 1 for monochrome image, 3 for color image

set_current_image_index((CImageIO)self, (int)index) None :

Set the index of the current image (2D plane) from a volume (3D image data structure).

Parameters:

index (int) – zero-based index of the 2D plane

set_image((CImageIO)self, (object)image) None :

Set the image data

Parameters:

image (Numpy array) – image buffer

set_overlay_mask((CImageIO)self, (object)mask) None :

Set the associated overlay mask. Ikomia Studio is able to display overlay mask on top of image. This method sets this mask, it will be displayed automatically according to a predefined color map. Zero-value pixels of the mask will be completely transparent, non-zero will be displayed according to the corresponding color in the color map. The color map must be defined in the task implementation. See set_output_color_map() for details.

Parameters:

image (Numpy array) – image buffer (8 bits - 1 channel)

set_video_path((CVideoIO)self, (str)path) None :

Set the source path of the video.

Parameters:

path (str) – can be a file path, a device ID (internal webcam) or an url (IP camera)

set_video_pos((CVideoIO)self, (int)position) None :

Set the current frame of the video.

Parameters:

position (int) – index of the frame

start_video((CVideoIO)self, (int)timeout) None :

Start playing the video.

Parameters:

timeout (int) – maximum time between 2 read operations (in ms)

start_video_write((CVideoIO)self, (int)width, (int)height, (int)frames, (int)fps, (int)fourcc, (int)timeout) None :

Write the video to disk.

Parameters:
  • width (int) – video width

  • height (int) – video height

  • frames (int) – number of frames

  • fps (int) – frames per second

  • fourcc (int) – codec code (-1 for default)

  • timeout (int) – maximum time between 2 write opertions (in ms)

stop_video((CVideoIO)self) None :

Stop playing the video.

stop_video_write((CVideoIO)self, (int)timeout) None :

Stop writting to disk.

Parameters:

timeout (int) – time for reading to end (in ms)

write_image((CVideoIO)self, (object)image) None :

Append a new image to the list of images to write to disk. The write process is launched using start_video_write().

Parameters:

image (Numpy array) – 2D image