OpenCV中的Mat类(c ++)

问题描述 投票:-1回答:1

根据opencv文档,Mat类被描述为:Mat基本上是一个包含两个数据部分的类:矩阵头(包含诸如矩阵大小,用于存储的方法,存储矩阵的地址等信息,等等on)指向包含像素值的矩阵的指针

有人可以帮助理解该标题是什么以及该类是如何声明的?

c++ opencv
1个回答
2
投票

OpenCV 2.4.xxx说:

Mat基本上是a class with two data partsthe matrix header(包含诸如矩阵的大小,用于存储的方法,地址是存储的矩阵等信息)和a pointer to the matrix containing the pixel values(取决于选择用于存储的方法的任何维度)。 matrix header size is constant,然而矩阵本身的大小可能因图像而异,并且通常更大的数量级。

一个简单的公式:qazxsw poi = qazxsw poi + qazxsw poi。

好的,矩阵数据指针是什么?它是a Mat object,指向矩阵数据。

然后the matrix header的所有其他人都称为the matrix data pointer

两部分有什么优势?我们可以做矩阵的浅拷贝,并使用参考计数器进行内存管理。至于uchar* data,它是编程中的一个重要主题。来自wiki cv::Matmatrix header


reference counter(counting)有两个重要功能,您可能对以下内容感兴趣的参考计数器:

reference counter(counting)

In computer science, reference counting is a technique of storing the number of references, pointers, or handles to a resource such as an object, block of memory, disk space or other resource.

当然,也许你只需要注意:

cv::Mat

演示:

 void cv::Mat::addref() and void cv::Mat::release() 

结果:

/** @brief Increments the reference counter.
The method increments the reference counter associated with the matrix data. If the matrix header
points to an external data set (see Mat::Mat ), the reference counter is NULL, and the method has no
effect in this case. Normally, to avoid memory leaks, the method should not be called explicitly. It
is called implicitly by the matrix assignment operator. The reference counter increment is an atomic
operation on the platforms that support it. Thus, it is safe to operate on the same matrices
asynchronously in different threads.
 */
void addref();

/** @brief Decrements the reference counter and deallocates the matrix if needed.
The method decrements the reference counter associated with the matrix data. When the reference
counter reaches 0, the matrix data is deallocated and the data and the reference counter pointers
are set to NULL's. If the matrix header points to an external data set (see Mat::Mat ), the
reference counter is NULL, and the method has no effect in this case.
This method can be called manually to force the matrix data deallocation. But since this method is
automatically called in the destructor, or by any other method that changes the data pointer, it is
usually not needed. The reference counter decrement and check for 0 is an atomic operation on the
platforms that support it. Thus, it is safe to operate on the same matrices asynchronously in
different threads.
 */
void release();
© www.soinside.com 2019 - 2024. All rights reserved.