0
votes

I am using the following code to normalize the histogram of a sequence of frames from video file and change the frame only if difference returned by compareHist method is over a certain threshold:

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;
}

However, I get a compiler error saying:

1>.\DMSUSBVideoDevicePlugin.cpp(454) : error C2665: 'cv::normalize' : none of the 2 overloads could convert all the argument types 1>
C:\opencv\build\include\opencv2/core/core.hpp(2023): could be 'void cv::normalize(cv::InputArray,cv::OutputArray,double,double,int,int,cv::InputArray)'

What am I doing wrong?

1

1 Answers

2
votes

You're trying to convert an SparseMat to an InputArray. This isn't legal. InputArray expects a container with sequential memory. From the docs:

where InputArray is a class that can be constructed from Mat, Mat, Matx, std::vector, std::vector > or std::vector. It can also be constructed from a matrix expression.

You can read on InputArray here.

You should use a regular cv::Mat object as the normalize function will not create a copy of the source. Same goes for OutputArray.