Mat Class Reference

Class representing 1 to 4-channel matrix of float or uchar, stored on CPU and/or GPU side. More...

Functions

Mat __cinit__ (self, width=0, height=0, mat_type=MAT_TYPE.F32_C1, memory_type=MEM.CPU)
 Default constructor. More...
 
None init_mat_type (self, width, height, mat_type, memory_type=MEM.CPU)
 Initilizes a new sl.Mat and allocates the requested memory by calling alloc_size(). More...
 
None init_mat_cpu (self, int width, int height, MAT_TYPE mat_type, ptr, step, memory_type=MEM.CPU)
 Initilizes a new sl.Mat from an existing data pointer. More...
 
None init_mat_resolution (self, Resolution resolution, MAT_TYPE mat_type, memory_type=MEM.CPU)
 Initilizes a new sl.Mat and allocates the requested memory by calling alloc_size(). More...
 
None init_mat_resolution_cpu (self, Resolution resolution, mat_type, ptr, step, memory_type=MEM.CPU)
 Initilizes a new sl.Mat from an existing data pointer. More...
 
None init_mat (self, Mat matrix)
 Initilizes a new sl.Mat by copy (shallow copy). More...
 
None alloc_size (self, width, height, mat_type, memory_type=MEM.CPU)
 Allocates the sl.Mat memory. More...
 
None alloc_resolution (self, Resolution resolution, MAT_TYPE mat_type, memory_type=MEM.CPU)
 Allocates the sl.Mat memory. More...
 
None free (self, memory_type=MEM.CPU)
 Free the owned memory. More...
 
ERROR_CODE copy_to (self, Mat dst, cpy_type=COPY_TYPE.CPU_CPU)
 Copies data to another sl.Mat (deep copy). More...
 
ERROR_CODE set_from (self, Mat src, cpy_type=COPY_TYPE.CPU_CPU)
 Copies data from an other sl.Mat (deep copy). More...
 
ERROR_CODE read (self, str filepath)
 Reads an image from a file (only if sl.MEM.CPU is available on the current sl.Mat). More...
 
ERROR_CODE write (self, str filepath, memory_type=MEM.CPU, compression_level=-1)
 Writes the sl.Mat (only if sl.MEM.CPU is available on the current sl.Mat) into a file as an image. More...
 
ERROR_CODE set_to (self, value, memory_type=MEM.CPU)
 Fills the sl.Mat with the given value. More...
 
ERROR_CODE set_value (self, int x, int y, value, memory_type=MEM.CPU)
 Sets a value to a specific point in the matrix. More...
 
ERROR_CODE get_value (self, int x, int y, memory_type=MEM.CPU)
 Returns the value of a specific point in the matrix. More...
 
int get_width (self)
 Returns the width of the matrix. More...
 
int get_height (self)
 Returns the height of the matrix. More...
 
Resolution get_resolution (self)
 Returns the resolution (width and height) of the matrix. More...
 
int get_channels (self)
 Returns the number of values stored in one pixel. More...
 
MAT_TYPE get_data_type (self)
 Returns the format of the matrix. More...
 
MEM get_memory_type (self)
 Returns the type of memory (CPU and/or GPU). More...
 
np.array numpy (self, force=False)
 Returns the sl.Mat as a NumPy array. More...
 
np.array get_data (self, memory_type=MEM.CPU, deep_copy=False)
 Cast the data of the sl.Mat in a NumPy array (with or without copy). More...
 
int get_step_bytes (self, memory_type=MEM.CPU)
 Returns the memory step in bytes (size of one pixel row). More...
 
int get_step (self, memory_type=MEM.CPU)
 Returns the memory step in number of elements (size in one pixel row). More...
 
int get_pixel_bytes (self)
 Returns the size of one pixel in bytes. More...
 
int get_width_bytes (self)
 Returns the size of a row in bytes. More...
 
str get_infos (self)
 Returns the information about the sl.Mat into a string. More...
 
bool is_init (self)
 Returns whether the sl.Mat is initialized or not. More...
 
bool is_memory_owner (self)
 Returns whether the sl.Mat is the owner of the memory it accesses. More...
 
ERROR_CODE clone (self, Mat py_mat)
 Duplicates a sl.Mat by copy (deep copy). More...
 
ERROR_CODE move (self, Mat py_mat)
 Moves the data of the sl.Mat to another sl.Mat. More...
 
int get_pointer (self, memory_type=MEM.CPU)
 Gets the pointer of the content of the sl.Mat. More...
 
str name (self)
 The name of the sl.Mat (optional). More...
 
int timestamp (self)
 Timestamp of the last manipulation of the data of the matrix by a method/function.
 
bool verbose (self)
 Whether the sl.Mat can display information.
 

Static Functions

None swap (Mat mat1, Mat mat2)
 Swaps the content of the provided sl::Mat (only swaps the pointers, no data copy). More...
 

Detailed Description

Class representing 1 to 4-channel matrix of float or uchar, stored on CPU and/or GPU side.

This class is defined in a row-major order, meaning that for an image buffer, the rows are stored consecutively from top to bottom.

Note
The ZED SDK Python wrapper does not support GPU data storage/access.

Functions

◆ __cinit__()

Mat __cinit__ (   self,
  width = 0,
  height = 0,
  mat_type = MAT_TYPE.F32_C1,
  memory_type = MEM.CPU 
)

Default constructor.

Parameters
width: Width of the matrix in pixels. Default: 0
height: Height of the matrix in pixels. Default: 0
mat_type: Type of the matrix (sl.MAT_TYPE.F32_C1, sl.MAT_TYPE.U8_C4, etc.).
Default: sl.MAT_TYPE.F32_C1
memory_type: Where the buffer will be stored. Default: sl.MEM.CPU (you cannot change this default value)
mat = sl.Mat(width=0, height=0, mat_type=sl.MAT_TYPE.F32_C1, memory_type=sl.MEM.CPU)

◆ init_mat_type()

None init_mat_type (   self,
  width,
  height,
  mat_type,
  memory_type = MEM.CPU 
)

Initilizes a new sl.Mat and allocates the requested memory by calling alloc_size().

Parameters
width: Width of the matrix in pixels. Default: 0
height: Height of the matrix in pixels. Default: 0
mat_type: Type of the matrix (sl.MAT_TYPE.F32_C1, sl.MAT_TYPE.U8_C4, etc.).
Default: sl.MAT_TYPE.F32_C1
memory_type: Where the buffer will be stored. Default: sl.MEM.CPU (you cannot change this default value)

◆ init_mat_cpu()

None init_mat_cpu (   self,
int  width,
int  height,
MAT_TYPE  mat_type,
  ptr,
  step,
  memory_type = MEM.CPU 
)

Initilizes a new sl.Mat from an existing data pointer.

This method does not allocate the memory.

Parameters
width: Width of the matrix in pixels.
height: Height of the matrix in pixels.
mat_type: Type of the matrix (sl.MAT_TYPE.F32_C1, sl.MAT_TYPE.U8_C4, etc.).
Default: sl.MAT_TYPE.F32_C1
ptr: Pointer to the data array.
step: Step of the data array (bytes size of one pixel row).
memory_type: Where the buffer will be stored. Default: sl.MEM.CPU (you cannot change this default value)

◆ init_mat_resolution()

None init_mat_resolution (   self,
Resolution  resolution,
MAT_TYPE  mat_type,
  memory_type = MEM.CPU 
)

Initilizes a new sl.Mat and allocates the requested memory by calling alloc_size().

Parameters
resolution: Size of the matrix in pixels.
mat_type: Type of the matrix (sl.MAT_TYPE.F32_C1, sl.MAT_TYPE.U8_C4, etc.).
Default: sl.MAT_TYPE.F32_C1
memory_type: Where the buffer will be stored. Default: sl.MEM.CPU (you cannot change this default value)

◆ init_mat_resolution_cpu()

None init_mat_resolution_cpu (   self,
Resolution  resolution,
  mat_type,
  ptr,
  step,
  memory_type = MEM.CPU 
)

Initilizes a new sl.Mat from an existing data pointer.

This method does not allocate the memory.

Parameters
resolution: the size of the matrix in pixels.
mat_type: Type of the matrix (sl.MAT_TYPE.F32_C1, sl.MAT_TYPE.U8_C4, etc.).
Default: sl.MAT_TYPE.F32_C1
ptr: Pointer to the data array (CPU or GPU).
step: Step of the data array (bytes size of one pixel row).
memory_type: Where the buffer will be stored. Default: sl.MEM.CPU (you cannot change this default value)

◆ init_mat()

None init_mat (   self,
Mat  matrix 
)

Initilizes a new sl.Mat by copy (shallow copy).

This method does not allocate the memory.

Parameters
mat: sl.Mat to copy.

◆ alloc_size()

None alloc_size (   self,
  width,
  height,
  mat_type,
  memory_type = MEM.CPU 
)

Allocates the sl.Mat memory.

Parameters
width: Width of the matrix in pixels.
height: Height of the matrix in pixels.
mat_type: Type of the matrix (sl.MAT_TYPE.F32_C1, sl.MAT_TYPE.U8_C4, etc.).
Default: sl.MAT_TYPE.F32_C1
memory_type: Where the buffer will be stored. Default: sl.MEM.CPU (you cannot change this default value)
Warning
It erases previously allocated memory.

◆ alloc_resolution()

None alloc_resolution (   self,
Resolution  resolution,
MAT_TYPE  mat_type,
  memory_type = MEM.CPU 
)

Allocates the sl.Mat memory.

Parameters
resolution: Size of the matrix in pixels.
mat_type: Type of the matrix (sl.MAT_TYPE.F32_C1, sl.MAT_TYPE.U8_C4, etc.).
Default: sl.MAT_TYPE.F32_C1
memory_type: Where the buffer will be stored. Default: sl.MEM.CPU (you cannot change this default value)
Warning
It erases previously allocated memory.

◆ free()

None free (   self,
  memory_type = MEM.CPU 
)

Free the owned memory.

Parameters
memory_type: Specifies which memory you wish to free. Default: sl.MEM.CPU (you cannot change this default value)

◆ copy_to()

ERROR_CODE copy_to (   self,
Mat  dst,
  cpy_type = COPY_TYPE.CPU_CPU 
)

Copies data to another sl.Mat (deep copy).

Parameters
dst: sl.Mat where the data will be copied to.
cpy_type: Specifies the memory that will be used for the copy. Default: sl.COPY_TYPE.CPU_CPU (you cannot change this default value)
Returns
sl.ERROR_CODE.SUCCESS if everything went well, sl.ERROR_CODE.FAILURE otherwise.
Note
If the destination is not allocated or does not have a compatible sl.MAT_TYPE or sl.Resolution, current memory is freed and new memory is directly allocated.

◆ set_from()

ERROR_CODE set_from (   self,
Mat  src,
  cpy_type = COPY_TYPE.CPU_CPU 
)

Copies data from an other sl.Mat (deep copy).

Parameters
src: sl.Mat where the data will be copied from.
cpy_type: Specifies the memory that will be used for the copy. Default: sl.COPY_TYPE.CPU_CPU (you cannot change this default value)
Returns
sl.ERROR_CODE.SUCCESS if everything went well, sl.ERROR_CODE.FAILURE otherwise.
Note
If the destination is not allocated or does not have a compatible sl.MAT_TYPE or sl.Resolution, current memory is freed and new memory is directly allocated.

◆ read()

ERROR_CODE read (   self,
str  filepath 
)

Reads an image from a file (only if sl.MEM.CPU is available on the current sl.Mat).

Supported input files format are PNG and JPEG.

Parameters
filepath: Path of the file to read from (including the name and extension).
Returns
sl.ERROR_CODE.SUCCESS if everything went well, sl.ERROR_CODE.FAILURE otherwise.
Note
Supported sl.MAT_TYPE are :

◆ write()

ERROR_CODE write (   self,
str  filepath,
  memory_type = MEM.CPU,
  compression_level = -1 
)

Writes the sl.Mat (only if sl.MEM.CPU is available on the current sl.Mat) into a file as an image.

Supported output files format are PNG and JPEG.

Parameters
filepath: Path of the file to write (including the name and extension).
memory_type: Memory type of the sl.Mat. Default: sl.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)).
Note
Specific/default value for compression_level = -1 : This will set the default quality for PNG(30) or JPEG(5).
compression_level is only supported for U8_Cx.
Returns
sl.ERROR_CODE.SUCCESS if everything went well, sl.ERROR_CODE.FAILURE otherwise.
Note
Supported sl.MAT_TYPE are :

◆ set_to()

ERROR_CODE set_to (   self,
  value,
  memory_type = MEM.CPU 
)

Fills the sl.Mat with the given value.

This method overwrites all the matrix.

Parameters
value: Value to be copied all over the matrix.
memory_type: Which buffer to fill. Default: sl.MEM.CPU (you cannot change the default value)

◆ set_value()

ERROR_CODE set_value (   self,
int  x,
int  y,
  value,
  memory_type = MEM.CPU 
)

Sets a value to a specific point in the matrix.

Parameters
x: Column of the point to change.
y: Row of the point to change.
value: Value to be set.
memory_type: Which memory will be updated.
Returns
sl.ERROR_CODE.SUCCESS if everything went well, sl.ERROR_CODE.FAILURE otherwise.
Warning
Not efficient for sl.MEM.GPU, use it on sparse data.

◆ get_value()

ERROR_CODE get_value (   self,
int  x,
int  y,
  memory_type = MEM.CPU 
)

Returns the value of a specific point in the matrix.

Parameters
x: Column of the point to get the value from.
y: Row of the point to get the value from.
memory_type: Which memory should be read.
Returns
sl.ERROR_CODE.SUCCESS if everything went well, sl.ERROR_CODE.FAILURE otherwise.
Warning
Not efficient for sl.MEM.GPU, use it on sparse data.

◆ get_width()

int get_width (   self)

Returns the width of the matrix.

Returns
Width of the matrix in pixels.

◆ get_height()

int get_height (   self)

Returns the height of the matrix.

Returns
Height of the matrix in pixels.

◆ get_resolution()

Resolution get_resolution (   self)

Returns the resolution (width and height) of the matrix.

Returns
Resolution of the matrix in pixels.

◆ get_channels()

int get_channels (   self)

Returns the number of values stored in one pixel.

Returns
Number of values in a pixel.

◆ get_data_type()

MAT_TYPE get_data_type (   self)

Returns the format of the matrix.

Returns
Format of the current sl.Mat.

Referenced by Mat.get_value(), Mat.set_to(), and Mat.set_value().

◆ get_memory_type()

MEM get_memory_type (   self)

Returns the type of memory (CPU and/or GPU).

Returns
Type of allocated memory.

◆ numpy()

np.array numpy (   self,
  force = False 
)

Returns the sl.Mat as a NumPy array.

This is for convenience to mimic the PyTorch API.
This is like an alias of get_data() method.

Parameters
force: Whether the memory of the sl.Mat need to be duplicated.
Returns
NumPy array containing the sl.Mat data.
Note
The fastest is force at False but the sl.Mat memory must not be released to use the NumPy array.

◆ get_data()

np.array get_data (   self,
  memory_type = MEM.CPU,
  deep_copy = False 
)

Cast the data of the sl.Mat in a NumPy array (with or without copy).

Parameters
memory_type: Which memory should be read. Default: MEM.CPU (you cannot change the default value)
deep_copy: Whether the memory of the sl.Mat need to be duplicated.
Returns
NumPy array containing the sl.Mat data.
Note
The fastest is deep_copy at False but the sl.Mat memory must not be released to use the NumPy array.

Referenced by Mat.numpy().

◆ get_step_bytes()

int get_step_bytes (   self,
  memory_type = MEM.CPU 
)

Returns the memory step in bytes (size of one pixel row).

Parameters
memory_type: Specifies whether you want sl.MEM.CPU or sl.MEM.GPU step.
Default: sl.MEM.CPU (you cannot change the default value)
Returns
The step in bytes of the specified memory.

◆ get_step()

int get_step (   self,
  memory_type = MEM.CPU 
)

Returns the memory step in number of elements (size in one pixel row).

Parameters
memory_type: Specifies whether you want sl.MEM.CPU or sl.MEM.GPU step.
Default: sl.MEM.CPU (you cannot change the default value)
Returns
The step in number of elements.

◆ get_pixel_bytes()

int get_pixel_bytes (   self)

Returns the size of one pixel in bytes.

Returns
Size of a pixel in bytes.

◆ get_width_bytes()

int get_width_bytes (   self)

Returns the size of a row in bytes.

Returns
Size of a row in bytes.

◆ get_infos()

str get_infos (   self)

Returns the information about the sl.Mat into a string.

Returns
String containing the sl.Mat information.

Referenced by Matrix4f.m(), and Mat.verbose().

◆ is_init()

bool is_init (   self)

Returns whether the sl.Mat is initialized or not.

Returns
True if current sl.Mat has been allocated (by the constructor or therefore).

◆ is_memory_owner()

bool is_memory_owner (   self)

Returns whether the sl.Mat is the owner of the memory it accesses.

If not, the memory won't be freed if the sl.Mat is destroyed.

Returns
True if the sl.Mat is owning its memory, else False.

◆ clone()

ERROR_CODE clone (   self,
Mat  py_mat 
)

Duplicates a sl.Mat by copy (deep copy).

Parameters
py_mat: sl.Mat to copy.

This method copies the data array(s) and it marks the new sl.Mat as the memory owner.

◆ move()

ERROR_CODE move (   self,
Mat  py_mat 
)

Moves the data of the sl.Mat to another sl.Mat.

This method gives the attribute of the current s.Mat to the specified one. (No copy.)

Parameters
py_mat: sl.Mat to move to.
Note
: The current sl.Mat is then no more usable since its loose its attributes.

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().

◆ swap()

None swap ( Mat  mat1,
Mat  mat2 
)
static

Swaps the content of the provided sl::Mat (only swaps the pointers, no data copy).

Parameters
mat1: First matrix to swap.
mat2: Second matrix to swap.

◆ get_pointer()

int get_pointer (   self,
  memory_type = MEM.CPU 
)

Gets the pointer of the content of the sl.Mat.

Parameters
memory_type: Which memory you want to get. Default: sl.MEM.CPU (you cannot change the default value)
Returns
Pointer of the content of the sl.Mat.

◆ name()

str name (   self)

The name of the sl.Mat (optional).

In verbose mode, it iss used to indicate which sl.Mat is printing information.
Default set to "n/a" to avoid empty string if not filled.