OpenCV 3.0打印垫

OpenCV 3.0打印垫,opencv,histogram,Opencv,Histogram,我是OpenCV的新手,所以请容忍我。。我正在尝试转储给定图像的直方图对象。。它失败了,错误如下-感谢您的帮助 以下程序中的第一列(即加载的图像)打印成功,而图像历史记录的第二列打印失败,出现以下错误 OpenCV错误:断言失败(基于OpenCV 2.4.9源代码的m.dims) static inline std::ostream& operator << (std::ostream& out, const Mat& mtx) { Formatter

我是OpenCV的新手,所以请容忍我。。我正在尝试转储给定图像的直方图对象。。它失败了,错误如下-感谢您的帮助

以下程序中的第一列(即加载的图像)打印成功,而图像历史记录的第二列打印失败,出现以下错误


OpenCV错误:断言失败(基于OpenCV 2.4.9源代码的m.dims)

static inline std::ostream& operator << (std::ostream& out, const Mat& mtx)
{
    Formatter::get()->write(out, mtx);
    return out;
}

正如您所看到的,如果
Mat
维度大于2,则会像在代码中一样抛出断言(
CV_Assert(m.dimsHave)您是否检查了Mat hist是否在离开calcHist()函数体时初始化?如果我这样做,它会打印void printMatrix(Mat mnd){for(int I=0;I<4;I++){for(intj=0;j<4;j++){for(intk=0;k<4;k++){cout
#include <stdio.h>
#include <string>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main(int argc, char** argv) {
    if (argc != 2) {
        printf("usage: opencv.out <Image_Path>\n");
        return -1;
    }

    string imagePath = (argv[1]);

    cout << "loading image..." << imagePath << endl;

    Mat image = imread(imagePath, 1);

    Mat hist;

    int imgCount = 1;
    int dims = 3;
    const int histSizes[] = {4, 4, 4};
    const int channels[] = {0, 1, 2};
    float rRange[] = {0, 256};
    float gRange[] = {0, 256};
    float bRange[] = {0, 256};
    const float *ranges[] = {rRange, gRange, bRange};
    Mat mask = Mat();

    calcHist(&image, imgCount, channels, mask, hist, dims, histSizes, ranges);

    cout << image << "Loaded image..." << endl;
    cout << "Hist of image..." << hist;
    return 0;
}
static inline std::ostream& operator << (std::ostream& out, const Mat& mtx)
{
    Formatter::get()->write(out, mtx);
    return out;
}
static void writeMat(std::ostream& out, const Mat& m, char rowsep, char elembrace, bool singleLine)
{
    CV_Assert(m.dims <= 2);
    int type = m.type();

    char crowbrace = getCloseBrace(rowsep);
    char orowbrace = crowbrace ? rowsep : '\0';

    if( orowbrace || isspace(rowsep) )
        rowsep = '\0';

    for( int i = 0; i < m.rows; i++ )
    {
        if(orowbrace)
            out << orowbrace;
        if( m.data )
            writeElems(out, m.ptr(i), m.cols, type, elembrace);
        if(orowbrace)
            out << crowbrace << (i+1 < m.rows ? ", " : "");
        if(i+1 < m.rows)
        {
            if(rowsep)
                out << rowsep << (singleLine ? " " : "");
            if(!singleLine)
                out << "\n  ";
        }
    }
}