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

C++ 访问颜色直方图openCV中的维度,c++,opencv,multidimensional-array,histogram,channel,C++,Opencv,Multidimensional Array,Histogram,Channel,我是openCV的新手,这里是我对矩阵维度主题的第一个疑问 我通过函数cv::calcHist…计算彩色图像的直方图 正如我所预料的那样,生成的矩阵是一个3D矩阵。我猜第三维意味着每个RGB颜色通道的颜色,但我不知道如何访问它们。经过计算,我有一个3维1通道的矩阵,我希望能够访问每个维度 我认为split函数在这里没有帮助,因为它只将矩阵拆分为通道 调试我从3Dhistrogram矩阵中获得以下相关信息: 尺寸:3, 行:-1, 列:-1, 尺码:256 我知道我可以通过先将图像分割成3个通道,

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

我通过函数cv::calcHist…计算彩色图像的直方图

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

我认为split函数在这里没有帮助,因为它只将矩阵拆分为通道

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

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

我知道我可以通过先将图像分割成3个通道,然后计算每个通道的1D直方图来获得单独的颜色直方图,但我很想知道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方法的参数来设置所需的元素位置。

您看到了吗?您好,谢谢您的回答,但正如我提到的,他们之前正在分割图像并计算各个直方图。我问的是如何处理直接从彩色图像计算直方图得到的三维矩阵:cv::calcHist&image,1,通道,cv::Mat,hist,3,histSize,范围;这更多的是一个关于如何处理这些没有通道的维度的问题,而不是关于直方图的问题。