The Mat class can handle multiple matrix formats from 1 to 4 channels, with different value types (float or uchar), and can be stored CPU and/or GPU side. More...
Functions | |
def | __cinit__ (self, width=0, height=0, mat_type=MAT_TYPE.F32_C1, memory_type=MEM.CPU) |
Constructor. More... | |
def | init_mat_type (self, width, height, mat_type, memory_type=MEM.CPU) |
Inits a new Mat . More... | |
def | init_mat_cpu (self, int width, int height, MAT_TYPE mat_type, ptr, step, memory_type=MEM.CPU) |
Inits a new Mat from an existing data pointer. More... | |
def | init_mat_resolution (self, Resolution resolution, MAT_TYPE mat_type, memory_type=MEM.CPU) |
Inits a new Mat . More... | |
def | init_mat_resolution_cpu (self, Resolution resolution, mat_type, ptr, step, memory_type=MEM.CPU) |
Inits a new Mat from an existing data pointer. More... | |
def | init_mat (self, Mat matrix) |
Inits a new Mat by copy (shallow copy). More... | |
def | alloc_size (self, width, height, mat_type, memory_type=MEM.CPU) |
Allocates the Mat memory. More... | |
def | alloc_resolution (self, Resolution resolution, MAT_TYPE mat_type, memory_type=MEM.CPU) |
Allocates the Mat memory. More... | |
def | free (self, memory_type=MEM.CPU) |
Free the owned memory. More... | |
def | copy_to (self, Mat dst, cpy_type=COPY_TYPE.CPU_CPU) |
Copies data to another Mat (deep copy). More... | |
def | set_from (self, Mat src, cpy_type=COPY_TYPE.CPU_CPU) |
Copies data from an other Mat (deep copy). More... | |
def | read (self, str filepath) |
Reads an image from a file (only if MEM.CPU is available on the current Mat ). More... | |
def | write (self, str filepath, memory_type=MEM.CPU, compression_level=-1) |
Writes the Mat (only if MEM.CPU is available on the current Mat ) into a file as an image. More... | |
def | set_to (self, value, memory_type=MEM.CPU) |
Fills the Mat with the given value. More... | |
def | set_value (self, int x, int y, value, memory_type=MEM.CPU) |
Sets a value to a specific point in the matrix. More... | |
def | get_value (self, int x, int y, memory_type=MEM.CPU) |
Returns the value of a specific point in the matrix. More... | |
def | get_width (self) |
Returns the width of the matrix. More... | |
def | get_height (self) |
Returns the height of the matrix. More... | |
def | get_resolution (self) |
Returns the resolution of the matrix. More... | |
def | get_channels (self) |
Returns the number of values stored in one pixel. More... | |
def | get_data_type (self) |
Returns the format of the matrix. More... | |
def | get_memory_type (self) |
Returns the format of the matrix. More... | |
def | get_data (self, memory_type=MEM.CPU, deep_copy=False) |
Cast the data of the Mat in a Numpy array (with or without copy). More... | |
def | get_step_bytes (self, memory_type=MEM.CPU) |
Returns the memory step in Bytes (the Bytes size of one pixel row). More... | |
def | get_step (self, memory_type=MEM.CPU) |
Returns the memory step in number of elements (the number of values in one pixel row). More... | |
def | get_pixel_bytes (self) |
Returns the size in bytes of one pixel. More... | |
def | get_width_bytes (self) |
Returns the size in bytes of a row. More... | |
def | get_infos (self) |
Returns the information about the Mat into a string. More... | |
def | is_init (self) |
Defines whether the Mat is initialized or not. More... | |
def | is_memory_owner (self) |
Returns whether the Mat is the owner of the memory it accesses. More... | |
def | clone (self, Mat py_mat) |
Duplicates Mat by copy (deep copy). More... | |
def | move (self, Mat py_mat) |
Moves Mat data to another Mat. More... | |
def | get_pointer (self, memory_type=MEM.CPU) |
Gets the pointer of the content of the Mat. More... | |
def | name (self) |
The name of the Mat (optional). More... | |
def | timestamp (self) |
The timestamp of the Mat. | |
def | verbose (self) |
Whether the Mat can display information or not. | |
Static Functions | |
def | swap (Mat mat1, Mat mat2) |
Swaps the content of the provided Mat (only swaps the pointers, no data copy). More... | |
The Mat class can handle multiple matrix formats from 1 to 4 channels, with different value types (float or uchar), and can be stored CPU and/or GPU side.
Mat is defined in a row-major order, it means that, for an image buffer, the entire first row is stored first, followed by the entire second row, and so on.
The CPU and GPU buffer aren't automatically synchronized for performance reasons, you can use update_gpu_from_cpu / update_gpu_from_cpu to do it. If you are using the GPU side of the Mat object, you need to make sure to call free before destroying the Camera object. The destruction of the Camera object deletes the CUDA context needed to free the Mat memory.
def __cinit__ | ( | self, | |
width = 0 , |
|||
height = 0 , |
|||
mat_type = MAT_TYPE.F32_C1 , |
|||
memory_type = MEM.CPU |
|||
) |
Constructor.
width | : width of the matrix in pixels. Default: 0 |
height | : height of the matrix in pixels. Default: 0 |
mat_type | : the type of the matrix ( MAT_TYPE.F32_C1 , MAT_TYPE.U8_C4 ...). Default: MAT_TYPE.F32_C1 |
memory_type | : defines where the buffer will be stored. Default: MEM.CPU (you cannot change this default value) |
def init_mat_type | ( | self, | |
width, | |||
height, | |||
mat_type, | |||
memory_type = MEM.CPU |
|||
) |
Inits a new Mat .
This function directly allocates the requested memory. It calls alloc_size .
width | : width of the matrix in pixels. |
height | : height of the matrix in pixels. |
mat_type | : the type of the matrix (MAT_TYPE.F32_C1 , MAT_TYPE.U8_C4 ...) |
memory_type | : defines where the buffer will be stored. Default: MEM.CPU (you cannot change this default value) |
def init_mat_cpu | ( | self, | |
int | width, | ||
int | height, | ||
MAT_TYPE | mat_type, | ||
ptr, | |||
step, | |||
memory_type = MEM.CPU |
|||
) |
Inits a new Mat from an existing data pointer.
This function doesn't allocate the memory.
width | : width of the matrix in pixels. |
height | : height of the matrix in pixels. |
mat_type | : the type of the matrix (MAT_TYPE.F32_C1 , MAT_TYPE.U8_C4 ...) |
ptr | : pointer to the data array. (CPU or GPU). |
step | : step of the data array. (the Bytes size of one pixel row). |
memory_type | : defines where the buffer will be stored. Default: MEM.CPU (you cannot change this default value) |
def init_mat_resolution | ( | self, | |
Resolution | resolution, | ||
MAT_TYPE | mat_type, | ||
memory_type = MEM.CPU |
|||
) |
Inits a new Mat .
This function directly allocates the requested memory. It calls alloc_resolution .
resolution | : the size of the matrix in pixels. |
mat_type | : the type of the matrix (MAT_TYPE.F32_C1 , MAT_TYPE.U8_C4 ... ) |
memory_type | : defines where the buffer will be stored. Default: MEM.CPU (you cannot change this default value) |
def init_mat_resolution_cpu | ( | self, | |
Resolution | resolution, | ||
mat_type, | |||
ptr, | |||
step, | |||
memory_type = MEM.CPU |
|||
) |
Inits a new Mat from an existing data pointer.
This function doesn't allocate the memory.
resolution | : the size of the matrix in pixels. |
mat_type | : the type of the matrix (MAT_TYPE.F32_C1 , MAT_TYPE.U8_C4 ...) |
ptr | : pointer to the data array. (CPU or GPU). |
step | : step of the data array. (the Bytes size of one pixel row). |
memory_type | : defines where the buffer will be stored. Default: MEM.CPU (you cannot change this default value) |
def init_mat | ( | self, | |
Mat | matrix | ||
) |
def alloc_size | ( | self, | |
width, | |||
height, | |||
mat_type, | |||
memory_type = MEM.CPU |
|||
) |
Allocates the Mat memory.
width | : width of the matrix in pixels. |
height | : height of the matrix in pixels. |
mat_type | : the type of the matrix (MAT_TYPE.F32_C1 , MAT_TYPE.U8_C4 ...) |
memory_type | : defines where the buffer will be stored. Default: MEM.CPU (you cannot change this default value) |
def alloc_resolution | ( | self, | |
Resolution | resolution, | ||
MAT_TYPE | mat_type, | ||
memory_type = MEM.CPU |
|||
) |
Allocates the Mat memory.
resolution | : the size of the matrix in pixels. |
mat_type | : the type of the matrix (MAT_TYPE.F32_C1 , MAT_TYPE.U8_C4 ...) |
memory_type | : defines where the buffer will be stored. Default: MEM.CPU (you cannot change this default value) |
def free | ( | self, | |
memory_type = MEM.CPU |
|||
) |
Free the owned memory.
memory_type | : specifies which memory you wish to free. Default: MEM.CPU (you cannot change this default value) |
def copy_to | ( | self, | |
Mat | dst, | ||
cpy_type = COPY_TYPE.CPU_CPU |
|||
) |
Copies data to another Mat (deep copy).
dst | : the Mat where the data will be copied. |
cpy_type | : specifies the memories that will be used for the copy. Default: COPY_TYPE.CPU_CPU (you cannot change the default value) |
def set_from | ( | self, | |
Mat | src, | ||
cpy_type = COPY_TYPE.CPU_CPU |
|||
) |
Copies data from an other Mat (deep copy).
src | : the Mat where the data will be copied from. |
cpy_type | : specifies the memories that will be used for the update. Default: COPY_TYPE.CPU_CPU (you cannot change the default value) |
def read | ( | self, | |
str | filepath | ||
) |
Reads an image from a file (only if MEM.CPU is available on the current Mat ).
Supported input files format are PNG and JPEG.
filepath | : file path including the name and extension |
def write | ( | self, | |
str | filepath, | ||
memory_type = MEM.CPU , |
|||
compression_level = -1 |
|||
) |
Writes the Mat (only if MEM.CPU is available on the current Mat ) into a file as an image.
Supported output files format are PNG and JPEG.
filepath | : file path including the name and extension. |
memory_type | : memory type of the Mat. Default: MEM.CPU (you cannot change the default value) |
compression_level | : level of compression between 0 (lowest compression == highest size == highest quality(jpg)) and 100 (highest compression == lowest size == lowest quality(jpg)). |
def set_to | ( | self, | |
value, | |||
memory_type = MEM.CPU |
|||
) |
def set_value | ( | self, | |
int | x, | ||
int | y, | ||
value, | |||
memory_type = MEM.CPU |
|||
) |
Sets a value to a specific point in the matrix.
x | : specifies the column. |
y | : specifies the row. |
value | : the value to be set. |
memory_type | : defines which memory will be updated. Default: MEM.CPU (you cannot change the default value) |
def get_value | ( | self, | |
int | x, | ||
int | y, | ||
memory_type = MEM.CPU |
|||
) |
Returns the value of a specific point in the matrix.
x | : specifies the column |
y | : specifies the row |
memory_type | : defines which memory should be read. Default: MEM.CPU (you cannot change this default value) |
def get_width | ( | self | ) |
Returns the width of the matrix.
def get_height | ( | self | ) |
Returns the height of the matrix.
def get_resolution | ( | self | ) |
Returns the resolution of the matrix.
def get_channels | ( | self | ) |
Returns the number of values stored in one pixel.
def get_data_type | ( | self | ) |
Returns the format of the matrix.
Referenced by Mat.get_value(), Mat.set_to(), and Mat.set_value().
def get_memory_type | ( | self | ) |
Returns the format of the matrix.
def get_data | ( | self, | |
memory_type = MEM.CPU , |
|||
deep_copy = False |
|||
) |
Cast the data of the Mat in a Numpy array (with or without copy).
memory_type | : defines which memory should be read. Default: MEM.CPU (you cannot change the default value) |
deep_copy | : defines if the memory of the Mat need to be duplicated or not. The fastest is deep_copy at False but the sl::Mat memory must not be released to use the numpy array. |
def get_step_bytes | ( | self, | |
memory_type = MEM.CPU |
|||
) |
Returns the memory step in Bytes (the Bytes size of one pixel row).
memory_type | : defines which memory should be read. Default: MEM.CPU (you cannot change the default value) |
def get_step | ( | self, | |
memory_type = MEM.CPU |
|||
) |
Returns the memory step in number of elements (the number of values in one pixel row).
memory_type | : defines which memory should be read. Default: MEM.CPU (you cannot change the default value) |
def get_pixel_bytes | ( | self | ) |
Returns the size in bytes of one pixel.
def get_width_bytes | ( | self | ) |
Returns the size in bytes of a row.
def get_infos | ( | self | ) |
Returns the information about the Mat into a string.
Referenced by Matrix4f.m(), and Mat.verbose().
def is_init | ( | self | ) |
def is_memory_owner | ( | self | ) |
def clone | ( | self, | |
Mat | py_mat | ||
) |
def move | ( | self, | |
Mat | py_mat | ||
) |
Moves Mat data to another Mat.
This function gives the attribute of the current Mat to the specified one. (No copy).
py_mat | : the Mat to move. |
Referenced by Mat.__cinit__(), Mat.init_mat(), Mat.init_mat_cpu(), Mat.init_mat_resolution(), Mat.init_mat_resolution_cpu(), and Mat.init_mat_type().
def get_pointer | ( | self, | |
memory_type = MEM.CPU |
|||
) |