0

I am new in opencv and I want to calculate HSV histogram. I am refering the code provided in this link. https://docs.opencv.org/3.0-beta/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.html

I am using opencv version 3.3.1 and facing the following errors errors.

Using the same code, I did not do anychanges in the code except changing the image for HSV histogram. Where detectPerson is the video frame and hsv is cv mat object.

Anyone plzz help I am stuck here.

int h_bins = 50, s_bins = 60;
int histSize[] = {h_bins, s_bins};
// hue varies from 0 to 179, saturation from 0 to 255
float h_ranges[] = { 0, 180 };
float s_ranges[] = { 0, 256 };
const float* ranges[] = { h_ranges, s_ranges };
// Use the 0-th and 1-st channels
int channels[] = { 0, 1 };
cv::Mat hist_hsv, hist_hsv2;

cvtColor(detectPerson, hsv, COLOR_BGR2HSV );            
calcHist( &hsv, 1, 0, Mat(), hist_hsv, 2, histSize, ranges, true, false );
normalize( hist_hsv, hist_hsv, 0, 1, NORM_MINMAX, -1, Mat() );

Errors

int channels[] = { 0, 1 };
error: too many initializers for 'int [0]'
int histSize[] = {h_bins, s_bins}
error: too many initializers for 'int [0]'
float h_ranges[] = { 0, 180 };
error: too many initializers for 'float [0]'
float s_ranges[] = { 0, 256 };
error: too many initializers for 'float [0]'
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • 1
    Looks like something might be broken with your compiler. What happens if you just try to compile `int main() { int foo[] = {1, 2}; }`? – NathanOliver May 21 '19 at 14:40
  • 2
    Possible duplicate of [too many initializers for 'int \[0\]' c++](https://stackoverflow.com/questions/21152171/too-many-initializers-for-int-0-c) It seems you haven't give us [mcve]. I guess you have not closed some your class definition when the line `int channels[] = { 0, 1 };` comes. – 273K May 21 '19 at 14:55
  • I am working on ROS, and using opencv in ROS – Varsha Sachdeva May 21 '19 at 15:20
  • @NathanOliver I checked I closed all the classes and function body – Varsha Sachdeva May 21 '19 at 15:27

1 Answers1

0

Your compiler is defective, although this perplexes me since such code would be one of the first things in a compiler regression test suite.

int channels[] = { 0, 1 }; is required by the C++ standard to be equivalent to int channels[2] = { 0, 1 };

It appears that your compiler assumes 0 as the default, to yield int channels[0] = { 0, 1 }; for which, in standard C++, a diagnostic must be given since zero length arrays are not supported.

Does switching off any purported variable length array support fix it?

Bathsheba
  • 231,907
  • 34
  • 361
  • 483