Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

calcHist returns invalid Mat (n-dimensional histogram, n>=3)

Hi there,

I want to calculate a n-dimensional histogram of an image (sample code below n=3), but calcHist returns an invalid Mat resulting in an error in normalize:

Mat hist_tmp;

const int K = 8;
const int nChannels = 3;
const int channels[K] = {0, 1, 2};
const int histSize[K] = {K, K, K};
const float range[2] = {0, 255};
const float* ranges[K] = {range, range, range};
calcHist( &_img, 1, channels, mask, hist_tmp, nChannels, histSize, ranges, true, false);

cout << "type "<< _img.type() << "|" << hist_tmp.type() << "\n";
cout << "rows "<< _img.rows << "|" << hist_tmp.rows << "\n";
cout << "columns "<< _img.cols << "|" << hist_tmp.cols << "\n";
cout << "channels "<< _img.channels() << "|" << hist_tmp.channels() << "\n";

normalize(hist_tmp, hist_tmp, 0, 255, NORM_MINMAX);

I get this error message:

type 16|5

rows 480|-1

columns 640|-1

channels 3|1

OpenCV Error: Assertion failed (img.dims <= 2) in minMaxLoc, file /build/opencv/src/opencv-2.4.8/modules/core/src/stat.cpp, line 1136 terminate called after throwing an instance of 'cv::Exception' what():

/build/opencv/src/opencv-2.4.8/modules/core/src/stat.cpp:1136: error: (-215) img.dims <= 2 in function minMaxLoc while executing normalize.

I know there are examples for generating a 3D-histogram (like here) but I can't see what I'm doing different/wrong!

Thanks! Torsten

calcHist returns invalid Mat (n-dimensional histogram, n>=3)

Hi there,

I want to calculate a n-dimensional histogram of an image (sample code below n=3), but calcHist returns an invalid Mat resulting in an error in normalize:

Mat hist_tmp;

const int K = 8;
const int nChannels = 3;
const int channels[K] channels[nChannels] = {0, 1, 2};
const int histSize[K] histSize[nChannels] = {K, K, K};
const float range[2] = {0, 255};
const float* ranges[K] ranges[nChannels] = {range, range, range};
calcHist( &_img, 1, channels, mask, hist_tmp, nChannels, histSize, ranges, true, false);

cout << "type "<< _img.type() << "|" << hist_tmp.type() << "\n";
cout << "rows "<< _img.rows << "|" << hist_tmp.rows << "\n";
cout << "columns "<< _img.cols << "|" << hist_tmp.cols << "\n";
cout << "channels "<< _img.channels() << "|" << hist_tmp.channels() << "\n";

normalize(hist_tmp, hist_tmp, 0, 255, NORM_MINMAX);

I get this error message:

type 16|5

rows 480|-1

columns 640|-1

channels 3|1

OpenCV Error: Assertion failed (img.dims <= 2) in minMaxLoc, file /build/opencv/src/opencv-2.4.8/modules/core/src/stat.cpp, line 1136 terminate called after throwing an instance of 'cv::Exception' what():

/build/opencv/src/opencv-2.4.8/modules/core/src/stat.cpp:1136: error: (-215) img.dims <= 2 in function minMaxLoc while executing normalize.

I know there are examples for generating a 3D-histogram (like here) but I can't see what I'm doing different/wrong!

Thanks! Torsten

calcHist returns invalid Mat (n-dimensional histogram, n>=3)

Hi there,

I want to calculate a n-dimensional histogram of an image (sample code below n=3), but calcHist returns an invalid Mat resulting in an error in normalize:

Mat hist_tmp;

const int K = 8;
const int nChannels = 3;
const int channels[nChannels] = {0, 1, 2};
const int histSize[nChannels] = {K, K, K};
const float range[2] = {0, 255};
const float* ranges[nChannels] = {range, range, range};
calcHist( &_img, 1, channels, mask, hist_tmp, nChannels, histSize, ranges, true, false);

cout << "type "<< _img.type() << "|" << hist_tmp.type() << "\n";
cout << "rows "<< _img.rows << "|" << hist_tmp.rows << "\n";
cout << "columns "<< _img.cols << "|" << hist_tmp.cols << "\n";
cout << "channels "<< _img.channels() << "|" << hist_tmp.channels() << "\n";

normalize(hist_tmp, hist_tmp, 0, 255, NORM_MINMAX);

I get this error message:

type 16|5

rows 480|-1

columns 640|-1

channels 3|1

OpenCV Error: Assertion failed (img.dims <= 2) in minMaxLoc, file /build/opencv/src/opencv-2.4.8/modules/core/src/stat.cpp, line 1136 terminate called after throwing an instance of 'cv::Exception' what():

/build/opencv/src/opencv-2.4.8/modules/core/src/stat.cpp:1136: error: (-215) img.dims <= 2 in function minMaxLoc while executing normalize.minMaxLoc

I know there are examples for generating a 3D-histogram (like here) but I can't see what I'm doing different/wrong!

Thanks! Torsten

click to hide/show revision 4
added comment about mask

calcHist returns invalid Mat (n-dimensional histogram, n>=3)

Hi there,

I want to calculate a n-dimensional histogram of an image (sample code below n=3), but calcHist returns an invalid Mat resulting in an error in normalize:

Mat hist_tmp;
//Mat1b mask (is a parameter of the function and not equal to Mat())

const int K = 8;
const int nChannels = 3;
const int channels[nChannels] = {0, 1, 2};
const int histSize[nChannels] = {K, K, K};
const float range[2] = {0, 255};
const float* ranges[nChannels] = {range, range, range};
calcHist( &_img, 1, channels, mask, hist_tmp, nChannels, histSize, ranges, true, false);

cout << "type "<< _img.type() << "|" << hist_tmp.type() << "\n";
cout << "rows "<< _img.rows << "|" << hist_tmp.rows << "\n";
cout << "columns "<< _img.cols << "|" << hist_tmp.cols << "\n";
cout << "channels "<< _img.channels() << "|" << hist_tmp.channels() << "\n";

normalize(hist_tmp, hist_tmp, 0, 255, NORM_MINMAX);

I get this error message:

type 16|5

rows 480|-1

columns 640|-1

channels 3|1

OpenCV Error: Assertion failed (img.dims <= 2) in minMaxLoc, file /build/opencv/src/opencv-2.4.8/modules/core/src/stat.cpp, line 1136 terminate called after throwing an instance of 'cv::Exception' what():

/build/opencv/src/opencv-2.4.8/modules/core/src/stat.cpp:1136: error: (-215) img.dims <= 2 in function minMaxLoc

I know there are examples for generating a 3D-histogram (like here) but I can't see what I'm doing different/wrong!

Thanks! Torsten