【问题标题】:Access dimensions in color histogram openCV访问颜色直方图 openCV 中的维度
【发布时间】:2014-09-29 16:02:26
【问题描述】:

我是 openCV 的新手,这是我对矩阵维度主题的第一个疑问。

我正在通过函数 cv::calcHist(..) 计算彩色图像的直方图。

正如我所料,生成的矩阵是一个 3D 矩阵。我猜第三维是指每个 RGB 颜色通道的颜色,但我不知道如何访问它们。计算后,我有一个 3 维和 1 个通道的矩阵,我希望能够访问每个维度。

我认为 split 函数在这里无济于事,因为它只会将矩阵拆分为其通道。

调试我从 3Dhistrogram 矩阵中获得以下相关信息:

尺寸:3, 行:-1, 列:-1, 尺寸:256

我知道我可以通过首先将图像分成 3 个通道并随后计算每个通道的一维直方图来获得单个颜色直方图,但我很想知道 openCV 中的尺寸是如何工作的。

提前致谢!

【问题讨论】:

  • 你看到这个tutorial了吗?
  • 您好,感谢您的回答,但正如我提到的,他们之前正在拆分图像并计算各个直方图。我在询问处理由直接从彩色图像计算直方图产生的 3 维矩阵: cv::calcHist(&image,1,channels,cv::Mat(), hist,3,histSize,ranges);更多的是关于如何处理这些维度(无通道)的问题,而不是关于直方​​图的问题。

标签: c++ opencv multidimensional-array histogram channel


【解决方案1】:

这是来自 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 方法的参数来设置所需的元素位置。

【讨论】:

    猜你喜欢
    • 2012-03-10
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    相关资源
    最近更新 更多