【发布时间】: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