我是 openCV 的新手,这是我对矩阵维度主题的第一个疑问。
我正在通过函数 cv::calcHist(..) 计算彩色图像的直方图。
如我所料,生成的矩阵是一个 3D 矩阵。我猜第三维意味着每个 RGB 颜色 channel 的颜色,但我不知道如何访问它们。计算后,我有一个 3 维和 1 channel 的矩阵,我希望能够访问每个维度。
我认为 split 函数在这里无济于事,因为它只是将矩阵拆分为其 channel 。
调试我从 3D 直方图矩阵中获得以下相关信息:
尺寸:3, 行数:-1, 列:-1, 尺寸:256
我知道我可以获得单独的颜色直方图,方法是首先将图像分成 3 个 channel ,然后计算每个 channel 的一维直方图,但我想知道 openCV 中的维度是如何工作的。
提前致谢!
最佳答案
这是来自 Opencv 对 MatND 类的引用:
// return pointer to the element (versions for 1D, 2D, 3D and generic nD cases)
uchar* ptr(int i0);
const uchar* ptr(int i0) const;
uchar* ptr(int i0, int i1);
const uchar* ptr(int i0, int i1) const;
uchar* ptr(int i0, int i1, int i2);
const uchar* ptr(int i0, int i1, int i2) const;
uchar* ptr(const int* idx);
const uchar* ptr(const int* idx) const;
// convenient template methods for element access.
// note that _Tp must match the actual matrix type -
// the functions do not do any on-fly type conversion
template<typename _Tp> _Tp& at(int i0);
template<typename _Tp> const _Tp& at(int i0) const;
template<typename _Tp> _Tp& at(int i0, int i1);
template<typename _Tp> const _Tp& at(int i0, int i1) const;
template<typename _Tp> _Tp& at(int i0, int i1, int i2);
template<typename _Tp> const _Tp& at(int i0, int i1, int i2) const;
template<typename _Tp> _Tp& at(const int* idx);
template<typename _Tp> const _Tp& at(const int* idx) const;
因此,您可以使用 3 个元素的数组作为 .at 方法的参数来设置所需的元素位置。
关于c++ - 颜色直方图openCV中的访问维度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26104109/