[英]Argument list error using calcHist() function in OpenCV
I'm trying to use the following code: 我正在尝试使用以下代码:
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 = ⦥
cv::calcHist(&frame.get<0>(), 1, &channel, cv::Mat(), hist, 1, &histSize, ranges, false, false);
The image is grayscale, so I'm using the zeroth channel to get the histogram, I know the range is uniform but I wanted to know my boundaries exactly, and the image is CV_16U type (in the original code the image is read from a camera, but that's too long to include here) 图像是灰度的,所以我正在使用第零个通道来获取直方图,我知道范围是均匀的,但是我想确切地知道边界,并且图像是CV_16U类型(在原始代码中,图像是从相机,但在此处无法包含在内)
My problem is that at compilation I get the following errors: 我的问题是在编译时出现以下错误:
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)'
I know its kind of silly, but I'm about to go crazy. 我知道这很傻,但是我快要疯了。 Any help is appreciated. 任何帮助表示赞赏。 PS: I'm using opencv 2.4.2 on Microsoft Visual C++ express in 64-bit environment. PS:我在64位环境中的Microsoft Visual C ++ Express上使用opencv 2.4.2。
Best, 最好,
Baris 巴里斯
If your OpenCV version is newer than 2.3, which seems to be the case, you should know that cv::Mat
and cv::MatND
are combined. 如果您的OpenCV版本比2.3更高,那么您应该知道cv::Mat
和cv::MatND
是结合在一起的。
But about the error, as in the new OpenCV cv::Mat
can have any number of dimensions, they have changed the definition, as you can see here : 但是关于错误,如新的OpenCV cv::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 )
You can also see in the brand new tutorial here , a simple cv::Mat
would do the trick: 您还可以在这里的全新教程中看到一个简单的cv::Mat
可以解决问题:
cv::Mat hist;
Using the new documentation would help you clear these things up, unfortunately most of the tutorials and codes available are based on the old OpenCV which has undertaken big changes to get to the current version. 使用新的文档将帮助您清除这些问题,不幸的是,大多数可用的教程和代码都是基于旧的OpenCV的,该版本已进行了较大的更改以更新到当前版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.