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 | |
Mat () | |
empty Mat default constructor. More... | |
Mat (size_t width, size_t height, MAT_TYPE mat_type, MEM memory_type=MEM::CPU) | |
Mat constructor. More... | |
Mat (size_t width, size_t height, MAT_TYPE mat_type, sl::uchar1 *ptr, size_t step, MEM memory_type=MEM::CPU) | |
Mat constructor from an existing data pointer. More... | |
Mat (size_t width, size_t height, MAT_TYPE mat_type, sl::uchar1 *ptr_cpu, size_t step_cpu, sl::uchar1 *ptr_gpu, size_t step_gpu) | |
Mat constructor from two existing data pointers, CPU and GPU. More... | |
Mat (Resolution resolution, MAT_TYPE mat_type, MEM memory_type=MEM::CPU) | |
Mat constructor. More... | |
Mat (Resolution resolution, MAT_TYPE mat_type, sl::uchar1 *ptr, size_t step, MEM memory_type=MEM::CPU) | |
Mat constructor from an existing data pointer. More... | |
Mat (Resolution resolution, MAT_TYPE mat_type, sl::uchar1 *ptr_cpu, size_t step_cpu, sl::uchar1 *ptr_gpu, size_t step_gpu) | |
Mat constructor from two existing data pointers, CPU and GPU. More... | |
Mat (const Mat &mat) | |
Mat constructor by copy (shallow copy). More... | |
void | alloc (size_t width, size_t height, MAT_TYPE mat_type, MEM memory_type=MEM::CPU) |
Allocates the Mat memory. More... | |
void | alloc (Resolution resolution, MAT_TYPE mat_type, MEM memory_type=MEM::CPU) |
Allocates the Mat memory. More... | |
~Mat () | |
Mat destructor. This function calls free to release owned memory. More... | |
void | free (MEM memory_type=MEM::CPU|MEM::GPU) |
Free the owned memory. More... | |
Mat & | operator= (const Mat &that) |
Performs a shallow copy. More... | |
ERROR_CODE | updateCPUfromGPU (cudaStream_t stream=0) |
Downloads data from DEVICE (GPU) to HOST (CPU), if possible. More... | |
ERROR_CODE | updateGPUfromCPU (cudaStream_t stream=0, int GPU_id=0) |
Uploads data from HOST (CPU) to DEVICE (GPU), if possible. More... | |
ERROR_CODE | copyTo (Mat &dst, COPY_TYPE cpyType=COPY_TYPE::CPU_CPU, cudaStream_t stream=0) const |
Copies data an other Mat (deep copy). More... | |
ERROR_CODE | setFrom (const Mat &src, COPY_TYPE cpyType=COPY_TYPE::CPU_CPU, cudaStream_t stream=0) |
Copies data from an other Mat (deep copy). More... | |
ERROR_CODE | read (const String &filePath) |
Reads an image from a file. More... | |
ERROR_CODE | write (const String &filePath, sl::MEM memory_type=sl::MEM::CPU, int compression_level=-1) |
Writes the Mat (only if MEM::CPU is available) into a file defined by its extension. More... | |
template<typename T > | |
ERROR_CODE | setTo (T value, sl::MEM memory_type=MEM::CPU) |
Fills the Mat with the given value. More... | |
template<typename N > | |
ERROR_CODE | setValue (size_t x, size_t y, N value, sl::MEM memory_type=MEM::CPU) |
Sets a value to a specific point in the matrix. More... | |
template<typename N > | |
ERROR_CODE | getValue (size_t x, size_t y, N *value, MEM memory_type=MEM::CPU) const |
Returns the value of a specific point in the matrix. More... | |
size_t | getWidth () const |
Returns the width of the matrix. More... | |
size_t | getHeight () const |
Returns the height of the matrix. More... | |
Resolution | getResolution () const |
Returns the resolution (width and height) of the matrix. More... | |
size_t | getChannels () const |
Returns the number of values stored in one pixel. More... | |
MAT_TYPE | getDataType () const |
Returns the format of the matrix. More... | |
MEM | getMemoryType () const |
Returns the type of memory (CPU and/or GPU). More... | |
template<typename N > | |
N * | getPtr (MEM memory_type=MEM::CPU) const |
Returns the CPU or GPU data pointer. More... | |
size_t | getStepBytes (MEM memory_type=MEM::CPU) const |
Returns the memory step in Bytes (the Bytes size of one pixel row). More... | |
template<typename N > | |
size_t | getStep (MEM memory_type=MEM::CPU) const |
Returns the memory step in number of elements (the number of values in one pixel row). More... | |
size_t | getStep (MEM memory_type=MEM::CPU) const |
Returns the memory step in number of elements (the number of values in one pixel row). More... | |
size_t | getPixelBytes () const |
Returns the size in bytes of one pixel. More... | |
size_t | getWidthBytes () const |
Returns the size in bytes of a row. More... | |
String | getInfos () |
Returns the information about the Mat into a String. More... | |
bool | isInit () const |
Defines whether the Mat is initialized or not. More... | |
bool | isMemoryOwner () const |
Returns whether the Mat is the owner of the memory it accesses. More... | |
ERROR_CODE | clone (const Mat &src) |
Duplicates Mat by copy (deep copy). More... | |
ERROR_CODE | move (Mat &dst) |
Moves Mat data to another Mat. More... | |
Static Functions | |
static void | swap (Mat &mat1, Mat &mat2) |
Swaps the content of the provided Mat (only swaps the pointers, no data copy). More... | |
Attributes | |
String | name = "n/a" |
bool | verbose = false |
Timestamp | timestamp = 0 |
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 updateCPUfromGPU / updateGPUfromCPU 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 sl::Camera object. The destruction of the sl::Camera object deletes the CUDA context needed to free the GPU Mat memory.
Mat constructor.
This function directly allocates the requested memory. It calls alloc.
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. (MEM::CPU and/or MEM::GPU). |
Mat | ( | size_t | width, |
size_t | height, | ||
MAT_TYPE | mat_type, | ||
sl::uchar1 * | ptr, | ||
size_t | step, | ||
MEM | memory_type = MEM::CPU |
||
) |
Mat constructor 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. (MEM::CPU and/or MEM::GPU). |
Mat | ( | size_t | width, |
size_t | height, | ||
MAT_TYPE | mat_type, | ||
sl::uchar1 * | ptr_cpu, | ||
size_t | step_cpu, | ||
sl::uchar1 * | ptr_gpu, | ||
size_t | step_gpu | ||
) |
Mat constructor from two existing data pointers, CPU and GPU.
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_cpu | : CPU pointer to the data array. |
step_cpu | : step of the CPU data array (the Bytes size of one pixel row). |
ptr_gpu | : GPU pointer to the data array. |
step_gpu | : step of the GPU data array (the Bytes size of one pixel row). |
Mat | ( | Resolution | resolution, |
MAT_TYPE | mat_type, | ||
MEM | memory_type = MEM::CPU |
||
) |
Mat constructor.
This function directly allocates the requested memory. It calls alloc.
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 (MEM::CPU and/or MEM::GPU). |
Mat | ( | Resolution | resolution, |
MAT_TYPE | mat_type, | ||
sl::uchar1 * | ptr, | ||
size_t | step, | ||
MEM | memory_type = MEM::CPU |
||
) |
Mat constructor 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. (MEM::CPU and/or MEM::GPU). |
Mat | ( | Resolution | resolution, |
MAT_TYPE | mat_type, | ||
sl::uchar1 * | ptr_cpu, | ||
size_t | step_cpu, | ||
sl::uchar1 * | ptr_gpu, | ||
size_t | step_gpu | ||
) |
Mat constructor from two existing data pointers, CPU and GPU.
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_cpu | : CPU pointer to the data array. |
step_cpu | : step of the CPU data array (the Bytes size of one pixel row). |
ptr_gpu | : GPU pointer to the data array. |
step_gpu | : step of the GPU data array (the Bytes size of one pixel row). |
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. (MEM::CPU and/or MEM::GPU). |
void alloc | ( | Resolution | resolution, |
MAT_TYPE | mat_type, | ||
MEM | memory_type = MEM::CPU |
||
) |
Allocates the Mat memory.
resolution | : the size of the matrix in pixels. |
mat_type | : the type of the matrix (sl::MAT_TYPE::F32_C1,sl::MAT_TYPE::U8_C4...). |
memory_type | : defines where the buffer will be stored. (sl::MEM::CPU and/or sl::MEM::GPU). |
ERROR_CODE updateCPUfromGPU | ( | cudaStream_t | stream = 0 | ) |
Downloads data from DEVICE (GPU) to HOST (CPU), if possible.
stream | : specifies the GPU stream to be used to enable Asynchronous overlaping (default 0 is synchronous). |
ERROR_CODE updateGPUfromCPU | ( | cudaStream_t | stream = 0 , |
int | GPU_id = 0 |
||
) |
Uploads data from HOST (CPU) to DEVICE (GPU), if possible.
stream | : specifies the GPU stream to be used to enable Asynchronous overlaping (default 0 is synchronous). |
ERROR_CODE copyTo | ( | Mat & | dst, |
COPY_TYPE | cpyType = COPY_TYPE::CPU_CPU , |
||
cudaStream_t | stream = 0 |
||
) | const |
Copies data an other Mat (deep copy).
dst | : the Mat where the data will be copied. |
cpyType | : specifies the memories that will be used for the copy. |
stream | : specifies the GPU stream to be used to enable Asynchronous overlaping (default 0 is synchronous). |
ERROR_CODE setFrom | ( | const Mat & | src, |
COPY_TYPE | cpyType = COPY_TYPE::CPU_CPU , |
||
cudaStream_t | stream = 0 |
||
) |
Copies data from an other Mat (deep copy).
src | : the Mat where the data will be copied from. |
cpyType | : specifies the memories that will be used for the update. |
stream | : specifies the GPU stream to be used to enable Asynchronous overlaping (default 0 is synchronous). |
ERROR_CODE read | ( | const String & | filePath | ) |
Reads an image from a file.
filePath | : file path including the name and extension. |
ERROR_CODE write | ( | const String & | filePath, |
sl::MEM | memory_type = sl::MEM::CPU , |
||
int | compression_level = -1 |
||
) |
Writes the Mat (only if MEM::CPU is available) into a file defined by its extension.
filePath | : file path including the name and extension. |
memory_type | : memory type (CPU or GPU) of the Mat. |
compression_level | : level of compression between 0 (lowest compression == highest size == highest quality(jpg)) and 100 (highest compression == lowest size == lowest quality(jpg)). |
ERROR_CODE setTo | ( | T | value, |
sl::MEM | memory_type = MEM::CPU |
||
) |
ERROR_CODE setValue | ( | size_t | x, |
size_t | y, | ||
N | value, | ||
sl::MEM | 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. |
ERROR_CODE getValue | ( | size_t | x, |
size_t | y, | ||
N * | value, | ||
MEM | memory_type = MEM::CPU |
||
) | const |
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. |
|
inline |
Returns the width of the matrix.
|
inline |
Returns the height of the matrix.
|
inline |
Returns the resolution (width and height) of the matrix.
|
inline |
Returns the number of values stored in one pixel.
|
inline |
Returns the format of the matrix.
|
inline |
Returns the type of memory (CPU and/or GPU).
|
inline |
Returns the size in bytes of one pixel.
|
inline |
Returns the size in bytes of a row.
String getInfos | ( | ) |
|
inline |
|
inline |
ERROR_CODE clone | ( | const Mat & | src | ) |
ERROR_CODE move | ( | Mat & | dst | ) |
String name = "n/a" |
bool verbose = false |
Timestamp timestamp = 0 |