I am getting an ambiguity error in OpenCV when I am trying to calculate a histogram and was wondering if I was missing something. I took a look at the function parameters and saw that it took one of the following:
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 );
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 );
And in my code I have the following:
if(histMat.size > 0)
{
float hranges[2] = {0, 180};
float* phranges = hranges;
cv::Mat hist;
cv::Mat hsv;
cv::Mat hue;
cv::Mat mask;
cvtColor(histMat, hsv, CV_BGR2HSV);
int _vmin = vmin, _vmax = vmax;
inRange(hsv, cv::Scalar(0, smin, MIN(_vmin,_vmax)),
cv::Scalar(180, 256, MAX(_vmin, _vmax)), mask);
int ch[] = {0, 0};
hue.create(hsv.size(), hsv.depth());
mixChannels(&hsv, 1, &hue, 1, ch, 1);
if(eType == MODEL)
{
cv::Mat roi(hue, selection), maskroi(mask, selection);
cv::calcHist(&roi, 1, 0, maskroi, hist, 1, &hsize, &phranges);
cv::normalize(hist, hist, 0, 255, CV_MINMAX);
trackWindow = selection;
histimg = cv::Scalar::all(0);
int binW = histimg.cols / hsize;
cv::Mat buf(1, hsize, CV_8UC3);
for( int i = 0; i < hsize; i++ )
buf.at<cv::Vec3b>(i) = cv::Vec3b(cv::saturate_cast<uchar>(i*180./hsize), 255, 255);
cvtColor(buf, buf, CV_HSV2BGR);
for( int i = 0; i < hsize; i++ )
{
int val = cv::saturate_cast<int>(hist.at<float>(i)*histimg.rows/255);
cv::rectangle( histimg, cv::Point(i*binW,histimg.rows),
cv::Point((i+1)*binW,histimg.rows - val),
cv::Scalar(buf.at<cv::Vec3b>(i)), -1, 8 );
}
}
}
I am trying to figure out what I can change in order to get this code to compile. Also please note that this chunk of code is in a function for a class. I’m trying to separate most of the Histogram sample code into it’s own separate function that is called only at certain points so I am not sure if it has anything to do with the fact that phranges is set at an improper place or if my variables are set improperly.
Any advice is greatly appreciated.
Thanks
As mentioned in my comment above I had to place all variables in the function scope and not in the if check itself. I am not sure why that made a difference, but maybe it had something to do during compile time.