SPPAS 4.22

https://sppas.org/

Module sppas.src.videodata

Class sppasSightsVideoBuffer

Description

A video buffer with lists of sights.

Constructor

Create a new instance.

Parameters
  • video: (str) The video filename
  • size: (int) Number of images of the buffer or -1 for auto
View Source
def __init__(self, video=None, size=-1):
    """Create a new instance.

    :param video: (str) The video filename
    :param size: (int) Number of images of the buffer or -1 for auto

    """
    super(sppasSightsVideoBuffer, self).__init__(video, size=size)
    self.__sights = list()
    self.__init_sights()

Public functions

reset

Override. Reset all the info related to the buffer content.

View Source
def reset(self):
    """Override. Reset all the info related to the buffer content."""
    sppasVideoReaderBuffer.reset(self)
    self.__init_sights()

next

Override. Fill in the buffer with the next images & reset sights.

View Source
def next(self):
    """Override. Fill in the buffer with the next images & reset sights.

        """
    ret = sppasVideoReaderBuffer.next(self)
    self.__init_sights()
    return ret

get_sights

Return the sights of all objects of a given image.

Parameters
  • buffer_index: (int) Index of the image in the buffer
Returns
  • (list of sppasSights)
View Source
def get_sights(self, buffer_index=None):
    """Return the sights of all objects of a given image.

        :param buffer_index: (int) Index of the image in the buffer
        :return: (list of sppasSights)

        """
    if buffer_index is not None:
        buffer_index = self.check_buffer_index(buffer_index)
        return self.__sights[buffer_index]
    else:
        if len(self.__sights) != self.__len__():
            raise ValueError('sppasSights were not properly associated to images of the buffer')
        return self.__sights

set_sights

Set the sights to a given image index.

The number of sights does not need to match the number of coords.

Parameters
  • buffer_index: (int) Index of the image in the buffer
  • sights: (list of sppasSights) Set the list of sights
View Source
def set_sights(self, buffer_index, sights):
    """Set the sights to a given image index.

        The number of sights does not need to match the number of coords.

        :param buffer_index: (int) Index of the image in the buffer
        :param sights: (list of sppasSights) Set the list of sights

        """
    if isinstance(sights, (list, tuple)) is True:
        checked = list()
        for c in sights:
            if c is None:
                c = sppasSights()
            elif isinstance(c, sppasSights) is False:
                raise sppasTypeError(c, 'sppasSights')
            checked.append(c)
        self.__sights[buffer_index] = checked
    else:
        raise sppasTypeError(type(sights), '(list, tuple)')

get_sight

Return the sights of an object of a given image.

Parameters
  • buffer_index: (int) Index of the image in the buffer
  • obj_idx: (int) Index of the object
Returns
  • (sppasSights)
View Source
def get_sight(self, buffer_index, obj_idx):
    """Return the sights of an object of a given image.

        :param buffer_index: (int) Index of the image in the buffer
        :param obj_idx: (int) Index of the object
        :return: (sppasSights)

        """
    buffer_index = self.check_buffer_index(buffer_index)
    if 0 <= obj_idx < len(self.__sights[buffer_index]):
        return self.__sights[buffer_index][obj_idx]
    raise ValueError('Invalid index value to get sights.')

append_sight

Set the sights to a given object of a given image index.

Parameters
  • buffer_index: (int) Index of the image in the buffer
  • sight: (sppasSights) the given sight object
View Source
def append_sight(self, buffer_index, sight):
    """Set the sights to a given object of a given image index.

        :param buffer_index: (int) Index of the image in the buffer
        :param sight: (sppasSights) the given sight object

        """
    buffer_index = self.check_buffer_index(buffer_index)
    if isinstance(sight, sppasSights):
        self.__sights[buffer_index].append(sight)
    else:
        raise sppasTypeError(sight, 'sppasSights')

Protected functions

__init_sights

View Source
def __init_sights(self):
    self.__sights = list()
    for i in range(self.get_buffer_size()):
        self.__sights.append(list())