Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv 规范化直方图时出现编译器错误_Opencv_Visual C++ - Fatal编程技术网

Opencv 规范化直方图时出现编译器错误

Opencv 规范化直方图时出现编译器错误,opencv,visual-c++,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 pl

我使用以下代码规范化视频文件中帧序列的直方图,并且仅当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;
}
bool
DMSUSBVideoDevicePlugin::_hasImageChanged()
{
使用名称空间cv;
Mat src=cv::Mat(_captureHeight,_captureWidth,cv_8UC3,(void*)_imageData);
///将图像分为三个位置(B、G和R)
矢量bgr_平面;
拆分(src、bgr_平面);
///确定垃圾箱的数量
int histSize=256;
///设置范围(对于B、G、R))
浮动范围[]={0,256};
常量浮点*histRange={range};
布尔一致=真;
布尔累积=假;
斯巴达b_hist,g_hist,r_hist;
///计算直方图:
calcHist(&bgr_平面[1],1,0,Mat(),g_hist,1,&histSize,&histRange,均匀,累积);
//绘制B、G和R的直方图
int hist_w=512;int hist_h=400;
int bin_w=cvRound((双)hist_w/histSize);
Mat histImage(hist_h,hist_w,CV_8UC3,标量(0,0,0));
规范化(g_hist,g_hist,0.0,histImage.rows,32,-1,SparseMat());
静态bool isFirstFrame=true;
if(isFirstFrame)
{
_lastGreenHistogram=g_hist;
isFirstFrame=false;
返回true;
}
double diff=比较列表(g_hist,_lastGreenHistogram,CV_COMP_BHATTACHARYYA);
_lastGreenHistogram=g_hist;
标准::cout
C:\opencv\build\include\opencv2/core/core.hpp(2023):可能是“void” cv::normalize(cv::InputArray,cv::OutputArray,double,double,int,int,cv::InputArray)'


我做错了什么?

您试图将
SparseMat
转换为
InputArray
。这是不合法的。InputArray需要具有顺序内存的容器。 从文档中:

其中InputArray是一个可以从Mat构造的类, Mat,Matx,std::vector,std::vector> 或者std::vector。它也可以由矩阵构造 表情

您可以在InputArray上阅读

您应该使用常规的
cv::Mat
对象,因为normalize函数不会创建源代码的副本。 输出阵列也是如此