A video buffer of images with a list of coordinates.
Module sppas.src.videodata
Class sppasCoordsVideoBuffer
Description
Constructor
Create a new instance.
Parameters
- video: (str) The video filename to browse
- 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 to browse
    :param size: (int) Number of images of the buffer or -1 for auto
    """
    super(sppasCoordsVideoBuffer, self).__init__(video, size=size, overlap=0)
    self.__coords = [list()] * size
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.__coords = [list()] * self.get_buffer_size()
next
Override. Fill in the buffer with the next images & reset coords.
View Source
def next(self):
    """Override. Fill in the buffer with the next images & reset coords.
        """
    ret = sppasVideoReaderBuffer.next(self)
    self.__coords = [list()] * self.get_buffer_size()
    return ret
get_coordinates
Return the coordinates of a given image.
Parameters
- buffer_index: (int) Index of the image in the buffer
Returns
- (list of sppasCoords) Coordinates
View Source
def get_coordinates(self, buffer_index=None):
    """Return the coordinates of a given image.
        :param buffer_index: (int) Index of the image in the buffer
        :return: (list of sppasCoords) Coordinates
        """
    if buffer_index is not None:
        buffer_index = self.check_buffer_index(buffer_index)
        return self.__coords[buffer_index]
    else:
        if len(self.__coords) != self.__len__():
            raise ValueError('Coordinates were not properly associated to images of the buffer')
        return self.__coords
set_coordinates
Set the coordinates to a given image index.
Parameters
- buffer_index: (int) Index of the image in the buffer
- coords: (list of sppasCoords) Set the list of coords
View Source
def set_coordinates(self, buffer_index, coords):
    """Set the coordinates to a given image index.
        :param buffer_index: (int) Index of the image in the buffer
        :param coords: (list of sppasCoords) Set the list of coords
        """
    buffer_index = self.check_buffer_index(buffer_index)
    if isinstance(coords, (list, tuple)) is True:
        for c in coords:
            if isinstance(c, sppasCoords) is False:
                raise sppasTypeError(str(type(c)), 'sppasCoords')
        self.__coords[buffer_index] = coords
    else:
        raise TypeError(str(type(coords)), 'list/tuple')
index_coordinate
Index of the given coordinate.
Parameters
- buffer_index
- coord
View Source
def index_coordinate(self, buffer_index, coord):
    """Index of the given coordinate."""
    buffer_index = self.check_buffer_index(buffer_index)
    return self.__coords[buffer_index].index(coord)
get_coordinate
Return a coordinate of a given image.
Parameters
- buffer_index: (int) Index of the image in the buffer
- coord_index: (int) Index of the coord
Returns
- (sppasCoords) Coordinates
View Source
def get_coordinate(self, buffer_index, coord_index):
    """Return a coordinate of a given image.
        :param buffer_index: (int) Index of the image in the buffer
        :param coord_index: (int) Index of the coord
        :return: (sppasCoords) Coordinates
        """
    if len(self.__coords[buffer_index]) == 0:
        raise ValueError('No coordinate at buffer index {:d}'.format(buffer_index))
    buffer_index = self.check_buffer_index(buffer_index)
    if 0 <= coord_index < len(self.__coords[buffer_index]):
        return self.__coords[buffer_index][coord_index]
    raise IndexError('Invalid coordinate index value {:d}. Should range [0; {:d}]'.format(coord_index, len(self.__coords[buffer_index])))
set_coordinate
Assign the coordinate to a given image index.
Parameters
- buffer_index: (int) Index of the image in the buffer
- coord_index: (int) Index of the coord
- coord: (sppasCoords) Append the given coord
View Source
def set_coordinate(self, buffer_index, coord_index, coord):
    """Assign the coordinate to a given image index.
        :param buffer_index: (int) Index of the image in the buffer
        :param coord_index: (int) Index of the coord
        :param coord: (sppasCoords) Append the given coord
        """
    buffer_index = self.check_buffer_index(buffer_index)
    if 0 <= coord_index < len(self.__coords[buffer_index]):
        if isinstance(coord, sppasCoords):
            self.__coords[buffer_index][coord_index] = coord
        else:
            raise TypeError('')
    else:
        raise ValueError('Invalid coordinate index value.')
append_coordinate
Append the coordinates to a given image index.
Parameters
- buffer_index: (int) Index of the image in the buffer
- coord: (sppasCoords) Append the given coord
View Source
def append_coordinate(self, buffer_index, coord):
    """Append the coordinates to a given image index.
        :param buffer_index: (int) Index of the image in the buffer
        :param coord: (sppasCoords) Append the given coord
        """
    buffer_index = self.check_buffer_index(buffer_index)
    if isinstance(coord, sppasCoords):
        self.__coords[buffer_index].append(coord)
    else:
        raise TypeError('')
remove_coordinate
Remove the coordinates to a given image index.
Parameters
- buffer_index: (int) Index of the image in the buffer
- coord: (sppasCoords) Remove the given coord
View Source
def remove_coordinate(self, buffer_index, coord):
    """Remove the coordinates to a given image index.
        :param buffer_index: (int) Index of the image in the buffer
        :param coord: (sppasCoords) Remove the given coord
        """
    buffer_index = self.check_buffer_index(buffer_index)
    if coord in self.__coords[buffer_index]:
        self.__coords[buffer_index].remove(coord)
pop_coordinate
Remove the coordinates to a given image index.
Parameters
- buffer_index: (int) Index of the image in the buffer
- coord_index: (int) Pop the given coord
View Source
def pop_coordinate(self, buffer_index, coord_index):
    """Remove the coordinates to a given image index.
        :param buffer_index: (int) Index of the image in the buffer
        :param coord_index: (int) Pop the given coord
        """
    buffer_index = self.check_buffer_index(buffer_index)
    self.__coords[buffer_index].pop(coord_index)
