1

所以我试图从我在 OpencCV 中生成的直方图中获取实际数据。我正在使用位于此处的代码,如下所示。但是,我不完全知道如何从中获取数据Mat。我看到了这个帖子,但是这个帖子hist.get(i, 0)用来获取直方图数据。但是,我的直方图Mat只包含 1 行......和 ​​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);
}

result变成Mat大小为 1 x 16384 的 a 并且值在Mat... 那么我将如何获得正确的直方图数据?

4

0 回答 0