1

我正在尝试使用以下代码:

    cv::MatND hist;
    cv::Mat image = cv::imread("image.bmp");
    float *range = new float[33];
    int histSize = 32;
    int channel = 0;
    for (int i = 0; i < 33; ++i)
        range[i] = (float)6602.0 + 21*i;
    float **ranges = &range;
    cv::calcHist(&frame.get<0>(), 1, &channel, cv::Mat(), hist, 1, &histSize, ranges, false, false);

图像是灰度的,所以我使用第零个通道来获取直方图,我知道范围是统一的,但我想准确地知道我的边界,并且图像是 CV_16U 类型(在原始代码中,图像是从相机,但这太长了,不能在这里包含)

我的问题是在编译时出现以下错误:

    error C2665: 'cv::calcHist' : none of the 3 overloads could convert all the argument types
    C:\opencv\build_x64\include\opencv2/imgproc/imgproc.hpp(670): could be 'void     cv::calcHist(const cv::Mat *,int,const int *,cv::InputArray,cv::OutputArray,int,const int *,const float **,bool,bool)'
    C:\opencv\build_x64\include\opencv2/imgproc/imgproc.hpp(676): or 'void cv::calcHist(const cv::Mat *,int,const int *,cv::InputArray,cv::SparseMat &,int,const int *,const float **,bool,bool)'
    while trying to match the argument list '(cv::Mat *, int, int *, cv::Mat, cv::MatND, int, int *, float **, bool, bool)'

我知道这有点傻,但我快要发疯了。任何帮助表示赞赏。PS:我在 64 位环境中的 Microsoft Visual C++ express 上使用 opencv 2.4.2。

最好的,

巴里斯

4

1 回答 1

0

如果您的 OpenCV 版本比 2.3 新,这似乎是这种情况,您应该知道这一点cv::Matcv::MatND结合在一起。

但是关于错误,因为在新的 OpenCVcv::Mat中可以有任意数量的维度,它们已经改变了定义,你可以在这里看到:

C++: void calcHist(const Mat* images, int nimages, const int* channels, InputArray mask, OutputArray hist, int dims, const int* histSize, const float** ranges, bool uniform=true, bool accumulate=false )
C++: void calcHist(const Mat* images, int nimages, const int* channels, InputArray mask, SparseMat& hist, int dims, const int* histSize, const float** ranges, bool uniform=true, bool accumulate=false )

您还可以在此处的全新教程中看到,一个简单的cv::Mat方法就可以了:

cv::Mat hist;

使用新的文档将帮助您清除这些东西,不幸的是,大多数可用的教程和代码都是基于旧的 OpenCV,它已经进行了很大的更改以达到当前版本。

于 2012-08-20T23:06:15.033 回答