Ask Your Question

Torsten's profile - activity

2014-10-17 02:09:57 -0600 received badge  Student (source)
2014-01-20 15:06:15 -0600 commented question calcHist returns invalid Mat (n-dimensional histogram, n>=3)

ok, I know that it's an Mat containing only uchar blanks: uchar *p = hist_tmp.datastart; while(p < hist_tmp.dataend) { cout << "'" << *p << "'\n"; p += 8; }

I wonder why I am the only person having this problem - 3D histograms seem to work (for other people); btw I use OpenCV 2.4.8 ArchLinux x86_64

2014-01-20 14:38:25 -0600 commented question calcHist returns invalid Mat (n-dimensional histogram, n>=3)

I tried to convert hist_temp with split to a set of one channels images (which should have dims = 2), but as hist_temp.channels() is already one that didn't help. I can't even print hist_tmp because of dims = 3 (cout << hist_tmp). Any idea how I can debug this further?

2014-01-20 14:23:42 -0600 commented question calcHist returns invalid Mat (n-dimensional histogram, n>=3)

how can an one channel image have dims > 2? (hist_temp has dims = 3)

2014-01-20 14:06:40 -0600 commented question calcHist returns invalid Mat (n-dimensional histogram, n>=3)

ok, thanks - I will have a look at this - but rows/cols = -1 is a little bit strange?

2014-01-20 13:33:34 -0600 received badge  Editor (source)
2014-01-20 13:31:39 -0600 asked a question 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

2013-03-05 06:25:16 -0600 answered a question image comparison

you can use a histogram comparison: http://docs.opencv.org/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.html

or PSNR/MSSIM: http://docs.opencv.org/doc/tutorials/highgui/video-input-psnr-ssim/video-input-psnr-ssim.html

or you can detect keypoints from both images, compare them and count the number of "good" matches, if the number is high enough it is probably a match