c++ - 颜色直方图openCV中的访问维度

标签 c++ opencv multidimensional-array histogram channel

我是 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/

相关文章:

python - 模仿OpenCV中的 "magic wand"photoshop工具

c - 如何声明和定义 2 维字符串

c++ - 如何将字符串中的所有数字保存到 C++ 中的多维数组中?

c++ - 更改派生类中打包结构的位大小

C++:简单的多线程示例并不比单线程快

c++ - std::vector<A> error C2582: 'operator =' 函数在

c++ - 使用 Img.at<cv::vec3???> 获取无符号短值

c++ - Armadillo :将立方体 subview (管)转换为 vector

python - 在已知 XY 坐标时绘制像素和轮廓

java - 一个元素在二维数组的列中出现的频率是多少?