0
votes

I used a function called 'calcHist' in opencv. And its declaration is:

void calcHist(const Mat* arrays, int narrays, const int* channels, InputArray mask, OutputArray hist, int dims, const int* histSize, const float** ranges, bool uniform=true, bool accumulate=false )

I wrote a code snippets:

Mat img = imread("lena.jpg", CV_LOAD_IMAGE_GRAYSCALE);

Mat* arrays = &img;
int narrays = 1;
int channels[] = { 0 };
InputArray mask = noArray();
Mat hist;
int dims = 1;
int histSize[] = { 256 };   
float hranges[] = { 0.0, 255.0 };
float *ranges[] = { hranges };

calcHist(arrays, narrays, channels, mask, hist, dims, histSize, ranges);

and then got an error:IntelliSense: no instance of overloaded function "calcHist" matches the argument list
But if I prefix 'const' to 'float *ranges[] = {ranges};' like const float *ranges[] = { hranges }; it's okay.

So why this 'const' is necessary and the 'const' before histSize is not.

1
@super_ No, u cant initialize double dimensional arrays like that. - tmj
@Ggicci: Yes, you can initialize two dimensional arrays like that. But a two-dimensional array is not convertible to an array of pointers or a pointer to a pointer. - Benjamin Lindley

1 Answers

1
votes

T* implicitly converts to const T*. Correspondingly, this means T** implicitly converts to T*const*. T*const* is not const T**, so this conversion doesn't work to let you make the function call.