C++ 来自Mat的Opencv直方图数据

C++ 来自Mat的Opencv直方图数据,c++,opencv,histogram,lbph-algorithm,C++,Opencv,Histogram,Lbph Algorithm,所以我试图从OpencCV中生成的直方图中获取实际数据。我使用的代码位于,可以在下面看到。但是,我不知道如何从这个Mat获取数据。我看到了这一点,但是帖子使用了hist.get(I,0)来获取直方图数据。但是,我的直方图Mat仅包含一行。。。和16384匹。相关代码如下 static Mat spatial_histogram(InputArray _src, int numPatterns, int grid_x, int grid_y, bo

所以我试图从OpencCV中生成的直方图中获取实际数据。我使用的代码位于,可以在下面看到。但是,我不知道如何从这个
Mat
获取数据。我看到了这一点,但是帖子使用了
hist.get(I,0)
来获取直方图数据。但是,我的直方图
Mat
仅包含一行。。。和16384匹。相关代码如下

static Mat spatial_histogram(InputArray _src, int numPatterns,
                         int grid_x, int grid_y, bool /*normed*/)
{
    Mat src = _src.getMat();
    // calculate LBP patch size
    int width = src.cols/grid_x;
    int height = src.rows/grid_y;
    // allocate memory for the spatial histogram
    Mat result = Mat::zeros(grid_x * grid_y, numPatterns, CV_32FC1);
    // return matrix with zeros if no data was given
    if(src.empty())
        return result.reshape(1,1);
    // initial result_row
    int resultRowIdx = 0;
    // iterate through grid
    for(int i = 0; i < grid_y; i++) {
        for(int j = 0; j < grid_x; j++) {
            Mat src_cell = Mat(src, Range(i*height,(i+1)*height), Range(j*width,(j+1)*width));
            Mat cell_hist = histc(src_cell, 0, (numPatterns-1), true);
            // copy to the result matrix
            Mat result_row = result.row(resultRowIdx);
            cell_hist.reshape(1,1).convertTo(result_row, CV_32FC1);
            // increase row count in result matrix
            resultRowIdx++;
        }
    }
    // return result as reshaped feature vector
    return result.reshape(1,1);
}
static Mat spatical_直方图(输入阵列_src,int numPatterns,
整数网格x,整数网格y,布尔/*赋范*/)
{
Mat src=_src.getMat();
//计算LBP面片大小
int width=src.cols/grid_x;
int height=src.rows/grid_y;
//为空间直方图分配内存
Mat结果=Mat::零(网格x*网格y,numPatterns,CV_32FC1);
//如果未给出数据,则返回带零的矩阵
if(src.empty())
返回结果。重塑(1,1);
//第一行的初始结果
int resultRowIdx=0;
//在网格中迭代
对于(int i=0;i

result
成为大小为1 x 16384的
Mat
,值在
Mat
中稀疏。。。那么,如何获得正确的直方图数据呢?

您得到的结果正是您想要的。你到底需要什么?您可以访问每个值,如:
float val=histogram.at(i)这很有趣,因为我也有同样的问题。你能提供你的工作代码吗?你有结果表,这正是你要找的。你到底需要什么?您可以访问每个值,如:
float val=histogram.at(i)这很有趣,因为我也有同样的问题。你能提供你的工作代码吗?