【问题标题】:too many initializers for 'int [0]' while setting the parameters for HSV histogram calculation [duplicate]在设置 HSV 直方图计算的参数时,“int [0]”的初始化程序太多[重复]
【发布时间】:2019-10-07 23:43:50
【问题描述】:

我是 opencv 的新手,我想计算 HSV 直方图。我指的是此链接中提供的代码。 https://docs.opencv.org/3.0-beta/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.html

我正在使用 opencv 3.3.1 版并面临以下错误错误。

使用相同的代码,除了更改 HSV 直方图的图像外,我没有对代码进行任何更改。其中 detectPerson 是视频帧,hsv 是 cv mat 对象。

任何人请帮助我被困在这里。

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() );

错误

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]'

【问题讨论】:

  • 看起来你的编译器可能有问题。如果你只是尝试编译 int main() { int foo[] = {1, 2}; } 会发生什么?
  • too many initializers for 'int [0]' c++ 的可能重复项您似乎没有给我们minimal reproducible example。我猜当int channels[] = { 0, 1 }; 出现时你还没有关闭你的一些类定义。
  • 我正在研究 ROS,并在 ROS 中使用 opencv
  • @NathanOliver 我检查了我关闭了所有的类和函数体

标签: c++ histogram hsv opencv3.3


【解决方案1】:

您的编译器有缺陷,尽管这让我感到困惑,因为这样的代码将是编译器回归测试套件中的首要内容之一。

C++ 标准要求int channels[] = { 0, 1 }; 等同于int channels[2] = { 0, 1 };

您的编译器似乎假定 0 作为默认值,以产生 int channels[0] = { 0, 1 };,在标准 C++ 中,必须给出诊断,因为不支持零长度数组。

关闭任何声称的可变长度数组是否支持修复它?

【讨论】:

  • 是的,当我输入 int channels[2] = { 0, 1 };它修复了..
  • 所以我可以使用 int channels[2] = { 0, 1 };计算 HSV 直方图是否正确??
  • 应该是这样,但这可能取决于您使用的直方图的具体情况。
  • 我正在使用接受这些参数的 calcHist 函数..
猜你喜欢
  • 2014-02-04
  • 2012-01-31
  • 1970-01-01
  • 1970-01-01
  • 2014-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-12
相关资源
最近更新 更多