标准化直方图时编译器错误

时间:2014-07-21 06:31:30

标签: opencv visual-c++

我正在使用以下代码来规范化视频文件中帧序列的直方图,并且仅当compareHist方法返回的差异超过某个阈值时才更改帧:

bool
DMSUSBVideoDevicePlugin::_hasImageChanged()
{
    using namespace cv;
    Mat src = cv::Mat(_captureHeight, _captureWidth, CV_8UC3, (void*) _imageData);
    /// Separate the image in 3 places ( B, G and R )
    vector<Mat> bgr_planes;
    split( src, bgr_planes );

    /// Establish the number of bins
    int histSize = 256;

    /// Set the ranges ( for B,G,R) )
    float range[] = { 0, 256 } ;
    const float* histRange = { range };

    bool uniform = true; 
    bool accumulate = false;

    SparseMat b_hist, g_hist, r_hist;

    /// Compute the histograms:
    calcHist( &bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate);

    // Draw the histograms for B, G and R
    int hist_w = 512; int hist_h = 400;
    int bin_w = cvRound( (double) hist_w/histSize );
    Mat histImage( hist_h, hist_w, CV_8UC3, Scalar( 0,0,0) );

    normalize(g_hist, g_hist, 0.0, histImage.rows, 32, -1, SparseMat());

    static bool isFirstFrame = true;
    if(isFirstFrame)
    {
        _lastGreenHistogram = g_hist;
        isFirstFrame = false;
        return true;
    }

    double diff = compareHist(g_hist, _lastGreenHistogram, CV_COMP_BHATTACHARYYA );
    _lastGreenHistogram = g_hist;
    std::cout << "Diff val: " << diff << std::endl;
    if(diff > 1.f)
    {
        return true;
    }

    return false;
}

但是,我收到编译错误:

  

1&gt;。\ DMSUSBVideoDevicePlugin.cpp(454):错误C2665:&#39; cv :: normalize&#39; :   2个重载中没有一个可以转换所有参数类型1&gt;
  C:\ opencv \ build \ include \ opencv2 / core / core.hpp(2023):可能是&#39;无效   CV ::正常化(CV :: InputArray,CV :: OutputArray,双,双,INT,INT,CV :: InputArray)&#39;

我做错了什么?

1 个答案:

答案 0 :(得分:2)

您正在尝试将SparseMat转换为InputArray。这不合法。 InputArray需要一个具有顺序内存的容器。 来自文档:

  

其中 InputArray是一个可以从Mat构造的类,   Mat ,Matx,std :: vector,std :: vector&gt;   或std :: vector。它也可以由矩阵构造   表达

您可以阅读InputArray here

您应该使用常规cv::Mat对象,因为normalize函数不会创建源的副本。 对于OutputArray也是如此。