I try to get a histogram from my color (three-channel) image in OpenCV, but every time I make a calcHist histogram as follows:
ColorHistogram::ColorHistogram()
{
histSize[0]= histSize[1]= histSize[2]= 256;
hranges[0]= 0.0;
hranges[1]= 255.0;
ranges[0]= hranges;
ranges[1]= hranges;
ranges[2]= hranges;
channels[0]= 0;
channels[1]= 1;
channels[2]= 2;
}
cv::MatND ColorHistogram::getHistogram(const cv::Mat &image)
{
cv::MatND hist;
cv::calcHist(&image,
1,
channels,
cv::Mat(),
hist,
3,
histSize,
ranges
);
return hist;
}

When I try to pass a result, for example cv::minMaxLoc, I get an unhandled exception.
cv::Mat ColorHistogram::getHistogramImage(const cv::Mat &image){
cv::MatND hist = getHistogram(image);
double maxVal=0;
double minVal=0;
cv::minMaxLoc(hist, &minVal, &maxVal, 0, 0);
}
EDIT
I don't know if this is important, but I get this error in the console:
OpenCV error: statement failed (img.dims <= 2) in an unknown function, file C: \ slave \ WinInstallerMegaPack \ SRC \ OpenCV \ Modules \ kernel \ SRC \ stat.cpp, line 788
and mine image dims = 2
source
share