gpt4 book ai didi

opencv - 直方图归一化时的编译器错误

转载 作者:行者123 更新时间:2023-12-02 17:13:17 25 4
gpt4 key购买 nike

我正在使用以下代码来规范视频文件中一系列帧的直方图,并且仅在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>.\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)'



我究竟做错了什么?

最佳答案

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

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.



您可以阅读InputArray here

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

关于opencv - 直方图归一化时的编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24858903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com